Exemplo n.º 1
0
$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);
    $t->fail('Config file without required child not checked successfully');
} catch (Exception $e) {
    $t->pass('Config file without required child not checked successfully');
}
$t->ok($checker->hasErrors(), 'Config file has errors');
$t->is(count($checker->getErrors()), 1, 'Config file has 1 errors');
$t->comment(' 4. Config file checks if files exist');
try {
    $checker->checkConfigFile($templateFile, $configFileNotExists);
    $t->fail('No config file to check exists');
Exemplo n.º 2
0
 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;
 }