示例#1
0
文件: nbCommand.php 项目: nubee/bee
 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;
 }
示例#2
0
    $t->pass('No config file to print exists');
}
$text = '
app_required_child_field: value
app_required_field: text
app_param1: value4
app_dir1: test/data/system
app_file1: test/data/system/Class.java
app_array: 
  0: 
    key1: value4
  1: 
    key2: field2';
$t->is(removeCarriageReturn($printer->printAll()), removeCarriageReturn($text), 'Printed text is formatted correctly');
$printer = new nbConfigurationPrinter();
$printer->addConfigurationFile($configFileNoChild);
$text = '
app_required_child_field: <error>required</error>
app_required_field: value
app_param3: value3
app_dir1: <error>dir_exists</error>
app_file1: <error>file_exists</error>';
$errors = array('app_required_child_field' => 'required', 'app_dir1' => 'dir_exists', 'app_file1' => 'file_exists');
$printer->addConfigurationErrors($errors);
$t->is(removeCarriageReturn($printer->printAll()), removeCarriageReturn($text), 'Printed text is formatted correctly with errors');
function removeCarriageReturn($text)
{
    $text = str_replace("\r", '', $text);
    $text = str_replace("\n", '|', $text);
    return $text;
}