protected function execute(array $arguments = array(), array $options = array()) { $template = $arguments['template']; $config = $arguments['filename']; $checker = new nbConfigurationChecker(array('logger' => $this->getLogger(), 'verbose' => $this->isVerbose())); $checker->checkConfigFile($template, $config); return true; }
require_once dirname(__FILE__) . '/../../../../test/bootstrap/unit.php'; nbConfig::set('nb_command_dir', nbConfig::get('nb_sandbox_dir')); $dataDir = nbConfig::get('nb_data_dir') . '/config'; $sandboxDir = nbConfig::get('nb_sandbox_dir'); $configFileOk = $dataDir . '/config.ok.yml'; $configFileNoField = $dataDir . '/config.nofield.yml'; $configFileNoChild = $dataDir . '/config.nochild.yml'; $configFileNotExists = $dataDir . '/config.notexists.yml'; $dirNotExists = $dataDir . '/config.dirnotexists.yml'; $fileNotExists = $dataDir . '/config.filenotexists.yml'; $templateFile = $dataDir . '/template.config.yml'; $templateFileNotExists = $dataDir . '/template.notexists.sample.yml'; $t = new lime_test(16); $t->comment('Check Configuration'); $t->comment(' 1. Config file checks correctly'); $checker = new nbConfigurationChecker(array('verbose' => true, 'logger' => nbLogger::getInstance())); $t->ok($checker->checkConfigFile($templateFile, $configFileOk), 'Project configuration checked successfully'); $t->comment(' 2. Config file has errors (no child and no required field)'); try { $checker->checkConfigFile($templateFile, $configFileNoField); $t->fail('Config file without required field not checked successfully'); } catch (Exception $e) { $t->pass('Config file without required field not checked successfully'); } $t->ok($checker->hasErrors(), 'Config file has errors'); $t->is(count($checker->getErrors()), 2, 'Config file has 2 errors'); $errors = array('app_required_field' => 'required', 'app_required_child_field' => 'required'); $t->is($checker->getErrors(), $errors, 'Config file has errors formatted correctly'); $t->comment(' 3. Config file has errors (no child)'); try { $checker->checkConfigFile($templateFile, $configFileNoChild);
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; }