Merge pull request #325 from andres-montanez/nostromo

[Nostromo] Prepare for Release
This commit is contained in:
Andrés Montañez 2017-01-29 19:51:59 -03:00 committed by GitHub
commit 82225d5336
21 changed files with 104 additions and 2018 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
/vendor/ /vendor/
/build /build
composer.lock

View file

@ -11,8 +11,7 @@ if (file_exists(__DIR__ . '/../../../autoload.php')) {
use Mage\MageApplication; use Mage\MageApplication;
try { try {
$mage = new MageApplication(); $mage = new MageApplication('.mage.yml');
$mage->configure('.mage.yml');
$mage->run(); $mage->run();
} catch (Exception $exception) { } catch (Exception $exception) {
printf('Error: %s' . PHP_EOL, $exception->getMessage()); printf('Error: %s' . PHP_EOL, $exception->getMessage());

1899
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -10,6 +10,7 @@
namespace Mage\Command; namespace Mage\Command;
use Mage\MageApplication;
use Mage\Utils; use Mage\Utils;
use Mage\Runtime\Runtime; use Mage\Runtime\Runtime;
use Psr\Log\LogLevel; use Psr\Log\LogLevel;
@ -66,4 +67,15 @@ abstract class AbstractCommand extends Command
$utils = new Utils(); $utils = new Utils();
return $utils->getStageName($this->runtime->getStage()); return $utils->getStageName($this->runtime->getStage());
} }
/**
* Requires the configuration to be loaded
*/
protected function requireConfig()
{
$app = $this->getApplication();
if ($app instanceof MageApplication) {
$app->configure();
}
}
} }

View file

@ -41,6 +41,8 @@ class DumpCommand extends AbstractCommand
*/ */
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$this->requireConfig();
$output->writeln('Starting <fg=blue>Magallanes</>'); $output->writeln('Starting <fg=blue>Magallanes</>');
$output->writeln(''); $output->writeln('');

View file

@ -42,6 +42,8 @@ class EnvironmentsCommand extends AbstractCommand
*/ */
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$this->requireConfig();
$output->writeln('Starting <fg=blue>Magallanes</>'); $output->writeln('Starting <fg=blue>Magallanes</>');
$output->writeln(''); $output->writeln('');

View file

@ -58,6 +58,8 @@ class DeployCommand extends AbstractCommand
*/ */
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$this->requireConfig();
$output->writeln('Starting <fg=blue>Magallanes</>'); $output->writeln('Starting <fg=blue>Magallanes</>');
$output->writeln(''); $output->writeln('');

View file

@ -51,6 +51,8 @@ class ListCommand extends AbstractCommand
*/ */
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$this->requireConfig();
$utils = new Utils(); $utils = new Utils();
$output->writeln('Starting <fg=blue>Magallanes</>'); $output->writeln('Starting <fg=blue>Magallanes</>');
$output->writeln(''); $output->writeln('');

View file

