try { $checker->checkConfigFile($templateFileNotExists, $configFileOk); $t->fail('No template file to check exists'); } catch (Exception $e) { $t->pass('No template file to check exists'); } try { $checker->checkConfigFile($templateFile, $dirNotExists); $t->fail('No directory exists (and it should be)'); } catch (Exception $e) { $t->pass('No directory exists (and it should be)'); } try { $checker->checkConfigFile($templateFile, $fileNotExists); $t->fail('No file exists (and it should be)'); } catch (Exception $e) { $t->pass('No file exists (and it should be)'); } $t->comment(' 5. Check whole configuration'); nbConfig::set('app_required_field', 'value'); try { $checker->check($templateFile, nbConfig::getConfiguration()); $t->fail('Whole configuration without required fields not checked successfully'); } catch (Exception $e) { $t->pass('Whole configuration without required fields not checked successfully'); } $t->ok($checker->hasErrors(), 'Configuration has errors'); $t->is(count($checker->getErrors()), 1, 'Configuration has 1 error'); nbConfig::set('app_required_child_field', 'value'); $checker->check($templateFile, nbConfig::getConfiguration()); $t->ok(!$checker->hasErrors(), 'Configuration has no errors');
public function checkConfiguration($configDir, $configFilename) { $configFile = $this->parser->checkDefaultConfigurationDirs($configFilename); if (!file_exists($configFile)) { throw new InvalidArgumentException(sprintf('Config file "%s" does not exist', $configFilename)); } // Check configuration $checker = new nbConfigurationChecker(array('logger' => $this->getLogger(), 'verbose' => $this->isVerbose())); $configuration = new nbConfiguration(); $configuration->add(nbConfig::getAll()); $configuration->add(sfYaml::load($configFile), '', true); try { $checker->check($configDir . '/' . $this->getTemplateConfigFilename(), $configuration); } catch (Exception $e) { $this->logLine('Configuration file doesn\'t match the template', nbLogger::ERROR); $printer = new nbConfigurationPrinter(); $printer->addConfiguration($configuration->getAll()); // $printer->addConfigurationFile($configFile); $printer->addConfigurationErrors($checker->getErrors()); $this->logLine($printer->printAll()); throw $e; } return $configFile; }