<?php

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');
$compareFile = $dataDir . '/config.compare.yml';
$destinationFile = $sandboxDir . '/config.yml';
$templateFile = $dataDir . '/template.config.yml';
$templateFileNotExists = $dataDir . '/template.notexists.sample.yml';
$t = new lime_test(3);
$t->comment('Generate Configuration');
$cmd = new nbGenerateConfigurationCommand();
$fs = nbFileSystem::getInstance();
$t->ok($cmd->run(new nbCommandLineParser(), sprintf('%s %s', $templateFile, $destinationFile)), 'Project configuration generate successfully');
$content = removeCarriageReturn(file_get_contents($destinationFile));
$compare = removeCarriageReturn(file_get_contents($compareFile));
$t->is($content, $compare, 'Generated file content is correct');
$fs->delete($destinationFile);
try {
    $cmd->run(new nbCommandLineParser(), sprintf('%s %s', $templateFileNotExists, $destinationFile));
    $t->fail('No template file to check exists');
} catch (Exception $e) {
    $t->pass('No template file to check exists');
}
function removeCarriageReturn($text)
{
    $text = str_replace("\r", '', $text);
    $text = str_replace("\n", '\\n', $text);
    return $text;
}
Пример #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;
}