@ -52,6 +52,8 @@ class RollbackCommand extends DeployCommand
*/ */
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
{ {
$this->requireConfig();
$output->writeln('Starting <fg=blue>Magallanes</>'); $output->writeln('Starting <fg=blue>Magallanes</>');
$output->writeln(''); $output->writeln('');

View file

@ -33,10 +33,18 @@ use Mage\Runtime\Exception\RuntimeException;
class MageApplication extends Application class MageApplication extends Application
{ {
protected $runtime; protected $runtime;
protected $file;
public function __construct() /**
* @param string $file The YAML file from which to read the configuration
*/
public function __construct($file)
{ {
parent::__construct('Magallanes', Mage::VERSION);
$this->file = $file;
$dispatcher = new EventDispatcher(); $dispatcher = new EventDispatcher();
$this->setDispatcher($dispatcher);
$dispatcher->addListener(ConsoleEvents::EXCEPTION, function (ConsoleExceptionEvent $event) { $dispatcher->addListener(ConsoleEvents::EXCEPTION, function (ConsoleExceptionEvent $event) {
$output = $event->getOutput(); $output = $event->getOutput();
@ -46,51 +54,45 @@ class MageApplication extends Application
$event->setException(new \LogicException('Caught exception', $exitCode, $event->getException())); $event->setException(new \LogicException('Caught exception', $exitCode, $event->getException()));
}); });
$this->setDispatcher($dispatcher); $this->runtime = $this->instantiateRuntime();
parent::__construct('Magallanes', Mage::VERSION); $this->loadBuiltInCommands();
} }
/** /**
* Configure the Magallanes Application * Configure the Magallanes Application
* *
* @param $file string The YAML file from which to read the configuration
*
* @throws RuntimeException * @throws RuntimeException
*/ */
public function configure($file) public function configure()
{ {
if (!file_exists($file) || !is_readable($file)) { if (!file_exists($this->file) || !is_readable($this->file)) {
throw new RuntimeException(sprintf('The file "%s" does not exists or is not readable.', $file)); throw new RuntimeException(sprintf('The file "%s" does not exists or is not readable.', $this->file));
} }
try { try {
$parser = new Parser(); $parser = new Parser();
$config = $parser->parse(file_get_contents($file)); $config = $parser->parse(file_get_contents($this->file));
} catch (ParseException $exception) { } catch (ParseException $exception) {
throw new RuntimeException(sprintf('Error parsing the file "%s".', $file)); throw new RuntimeException(sprintf('Error parsing the file "%s".', $this->file));
} }
if (array_key_exists('magephp', $config)) { if (array_key_exists('magephp', $config) && is_array($config['magephp'])) {
$config = $config['magephp'];
$logger = null; $logger = null;
if (array_key_exists('log_dir', $config) && file_exists($config['log_dir']) && is_dir($config['log_dir'])) { if (array_key_exists('log_dir', $config['magephp']) && file_exists($config['magephp']['log_dir']) && is_dir($config['magephp']['log_dir'])) {
$logfile = sprintf('%s/%s.log', $config['log_dir'], date('Ymd_His')); $logfile = sprintf('%s/%s.log', $config['magephp']['log_dir'], date('Ymd_His'));
$config['log_file'] = $logfile; $config['magephp']['log_file'] = $logfile;
$logger = new Logger('magephp'); $logger = new Logger('magephp');
$logger->pushHandler(new StreamHandler($logfile)); $logger->pushHandler(new StreamHandler($logfile));
} }
$this->runtime = $this->instantiateRuntime(); $this->runtime->setConfiguration($config['magephp']);
$this->runtime->setConfiguration($config);
$this->runtime->setLogger($logger); $this->runtime->setLogger($logger);
return;
$this->loadBuiltInCommands();
return true;
} }
throw new RuntimeException(sprintf('The file "%s" does not have a valid Magallanes configuration.', $file)); throw new RuntimeException(sprintf('The file "%s" does not have a valid Magallanes configuration.', $this->file));
} }
/** /**

View file

@ -41,7 +41,7 @@ class PrepareTask extends AbstractTask
$this->runtime->setVar('tar_local', $tarLocal); $this->runtime->setVar('tar_local', $tarLocal);
$excludes = $this->getExcludes(); $excludes = $this->getExcludes();
$flags = $this->runtime->getEnvOption('tar_create', 'cfzop'); $flags = $this->runtime->getEnvOption('tar_create', 'cfzp');
$cmdTar = sprintf('tar %s %s %s ./', $flags, $tarLocal, $excludes); $cmdTar = sprintf('tar %s %s %s ./', $flags, $tarLocal, $excludes);
/** @var Process $process */ /** @var Process $process */

View file

@ -20,8 +20,7 @@ class DumpCommandTest extends TestCase
{ {
public function testConfigDumpTermination() public function testConfigDumpTermination()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../../Resources/basic.yml');
$application->configure(__DIR__ . '/../../../Resources/basic.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('config:dump'); $command = $application->find('config:dump');

View file

@ -20,8 +20,7 @@ class EnvironmentsCommandTest extends TestCase
{ {
public function testConfigDumpTermination() public function testConfigDumpTermination()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../../Resources/basic.yml');
$application->configure(__DIR__ . '/../../../Resources/basic.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('config:environments'); $command = $application->find('config:environments');

View file

@ -20,8 +20,7 @@ class DeployCommandMiscTasksTest extends TestCase
{ {
public function testSymfonyEnvironmentConfiguration() public function testSymfonyEnvironmentConfiguration()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/symfony-envconf.yml');
$application->configure(__DIR__ . '/../../Resources/symfony-envconf.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('deploy'); $command = $application->find('deploy');
@ -53,8 +52,7 @@ class DeployCommandMiscTasksTest extends TestCase
public function testComposerFlags() public function testComposerFlags()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/composer.yml');
$application->configure(__DIR__ . '/../../Resources/composer.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('deploy'); $command = $application->find('deploy');
@ -84,8 +82,7 @@ class DeployCommandMiscTasksTest extends TestCase
public function testInvalidTaskName() public function testInvalidTaskName()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/invalid-task.yml');
$application->configure(__DIR__ . '/../../Resources/invalid-task.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('deploy'); $command = $application->find('deploy');
@ -100,8 +97,7 @@ class DeployCommandMiscTasksTest extends TestCase
public function testBrokenGitBranch() public function testBrokenGitBranch()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/broken-git-branch.yml');
$application->configure(__DIR__ . '/../../Resources/broken-git-branch.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('deploy'); $command = $application->find('deploy');
@ -119,8 +115,7 @@ class DeployCommandMiscTasksTest extends TestCase
public function testBrokenGitCheckout() public function testBrokenGitCheckout()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/broken-git-branch.yml');
$application->configure(__DIR__ . '/../../Resources/broken-git-branch.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('deploy'); $command = $application->find('deploy');
@ -138,8 +133,7 @@ class DeployCommandMiscTasksTest extends TestCase
public function testBrokenGitUpdate() public function testBrokenGitUpdate()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/broken-git-branch.yml');
$application->configure(__DIR__ . '/../../Resources/broken-git-branch.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('deploy'); $command = $application->find('deploy');

View file

@ -20,8 +20,7 @@ class DeployCommandMiscTest extends TestCase
{ {
public function testDeploymentWithNoHosts() public function testDeploymentWithNoHosts()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/no-hosts.yml');
$application->configure(__DIR__ . '/../../Resources/no-hosts.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('deploy'); $command = $application->find('deploy');
@ -39,8 +38,7 @@ class DeployCommandMiscTest extends TestCase
public function testDeploymentWithSudo() public function testDeploymentWithSudo()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-sudo.yml');
$application->configure(__DIR__ . '/../../Resources/testhost-sudo.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('deploy'); $command = $application->find('deploy');
@ -78,8 +76,7 @@ class DeployCommandMiscTest extends TestCase
public function testDeploymentWithBranchOverwrite() public function testDeploymentWithBranchOverwrite()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-without-releases.yml');
$application->configure(__DIR__ . '/../../Resources/testhost-without-releases.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('deploy'); $command = $application->find('deploy');
@ -116,9 +113,7 @@ class DeployCommandMiscTest extends TestCase
public function testDeploymentWithCustomTask() public function testDeploymentWithCustomTask()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-custom-task.yml');
$application->configure(__DIR__ . '/../../Resources/testhost-custom-task.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('deploy'); $command = $application->find('deploy');
@ -150,8 +145,7 @@ class DeployCommandMiscTest extends TestCase
public function testDeploymentWithErrorTaskCommands() public function testDeploymentWithErrorTaskCommands()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-with-error.yml');
$application->configure(__DIR__ . '/../../Resources/testhost-with-error.yml');
$application->getRuntime()->setReleaseId('20170101015120'); $application->getRuntime()->setReleaseId('20170101015120');
@ -170,7 +164,7 @@ class DeployCommandMiscTest extends TestCase
2 => 'git pull', 2 => 'git pull',
3 => 'composer install --optimize-autoloader', 3 => 'composer install --optimize-autoloader',
4 => 'composer dump-autoload --optimize', 4 => 'composer dump-autoload --optimize',
5 => 'tar cfzop /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./', 5 => 'tar cfzp /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./',
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"mkdir -p /var/www/test/releases/1234567890\\"', 6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"mkdir -p /var/www/test/releases/1234567890\\"',
7 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ', 7 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ',
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& tar xfzop mageXYZ\\"', 8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& tar xfzop mageXYZ\\"',
@ -192,8 +186,7 @@ class DeployCommandMiscTest extends TestCase
public function testDeploymentWithFailingPostDeployTaskCommands() public function testDeploymentWithFailingPostDeployTaskCommands()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-with-postdeploy-error.yml');
$application->configure(__DIR__ . '/../../Resources/testhost-with-postdeploy-error.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('deploy'); $command = $application->find('deploy');
@ -228,8 +221,7 @@ class DeployCommandMiscTest extends TestCase
public function testDeploymentWithSkippingTask() public function testDeploymentWithSkippingTask()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-skipping.yml');
$application->configure(__DIR__ . '/../../Resources/testhost-skipping.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('deploy'); $command = $application->find('deploy');

View file

@ -20,8 +20,7 @@ class DeployCommandWithReleasesTest extends TestCase
{ {
public function testDeploymentWithReleasesCommands() public function testDeploymentWithReleasesCommands()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost.yml');
$application->configure(__DIR__ . '/../../Resources/testhost.yml');
$application->getRuntime()->setReleaseId('20170101015120'); $application->getRuntime()->setReleaseId('20170101015120');
@ -40,7 +39,7 @@ class DeployCommandWithReleasesTest extends TestCase
2 => 'git pull', 2 => 'git pull',
3 => 'composer install --optimize-autoloader', 3 => 'composer install --optimize-autoloader',
4 => 'composer dump-autoload --optimize', 4 => 'composer dump-autoload --optimize',
5 => 'tar cfzop /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./', 5 => 'tar cfzp /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./',
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"mkdir -p /var/www/test/releases/1234567890\\"', 6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"mkdir -p /var/www/test/releases/1234567890\\"',
7 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ', 7 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ',
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& tar xfzop mageXYZ\\"', 8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& tar xfzop mageXYZ\\"',
@ -71,8 +70,7 @@ class DeployCommandWithReleasesTest extends TestCase
public function testDeploymentWithoutReleasesTarPrepare() public function testDeploymentWithoutReleasesTarPrepare()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-force-tar1.yml');
$application->configure(__DIR__ . '/../../Resources/testhost-force-tar1.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('deploy'); $command = $application->find('deploy');
@ -87,8 +85,7 @@ class DeployCommandWithReleasesTest extends TestCase
public function testDeploymentWithoutReleasesTarCopy() public function testDeploymentWithoutReleasesTarCopy()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-force-tar2.yml');
$application->configure(__DIR__ . '/../../Resources/testhost-force-tar2.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('deploy'); $command = $application->find('deploy');
@ -103,8 +100,7 @@ class DeployCommandWithReleasesTest extends TestCase
public function testDeploymentWithoutReleasesTarCleanup() public function testDeploymentWithoutReleasesTarCleanup()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-force-tar3.yml');
$application->configure(__DIR__ . '/../../Resources/testhost-force-tar3.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('deploy'); $command = $application->find('deploy');
@ -119,8 +115,7 @@ class DeployCommandWithReleasesTest extends TestCase
public function testDeploymentFailCopyCommands() public function testDeploymentFailCopyCommands()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-fail-copy-tar.yml');
$application->configure(__DIR__ . '/../../Resources/testhost-fail-copy-tar.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('deploy'); $command = $application->find('deploy');
@ -135,8 +130,7 @@ class DeployCommandWithReleasesTest extends TestCase
public function testDeploymentWithoutReleasesForceRelease() public function testDeploymentWithoutReleasesForceRelease()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-force-release.yml');
$application->configure(__DIR__ . '/../../Resources/testhost-force-release.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('deploy'); $command = $application->find('deploy');
@ -151,8 +145,7 @@ class DeployCommandWithReleasesTest extends TestCase
public function testDeploymentFailToExtract() public function testDeploymentFailToExtract()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost.yml');
$application->configure(__DIR__ . '/../../Resources/testhost.yml');
$application->getRuntime()->setReleaseId('20170101015120'); $application->getRuntime()->setReleaseId('20170101015120');
@ -173,7 +166,7 @@ class DeployCommandWithReleasesTest extends TestCase
2 => 'git pull', 2 => 'git pull',
3 => 'composer install --optimize-autoloader', 3 => 'composer install --optimize-autoloader',
4 => 'composer dump-autoload --optimize', 4 => 'composer dump-autoload --optimize',
5 => 'tar cfzop /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./', 5 => 'tar cfzp /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./',
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"mkdir -p /var/www/test/releases/1234567890\\"', 6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"mkdir -p /var/www/test/releases/1234567890\\"',
7 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ', 7 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ',
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& tar xfzop mageXYZ\\"', 8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& tar xfzop mageXYZ\\"',
@ -194,8 +187,7 @@ class DeployCommandWithReleasesTest extends TestCase
public function testDeploymentFailToCopy() public function testDeploymentFailToCopy()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost.yml');
$application->configure(__DIR__ . '/../../Resources/testhost.yml');
$application->getRuntime()->setReleaseId('20170101015120'); $application->getRuntime()->setReleaseId('20170101015120');
@ -216,7 +208,7 @@ class DeployCommandWithReleasesTest extends TestCase
2 => 'git pull', 2 => 'git pull',
3 => 'composer install --optimize-autoloader', 3 => 'composer install --optimize-autoloader',
4 => 'composer dump-autoload --optimize', 4 => 'composer dump-autoload --optimize',
5 => 'tar cfzop /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./', 5 => 'tar cfzp /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./',
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"mkdir -p /var/www/test/releases/1234567890\\"', 6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"mkdir -p /var/www/test/releases/1234567890\\"',
7 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ', 7 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ',
); );
@ -236,8 +228,7 @@ class DeployCommandWithReleasesTest extends TestCase
public function testDeploymentFailCleanup() public function testDeploymentFailCleanup()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost.yml');
$application->configure(__DIR__ . '/../../Resources/testhost.yml');
$application->getRuntime()->setReleaseId('20170101015120'); $application->getRuntime()->setReleaseId('20170101015120');
@ -258,7 +249,7 @@ class DeployCommandWithReleasesTest extends TestCase
2 => 'git pull', 2 => 'git pull',
3 => 'composer install --optimize-autoloader', 3 => 'composer install --optimize-autoloader',
4 => 'composer dump-autoload --optimize', 4 => 'composer dump-autoload --optimize',
5 => 'tar cfzop /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./', 5 => 'tar cfzp /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./',
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"mkdir -p /var/www/test/releases/1234567890\\"', 6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"mkdir -p /var/www/test/releases/1234567890\\"',
7 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ', 7 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ',
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& tar xfzop mageXYZ\\"', 8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& tar xfzop mageXYZ\\"',
@ -290,8 +281,7 @@ class DeployCommandWithReleasesTest extends TestCase
public function testDeploymentFailMidway() public function testDeploymentFailMidway()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost.yml');
$application->configure(__DIR__ . '/../../Resources/testhost.yml');
$application->getRuntime()->setReleaseId('20170101015120'); $application->getRuntime()->setReleaseId('20170101015120');
@ -312,7 +302,7 @@ class DeployCommandWithReleasesTest extends TestCase
2 => 'git pull', 2 => 'git pull',
3 => 'composer install --optimize-autoloader', 3 => 'composer install --optimize-autoloader',
4 => 'composer dump-autoload --optimize', 4 => 'composer dump-autoload --optimize',
5 => 'tar cfzop /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./', 5 => 'tar cfzp /tmp/mageXYZ --exclude=".git" --exclude="./var/cache/*" --exclude="./var/log/*" --exclude="./web/app_dev.php" ./',
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"mkdir -p /var/www/test/releases/1234567890\\"', 6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"mkdir -p /var/www/test/releases/1234567890\\"',
7 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ', 7 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ',
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& tar xfzop mageXYZ\\"', 8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& tar xfzop mageXYZ\\"',

View file

@ -20,8 +20,7 @@ class DeployCommandWithoutReleasesTest extends TestCase
{ {
public function testDeploymentWithoutReleasesCommands() public function testDeploymentWithoutReleasesCommands()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-without-releases.yml');
$application->configure(__DIR__ . '/../../Resources/testhost-without-releases.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('deploy'); $command = $application->find('deploy');
@ -58,8 +57,7 @@ class DeployCommandWithoutReleasesTest extends TestCase
public function testDeploymentFailMidway() public function testDeploymentFailMidway()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/testhost-without-releases.yml');
$application->configure(__DIR__ . '/../../Resources/testhost-without-releases.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('deploy'); $command = $application->find('deploy');

View file

@ -20,8 +20,7 @@ class ListCommandTest extends TestCase
{ {
public function testListReleasesCommands() public function testListReleasesCommands()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../../Resources/testhost.yml');
$application->configure(__DIR__ . '/../../../Resources/testhost.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('releases:list'); $command = $application->find('releases:list');
@ -48,8 +47,7 @@ class ListCommandTest extends TestCase
public function testListReleasesWithInvalidEnvironment() public function testListReleasesWithInvalidEnvironment()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../../Resources/testhost.yml');
$application->configure(__DIR__ . '/../../../Resources/testhost.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('releases:list'); $command = $application->find('releases:list');
@ -64,8 +62,7 @@ class ListCommandTest extends TestCase
public function testListReleasesWithoutReleases() public function testListReleasesWithoutReleases()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../../Resources/testhost-without-releases.yml');
$application->configure(__DIR__ . '/../../../Resources/testhost-without-releases.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('releases:list'); $command = $application->find('releases:list');
@ -80,8 +77,7 @@ class ListCommandTest extends TestCase
public function testFailToGetCurrentRelease() public function testFailToGetCurrentRelease()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../../Resources/testhost-fail-get-current.yml');
$application->configure(__DIR__ . '/../../../Resources/testhost-fail-get-current.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('releases:list'); $command = $application->find('releases:list');
@ -96,8 +92,7 @@ class ListCommandTest extends TestCase
public function testNoReleasesAvailable() public function testNoReleasesAvailable()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../../Resources/testhost-no-releases.yml');
$application->configure(__DIR__ . '/../../../Resources/testhost-no-releases.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('releases:list'); $command = $application->find('releases:list');
@ -111,8 +106,7 @@ class ListCommandTest extends TestCase
public function testFailGetReleases() public function testFailGetReleases()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../../Resources/testhost-fail-get-releases.yml');
$application->configure(__DIR__ . '/../../../Resources/testhost-fail-get-releases.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('releases:list'); $command = $application->find('releases:list');
@ -127,8 +121,7 @@ class ListCommandTest extends TestCase
public function testNoHosts() public function testNoHosts()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../../Resources/testhost-no-hosts.yml');
$application->configure(__DIR__ . '/../../../Resources/testhost-no-hosts.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('releases:list'); $command = $application->find('releases:list');

View file

@ -20,8 +20,7 @@ class RollbackCommandTest extends TestCase
{ {
public function testRollbackReleaseCommands() public function testRollbackReleaseCommands()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../../Resources/testhost.yml');
$application->configure(__DIR__ . '/../../../Resources/testhost.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('releases:rollback'); $command = $application->find('releases:rollback');
@ -48,8 +47,7 @@ class RollbackCommandTest extends TestCase
public function testRollbackReleaseWithInvalidEnvironment() public function testRollbackReleaseWithInvalidEnvironment()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../../Resources/testhost.yml');
$application->configure(__DIR__ . '/../../../Resources/testhost.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('releases:rollback'); $command = $application->find('releases:rollback');
@ -64,8 +62,7 @@ class RollbackCommandTest extends TestCase
public function testRollbackReleaseWithoutReleases() public function testRollbackReleaseWithoutReleases()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../../Resources/testhost-without-releases.yml');
$application->configure(__DIR__ . '/../../../Resources/testhost-without-releases.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('releases:rollback'); $command = $application->find('releases:rollback');
@ -80,8 +77,7 @@ class RollbackCommandTest extends TestCase
public function testRollbackReleaseNotAvailable() public function testRollbackReleaseNotAvailable()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../../Resources/testhost-not-have-release.yml');
$application->configure(__DIR__ . '/../../../Resources/testhost-not-have-release.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('releases:rollback'); $command = $application->find('releases:rollback');

View file

@ -21,8 +21,7 @@ class VersionCommandTest extends TestCase
{ {
public function testVersionOutput() public function testVersionOutput()
{ {
$application = new MageApplicationMockup(); $application = new MageApplicationMockup(__DIR__ . '/../../Resources/basic.yml');
$application->configure(__DIR__ . '/../../Resources/basic.yml');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('version'); $command = $application->find('version');

View file

@ -20,16 +20,16 @@ class MageApplicationTest extends TestCase
{ {
public function testValidConfiguration() public function testValidConfiguration()
{ {
$application = new MageApplication(); $application = new MageApplication(__DIR__ . '/Resources/basic.yml');
$application->configure(__DIR__ . '/Resources/basic.yml');
$this->assertTrue($application instanceof MageApplication); $this->assertTrue($application instanceof MageApplication);
} }
public function testInValidConfiguration() public function testInValidConfiguration()
{ {
try { try {
$application = new MageApplication(); $application = new MageApplication(__DIR__ . '/Resources/invalid.yml');
$application->configure(__DIR__ . '/Resources/invalid.yml'); $application->configure();
$this->assertTrue(false, 'Application did not throw exception.');
} catch (Exception $exception) { } catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException); $this->assertTrue($exception instanceof RuntimeException);
$this->assertEquals(sprintf('The file "%s" does not have a valid Magallanes configuration.', __DIR__ . '/Resources/invalid.yml'), $exception->getMessage()); $this->assertEquals(sprintf('The file "%s" does not have a valid Magallanes configuration.', __DIR__ . '/Resources/invalid.yml'), $exception->getMessage());
@ -39,8 +39,9 @@ class MageApplicationTest extends TestCase
public function testParserError() public function testParserError()
{ {
try { try {
$application = new MageApplication(); $application = new MageApplication(__DIR__ . '/Resources/invalid-yaml.yml');
$application->configure(__DIR__ . '/Resources/invalid-yaml.yml'); $application->configure();
$this->assertTrue(false, 'Application did not throw exception.');
} catch (Exception $exception) { } catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException); $this->assertTrue($exception instanceof RuntimeException);
$this->assertEquals(sprintf('Error parsing the file "%s".', __DIR__ . '/Resources/invalid-yaml.yml'), $exception->getMessage()); $this->assertEquals(sprintf('Error parsing the file "%s".', __DIR__ . '/Resources/invalid-yaml.yml'), $exception->getMessage());
@ -50,8 +51,9 @@ class MageApplicationTest extends TestCase
public function testInvalidFile() public function testInvalidFile()
{ {
try { try {
$application = new MageApplication(); $application = new MageApplication(__DIR__ . '/Resources/this-does-not-exists.yml');
$application->configure(__DIR__ . '/Resources/this-does-not-exists.yml'); $application->configure();
$this->assertTrue(false, 'Application did not throw exception.');
} catch (Exception $exception) { } catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException); $this->assertTrue($exception instanceof RuntimeException);
$this->assertEquals(sprintf('The file "%s" does not exists or is not readable.', __DIR__ . '/Resources/this-does-not-exists.yml'), $exception->getMessage()); $this->assertEquals(sprintf('The file "%s" does not exists or is not readable.', __DIR__ . '/Resources/this-does-not-exists.yml'), $exception->getMessage());
@ -60,9 +62,8 @@ class MageApplicationTest extends TestCase
public function testAppDispatcher() public function testAppDispatcher()
{ {
$application = new MageApplication(); $application = new MageApplication(__DIR__ . '/Resources/basic.yml');
$application->setAutoExit(false); $application->setAutoExit(false);
$application->configure(__DIR__ . '/Resources/basic.yml');
$this->assertTrue($application instanceof MageApplication); $this->assertTrue($application instanceof MageApplication);
$application->register('foo')->setCode(function () { $application->register('foo')->setCode(function () {