Пример #1
0
$t = new lime_test(2);
//Setup
try {
    $cmd = new nbMysqlDropCommand();
    $commandLine = sprintf('%s %s %s', $dbName, $adminUsername, $adminPassword);
    $cmd->run(new nbCommandLineParser(), $commandLine);
} catch (Exception $e) {
    $t->comment('Drop database: ' . $e->getMessage());
}
try {
    $cmd = new nbMysqlCreateCommand();
    $commandLine = sprintf('%s %s %s', $dbName, $adminUsername, $adminPassword);
    $cmd->run(new nbCommandLineParser(), $commandLine);
} catch (Exception $e) {
    $t->comment('Create database: ' . $e->getMessage());
}
$cmd = new nbSymfonyDeployCommand();
$parser = new nbCommandLineParser();
$parser->setDefaultConfigurationDirs(array(dirname(__FILE__) . '/../data/config'));
$t->comment('Symfony Deploy dry run');
$commandLine = '--config-file ';
$t->ok($cmd->run($parser, $commandLine), 'Symfony project deployed successfully');
$cmd = new nbSymfonyDeployCommand();
$parser = new nbCommandLineParser();
$parser->setDefaultConfigurationDirs(array(dirname(__FILE__) . '/../data/config'));
$t->comment('Symfony Deploy');
$commandLine = '--config-file --doit';
$t->ok($cmd->run($parser, $commandLine), 'Symfony project deployed successfully');
$fileSystem->rmdir($logDir, true, true);
$fileSystem->rmdir($cacheDir, true, true);
$fileSystem->rmdir(nbConfig::get('archive_archive-dir_destination-dir'), true);
Пример #2
0
$fs->delete($otherFileToSync);
$t->ok($cmd->run(new nbCommandLineParser(), '--doit --exclude-from=' . $excludeFile . ' ' . $commandLine), 'Command nbDirTransfer called successfully exclude file');
$t->ok(!file_exists($folderToExclude), 'folderToExclude was not synchronized in the target site');
$t->ok(!file_exists($fileToExclude), 'fileToExclude was not synchronized in the target site');
$t->ok(!file_exists($fileToInclude), 'fileToInclude was not synchronized in the target site');
$t->ok(file_exists($fileToSync), 'fileToSync was synchronized in the target folder');
$t->ok(file_exists($otherFileToSync), 'otherFileToSync was synchronized in the target folder');
$fs->delete($fileToSync);
$fs->delete($otherFileToSync);
$t->ok($cmd->run(new nbCommandLineParser(), '--doit --exclude-from=' . $excludeFile . ' --include-from=' . $includeFile . ' ' . $commandLine), 'Command nbDirTransfer called successfully');
$t->ok(!file_exists($folderToExclude), 'folderToExclude was not synchronized in the target site');
$t->ok(!file_exists($fileToExclude), 'fileToExclude was not synchronized in the target site');
$t->ok(file_exists($fileToInclude), 'fileToInclude was synchronized in the target site');
$t->ok(file_exists($fileToSync), 'fileToSync was synchronized in the target folder');
$t->ok(file_exists($otherFileToSync), 'otherFileToSync was synchronized in the target folder');
$fs->delete($fileToSync);
$fs->delete($fileToInclude);
$fs->delete($otherFileToSync);
$commandLine = '--delete --config-file=config.yml';
$parser = new nbCommandLineParser();
$parser->setDefaultConfigurationDirs($dataDir);
$t->ok($cmd->run($parser, '--doit --exclude-from=' . $excludeFile . ' --include-from=' . $includeFile . ' ' . $commandLine), 'Command nbDirTransfer called successfully');
$t->ok(!file_exists($folderToExclude), 'folderToExclude was not synchronized in the target site');
$t->ok(!file_exists($fileToExclude), 'fileToExclude was not synchronized in the target site');
$t->ok(file_exists($fileToInclude), 'fileToInclude was synchronized in the target site');
$t->ok(file_exists($fileToSync), 'fileToSync was synchronized in the target folder');
$t->ok(file_exists($otherFileToSync), 'otherFileToSync was synchronized in the target folder');
$fs->delete($fileToSync);
$fs->delete($fileToInclude);
$fs->delete($otherFileToSync);
$fs->touch($targetDir . '/readme');
Пример #3
0
require_once dirname(__FILE__) . '/../bootstrap/unit.php';
if (!checkMysql()) {
    return true;
}
$t = new lime_test(3);
$t->comment('Mysql Drop Command');
// Setup
createAdminUser($mysqlAdminUsername, $mysqlAdminPassword, $tempAdminUsername, $tempAdminPassword);
createDb($mysqlAdminUsername, $mysqlAdminPassword, $dbName);
$t->comment('MysqlDropCommand executed by admin user with password');
$cmd = new nbMysqlDropCommand();
$commandLine = sprintf('%s %s %s', $dbName, $tempAdminUsername, $tempAdminPassword);
$t->ok($cmd->run(new nbCommandLineParser(), $commandLine), 'MysqlDrop executed successfully');
//TearDown
dropDatabaseUser($mysqlAdminUsername, $mysqlAdminPassword, $tempAdminUsername);
// Setup
createAdminUser($mysqlAdminUsername, $mysqlAdminPassword, $tempAdminUsernameWithNoPassword);
createDb($mysqlAdminUsername, $mysqlAdminPassword, $dbName);
$t->comment('MysqlDropCommand executed by admin user without password');
$cmd = new nbMysqlDropCommand();
$commandLine = sprintf('%s %s', $dbName, $tempAdminUsernameWithNoPassword);
$t->ok($cmd->run(new nbCommandLineParser(), $commandLine), 'MysqlDrop executed successfully');
//TearDown
dropDatabaseUser($mysqlAdminUsername, $mysqlAdminPassword, $tempAdminUsernameWithNoPassword);
// Setup
createDb($mysqlAdminUsername, $mysqlAdminPassword, $dbName);
$cmd = new nbMysqlDropCommand();
$parser = new nbCommandLineParser();
$parser->setDefaultConfigurationDirs(dirname(__FILE__) . '/../data/config');
$commandLine = '--config-file=mysql-plugin.yml';
$t->ok($cmd->run($parser, $commandLine), 'MysqlDrop executed successfully from config file');
Пример #4
0
$t->comment('Archive Dir');
$t->comment('  1. - Create archive');
$cmd = new nbArchiveDirCommand();
$timestamp = date('YmdHi', time());
$archivedFile = sprintf('%s/%s-%s.tar.gz', $destinationDir, $filename, $timestamp);
$commandLine = $sourceDir . ' ' . $destinationDir;
$t->ok($cmd->run(new nbCommandLineParser(), $commandLine), 'Directory has been archived into a destination file ');
$t->ok(file_exists($archivedFile), 'Destination file exists');
// Tear down
$fs->delete($archivedFile);
$t->comment('  2. - Create archive with config-file');
// parameters passed by config-file
$timestamp = date('YmdHi', time());
$archivedFile = sprintf('%s/%s-%s.tar.gz', $destinationDir, $filename, $timestamp);
$commandLine = '--config-file=archive-plugin.yml';
$parser = new nbCommandLineParser();
$parser->setDefaultConfigurationDirs(dirname(__FILE__) . '/../data/config');
$t->ok($cmd->run($parser, $commandLine), 'Directory has been archived into a destination file with a config-file');
$t->ok(file_exists($archivedFile), 'Destination file exists');
// Tear down
$fs->delete($archivedFile);
$t->comment('  3. - Cannot create archive with directories options');
try {
    $commandLine = $dirNotExists . ' ' . $destinationDir;
    $cmd->run(new nbCommandLineParser(), $commandLine);
    $t->fail('Cannot archive a source folder that does not exist ');
} catch (InvalidArgumentException $e) {
    $t->pass('Cannot archive a source folder that does not exist');
}
try {
    $commandLine = $sourceDir . ' ' . $dirNotExists;
Пример #5
0
$t->is($parser->hasArgumentValue('argumentOptional'), true, '->hasArgumentValue(argOptional) returns "true"');
$t->is($parser->getArgumentValue('argumentOptional'), 'fooOptionalCfg', '->getArgumentValue(argumentOptional) returns "fooOptionalCfg"');
$t->is($parser->hasOptionValue('optionDisabledCfg'), false, '->hasOptionValue(optionDisabledCfg) returns "false"');
$t->is($parser->hasOptionValue('optionCfg'), true, '->hasOptionValue(optionCfg) returns "true"');
$t->is($parser->getOptionValue('optionCfg'), true, '->getOptionValue(optionCfg) returns "true"');
$parser->parse(' --config-file --optionWithParameter=foo --otherOptionWithParameter bar', 'myNS', 'myCommand');
$t->is($parser->hasArgumentValue('argumentRequired'), true, '->hasArgumentValue(argumentRequired) returns "true"');
$t->is($parser->getArgumentValue('argumentRequired'), 'bar', '->getArgumentValue(argumentRequired) returns "bar"');
$t->is($parser->hasOptionValue('optionWithParameter'), true, '->hasOptionValue(optionWithParameter) returns "true"');
$t->is($parser->getOptionValue('optionWithParameter'), 'foo', '->getOptionValue(optionWithParameter) returns "foo"');
$t->is($parser->hasArgumentValue('argumentOptional'), true, '->hasArgumentValue(argOptional) returns "true"');
$t->is($parser->getArgumentValue('argumentOptional'), 'fooOptionalCfg', '->getArgumentValue(argumentOptional) returns "fooOptionalCfg"');
$t->is($parser->hasOptionValue('optionDisabledCfg'), false, '->hasOptionValue(optionDisabledCfg) returns "false"');
$t->is($parser->hasOptionValue('optionCfg'), true, '->hasOptionValue(optionCfg) returns "true"');
$t->is($parser->getOptionValue('optionCfg'), true, '->getOptionValue(optionCfg) returns "true"');
$t->is($parser->hasOptionValue('otherOptionWithParameter'), true, '->hasOptionValue(otherOptionWithParameter) returns "true"');
$t->is($parser->getOptionValue('otherOptionWithParameter'), 'bar2ParameterDefault', '->getOptionValue(otherOptionWithParameter) returns "bar2ParameterDefault"');
$t->comment('nbCommandLineParserTest - Test set/getDefaultConfigurationDirs');
$parser = new nbCommandLineParser();
$dataConfigDir = nbConfig::get('nb_data_dir') . '/config';
$parser->setDefaultConfigurationDirs($dataConfigDir);
$t->is($parser->getDefaultConfigurationDirs(), array($dataConfigDir), 'Default configuration dir is ' . $dataConfigDir);
$t->comment('nbCommandLineParserTest - Test checkDefaultConfigurationDirs
  (only filename is provided (eg.: config.ok.yml))');
$t->is($parser->checkDefaultConfigurationDirs('config.ok.yml'), $dataConfigDir . '/config.ok.yml', 'File was found in ' . $dataConfigDir);
$t->is($parser->checkDefaultConfigurationDirs('config.notexists.yml'), null, 'File doesn\'t exists');
$t->comment('nbCommandLineParserTest - Test checkDefaultConfigurationDirs
  (an absolute or relative filename is provided (eg.: ../../../data/config/config.ok.yml))');
$t->is($parser->checkDefaultConfigurationDirs($dataConfigDir . '/config.ok.yml'), $dataConfigDir . '/config.ok.yml', 'The file exists: ' . $dataConfigDir . '/config.ok.yml');
$t->is($parser->checkDefaultConfigurationDirs($dataConfigDir . '/config.notexists.yml'), null, 'File doesn\'t exists');
$t->is($parser->checkDefaultConfigurationDirs($dataConfigDir), null, 'Only file (not dir) is valid');
Пример #6
0
 protected function executeCommand(nbCommand $command, $commandLine, $doit, $verbose)
 {
     if ($doit) {
         $parser = new nbCommandLineParser();
         $parser->setDefaultConfigurationDirs($this->getParser()->getDefaultConfigurationDirs());
         $command->run($parser, $commandLine);
     }
     if ($verbose) {
         $this->logLine(sprintf("%s %s\n", $command->getFullName(), $commandLine), nbLogger::COMMENT);
     }
 }