mirror of
https://github.com/hauke68/Magallanes.git
synced 2026-08-29 18:48:56 +02:00
Change structure.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the Magallanes package.
|
||||
*
|
||||
* (c) Andrés Montañez <andres@andresmontanez.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Mage\Tests\Command\BuiltIn\Config;
|
||||
|
||||
use Mage\Command\BuiltIn\Config\DumpCommand;
|
||||
use Mage\Command\AbstractCommand;
|
||||
use Mage\Tests\MageApplicationMockup;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class DumpCommandTest extends TestCase
|
||||
{
|
||||
public function testConfigDumpTermination()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../../Resources/basic.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('config:dump');
|
||||
$this->assertTrue($command instanceof DumpCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName()]);
|
||||
|
||||
$this->assertEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the Magallanes package.
|
||||
*
|
||||
* (c) Andrés Montañez <andres@andresmontanez.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Mage\Tests\Command\BuiltIn\Config;
|
||||
|
||||
use Mage\Command\BuiltIn\Config\EnvironmentsCommand;
|
||||
use Mage\Command\AbstractCommand;
|
||||
use Mage\Tests\MageApplicationMockup;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class EnvironmentsCommandTest extends TestCase
|
||||
{
|
||||
public function testConfigDumpTermination()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../../Resources/basic.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('config:environments');
|
||||
$this->assertTrue($command instanceof EnvironmentsCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName()]);
|
||||
|
||||
$this->assertEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,157 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the Magallanes package.
|
||||
*
|
||||
* (c) Andrés Montañez <andres@andresmontanez.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Mage\Tests\Command\BuiltIn;
|
||||
|
||||
use Mage\Command\BuiltIn\DeployCommand;
|
||||
use Mage\Tests\MageApplicationMockup;
|
||||
use Mage\Command\AbstractCommand;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class DeployCommandMiscTasksTest extends TestCase
|
||||
{
|
||||
public function testSymfonyEnvironmentConfiguration()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/symfony-envconf.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$ranCommands = $application->getRuntime()->getRanCommands();
|
||||
|
||||
$testCase = array(
|
||||
0 => 'rsync -e "ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -avz --exclude=.git --exclude=./var/cache/* --exclude=./var/log/* --exclude=./web/app_dev.php ./ tester@testhost:/var/www/test',
|
||||
1 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& bin/console cache:warmup --env=testenv\\"',
|
||||
2 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& bin/console assets:install web --env=testenv --symlink --relative\\"',
|
||||
3 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& bin/console assetic:dump --env=testenv\\"',
|
||||
4 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& bin/console assetic:dump --env=prod\\"',
|
||||
);
|
||||
|
||||
// Check total of Executed Commands
|
||||
$this->assertEquals(count($testCase), count($ranCommands));
|
||||
|
||||
// Check Generated Commands
|
||||
foreach ($testCase as $index => $command) {
|
||||
$this->assertEquals($command, $ranCommands[$index]);
|
||||
}
|
||||
|
||||
$this->assertEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testComposerFlags()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/composer.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$ranCommands = $application->getRuntime()->getRanCommands();
|
||||
|
||||
$testCase = array(
|
||||
0 => '/usr/bin/composer.phar install --prefer-source',
|
||||
1 => '/usr/bin/composer.phar dump-autoload --no-scripts',
|
||||
2 => 'rsync -e "ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -avz --exclude=.git --exclude=./var/cache/* --exclude=./var/log/* --exclude=./web/app_dev.php ./ tester@testhost:/var/www/test',
|
||||
);
|
||||
|
||||
// Check total of Executed Commands
|
||||
$this->assertEquals(count($testCase), count($ranCommands));
|
||||
|
||||
// Check Generated Commands
|
||||
foreach ($testCase as $index => $command) {
|
||||
$this->assertEquals($command, $ranCommands[$index]);
|
||||
}
|
||||
|
||||
$this->assertEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testInvalidTaskName()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/invalid-task.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
$this->assertEquals(7, $tester->getStatusCode());
|
||||
$this->assertContains('Invalid task name "invalid/task"', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testBrokenGitBranch()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/broken-git-branch.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$application->getRuntime()->forceFail('git branch | grep "*"');
|
||||
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$this->assertContains('Running [Git] Change Branch (broken-test) ... FAIL', $tester->getDisplay());
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testBrokenGitCheckout()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/broken-git-branch.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$application->getRuntime()->forceFail('git checkout broken-test');
|
||||
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$this->assertContains('Running [Git] Change Branch (broken-test) ... FAIL', $tester->getDisplay());
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testBrokenGitUpdate()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/broken-git-branch.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$application->getRuntime()->forceFail('git pull');
|
||||
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$this->assertContains('Running [Git] Update ... FAIL', $tester->getDisplay());
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the Magallanes package.
|
||||
*
|
||||
* (c) Andrés Montañez <andres@andresmontanez.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Mage\Tests\Command\BuiltIn;
|
||||
|
||||
use Mage\Command\BuiltIn\DeployCommand;
|
||||
use Mage\Tests\MageApplicationMockup;
|
||||
use Mage\Command\AbstractCommand;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class DeployCommandMiscTest extends TestCase
|
||||
{
|
||||
public function testDeploymentWithNoHosts()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/no-hosts.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$this->assertContains('No hosts defined, skipping On Deploy tasks', $tester->getDisplay());
|
||||
$this->assertContains('No hosts defined, skipping On Release tasks', $tester->getDisplay());
|
||||
$this->assertContains('No hosts defined, skipping Post Release tasks', $tester->getDisplay());
|
||||
|
||||
$this->assertEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testDeploymentWithSudo()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/testhost-sudo.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$ranCommands = $application->getRuntime()->getRanCommands();
|
||||
|
||||
$testCase = array(
|
||||
0 => 'git branch | grep "*"',
|
||||
1 => 'git checkout test',
|
||||
2 => 'git pull',
|
||||
3 => 'composer install --optimize-autoloader',
|
||||
4 => 'composer dump-autoload --optimize',
|
||||
5 => 'rsync -e "ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -avz --exclude=.git --exclude=./var/cache/* --exclude=./var/log/* --exclude=./web/app_dev.php ./ tester@testhost:/var/www/test',
|
||||
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& sudo bin/console cache:clear --env=dev\\"',
|
||||
7 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& sudo bin/console cache:warmup --env=dev\\"',
|
||||
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& sudo bin/console assets:install web --env=dev --symlink --relative\\"',
|
||||
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& sudo bin/console assetic:dump --env=dev\\"',
|
||||
10 => 'git checkout master',
|
||||
);
|
||||
|
||||
// Check total of Executed Commands
|
||||
$this->assertEquals(count($testCase), count($ranCommands));
|
||||
|
||||
// Check Generated Commands
|
||||
foreach ($testCase as $index => $command) {
|
||||
$this->assertEquals($command, $ranCommands[$index]);
|
||||
}
|
||||
|
||||
$this->assertEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testDeploymentWithBranchOverwrite()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/testhost-without-releases.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test', '--branch' => 'maintenance']);
|
||||
|
||||
$ranCommands = $application->getRuntime()->getRanCommands();
|
||||
|
||||
$testCase = array(
|
||||
0 => 'git branch | grep "*"',
|
||||
1 => 'git checkout maintenance',
|
||||
2 => 'git pull',
|
||||
3 => 'composer install --optimize-autoloader',
|
||||
4 => 'composer dump-autoload --optimize',
|
||||
5 => 'rsync -e "ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -avz --exclude=.git --exclude=./var/cache/* --exclude=./var/log/* --exclude=./web/app_dev.php ./ tester@testhost:/var/www/test',
|
||||
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& bin/console cache:warmup --env=dev\\"',
|
||||
7 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& bin/console assets:install web --env=dev --symlink --relative\\"',
|
||||
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& bin/console assetic:dump --env=dev\\"',
|
||||
9 => 'git checkout master',
|
||||
);
|
||||
|
||||
// Check total of Executed Commands
|
||||
$this->assertEquals(count($testCase), count($ranCommands));
|
||||
|
||||
// Check Generated Commands
|
||||
foreach ($testCase as $index => $command) {
|
||||
$this->assertEquals($command, $ranCommands[$index]);
|
||||
}
|
||||
|
||||
$this->assertEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testDeploymentWithCustomTask()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/testhost-custom-task.yml');
|
||||
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$ranCommands = $application->getRuntime()->getRanCommands();
|
||||
|
||||
$testCase = array(
|
||||
0 => 'composer install --optimize-autoloader',
|
||||
1 => 'composer dump-autoload --optimize',
|
||||
2 => 'rsync -e "ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -avz --exclude=.git --exclude=./var/cache/* --exclude=./var/log/* --exclude=./web/app_dev.php ./ tester@testhost:/var/www/test',
|
||||
);
|
||||
|
||||
// Check total of Executed Commands
|
||||
$this->assertEquals(count($testCase), count($ranCommands));
|
||||
|
||||
// Check Generated Commands
|
||||
foreach ($testCase as $index => $command) {
|
||||
$this->assertEquals($command, $ranCommands[$index]);
|
||||
}
|
||||
|
||||
$this->assertTrue(strpos($tester->getDisplay(), '[Custom] Dummy Task') !== false);
|
||||
|
||||
$this->assertEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testDeploymentWithErrorTaskCommands()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/testhost-with-error.yml');
|
||||
|
||||
$application->getRuntime()->setReleaseId('20170101015120');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$ranCommands = $application->getRuntime()->getRanCommands();
|
||||
|
||||
$testCase = array(
|
||||
0 => 'git branch | grep "*"',
|
||||
1 => 'git checkout test',
|
||||
2 => 'git pull',
|
||||
3 => 'composer install --optimize-autoloader',
|
||||
4 => 'composer dump-autoload --optimize',
|
||||
5 => 'tar cfz /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\\"',
|
||||
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 xfz mageXYZ\\"',
|
||||
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"rm /var/www/test/releases/1234567890/mageXYZ\\"',
|
||||
);
|
||||
|
||||
// Check total of Executed Commands
|
||||
$this->assertEquals(count($testCase), count($ranCommands));
|
||||
|
||||
// Check Generated Commands
|
||||
foreach ($testCase as $index => $command) {
|
||||
$this->assertEquals($command, $ranCommands[$index]);
|
||||
}
|
||||
|
||||
$this->assertTrue(strpos($tester->getDisplay(), 'ERROR') !== false);
|
||||
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testDeploymentWithFailingPostDeployTaskCommands()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/testhost-with-postdeploy-error.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$ranCommands = $application->getRuntime()->getRanCommands();
|
||||
|
||||
$testCase = array(
|
||||
0 => 'git branch | grep "*"',
|
||||
1 => 'git checkout test',
|
||||
2 => 'git pull',
|
||||
3 => 'composer install --optimize-autoloader',
|
||||
4 => 'composer dump-autoload --optimize',
|
||||
5 => 'rsync -e "ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -avz --exclude=.git --exclude=./var/cache/* --exclude=./var/log/* --exclude=./web/app_dev.php ./ tester@testhost:/var/www/test',
|
||||
);
|
||||
|
||||
// Check total of Executed Commands
|
||||
$this->assertEquals(count($testCase), count($ranCommands));
|
||||
|
||||
// Check Generated Commands
|
||||
foreach ($testCase as $index => $command) {
|
||||
$this->assertEquals($command, $ranCommands[$index]);
|
||||
}
|
||||
|
||||
$this->assertTrue(strpos($tester->getDisplay(), 'ERROR') !== false);
|
||||
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testDeploymentWithSkippingTask()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/testhost-skipping.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$ranCommands = $application->getRuntime()->getRanCommands();
|
||||
|
||||
$testCase = array(
|
||||
0 => 'git branch | grep "*"',
|
||||
1 => 'git pull',
|
||||
2 => 'composer install --optimize-autoloader',
|
||||
3 => 'composer dump-autoload --optimize',
|
||||
4 => 'rsync -e "ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -avz --exclude=.git --exclude=./var/cache/* --exclude=./var/log/* --exclude=./web/app_dev.php ./ tester@testhost:/var/www/test',
|
||||
5 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& bin/console cache:warmup --env=dev\\"',
|
||||
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& bin/console assets:install web --env=dev --symlink --relative\\"',
|
||||
7 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& bin/console assetic:dump --env=dev\\"',
|
||||
8 => 'git branch | grep "*"',
|
||||
);
|
||||
|
||||
// Check total of Executed Commands
|
||||
$this->assertEquals(count($testCase), count($ranCommands));
|
||||
|
||||
// Check Generated Commands
|
||||
foreach ($testCase as $index => $command) {
|
||||
$this->assertEquals($command, $ranCommands[$index]);
|
||||
}
|
||||
|
||||
$this->assertTrue(strpos($tester->getDisplay(), 'SKIPPED') !== false);
|
||||
|
||||
$this->assertEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,339 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the Magallanes package.
|
||||
*
|
||||
* (c) Andrés Montañez <andres@andresmontanez.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Mage\Tests\Command\BuiltIn;
|
||||
|
||||
use Mage\Command\BuiltIn\DeployCommand;
|
||||
use Mage\Command\AbstractCommand;
|
||||
use Mage\Tests\MageApplicationMockup;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class DeployCommandWithReleasesTest extends TestCase
|
||||
{
|
||||
public function testDeploymentWithReleasesCommands()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/testhost.yml');
|
||||
|
||||
$application->getRuntime()->setReleaseId('20170101015120');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$ranCommands = $application->getRuntime()->getRanCommands();
|
||||
|
||||
$testCase = array(
|
||||
0 => 'git branch | grep "*"',
|
||||
1 => 'git checkout test',
|
||||
2 => 'git pull',
|
||||
3 => 'composer install --optimize-autoloader',
|
||||
4 => 'composer dump-autoload --optimize',
|
||||
5 => 'tar cfz /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\\"',
|
||||
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 xfz mageXYZ\\"',
|
||||
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"rm /var/www/test/releases/1234567890/mageXYZ\\"',
|
||||
10 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& bin/console cache:warmup --env=dev\\"',
|
||||
11 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& bin/console assets:install web --env=dev --symlink --relative\\"',
|
||||
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& bin/console assetic:dump --env=dev\\"',
|
||||
13 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& ln -snf releases/1234567890 current\\"',
|
||||
14 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"ls -1 /var/www/test/releases\\"',
|
||||
15 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"rm -rf /var/www/test/releases/20170101015110\\"',
|
||||
16 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"rm -rf /var/www/test/releases/20170101015111\\"',
|
||||
17 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"rm -rf /var/www/test/releases/20170101015112\\"',
|
||||
18 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"rm -rf /var/www/test/releases/20170101015113\\"',
|
||||
19 => 'rm /tmp/mageXYZ',
|
||||
20 => 'git checkout master',
|
||||
);
|
||||
|
||||
// Check total of Executed Commands
|
||||
$this->assertEquals(count($testCase), count($ranCommands));
|
||||
|
||||
// Check Generated Commands
|
||||
foreach ($testCase as $index => $command) {
|
||||
$this->assertEquals($command, $ranCommands[$index]);
|
||||
}
|
||||
|
||||
$this->assertEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testDeploymentWithoutReleasesTarPrepare()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/testhost-force-tar1.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$this->assertContains('This task is only available with releases enabled', $tester->getDisplay());
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testDeploymentWithoutReleasesTarCopy()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/testhost-force-tar2.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$this->assertContains('This task is only available with releases enabled', $tester->getDisplay());
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testDeploymentWithoutReleasesTarCleanup()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/testhost-force-tar3.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$this->assertContains('This task is only available with releases enabled', $tester->getDisplay());
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testDeploymentFailCopyCommands()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/testhost-fail-copy-tar.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$this->assertContains('Copying files with TarGZ ... FAIL', $tester->getDisplay());
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testDeploymentWithoutReleasesForceRelease()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/testhost-force-release.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$this->assertContains('This task is only available with releases enabled', $tester->getDisplay());
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testDeploymentFailToExtract()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/testhost.yml');
|
||||
|
||||
$application->getRuntime()->setReleaseId('20170101015120');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$application->getRuntime()->forceFail('ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& tar xfz mageXYZ\\"');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$ranCommands = $application->getRuntime()->getRanCommands();
|
||||
|
||||
$testCase = array(
|
||||
0 => 'git branch | grep "*"',
|
||||
1 => 'git checkout test',
|
||||
2 => 'git pull',
|
||||
3 => 'composer install --optimize-autoloader',
|
||||
4 => 'composer dump-autoload --optimize',
|
||||
5 => 'tar cfz /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\\"',
|
||||
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 xfz mageXYZ\\"',
|
||||
);
|
||||
|
||||
// Check total of Executed Commands
|
||||
$this->assertEquals(count($testCase), count($ranCommands));
|
||||
|
||||
// Check Generated Commands
|
||||
foreach ($testCase as $index => $command) {
|
||||
$this->assertEquals($command, $ranCommands[$index]);
|
||||
}
|
||||
|
||||
$this->assertContains('Running [Deploy] Copying files with TarGZ ... FAIL', $tester->getDisplay());
|
||||
$this->assertContains('Stage "On Deploy" did not finished successfully, halting command.', $tester->getDisplay());
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testDeploymentFailToCopy()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/testhost.yml');
|
||||
|
||||
$application->getRuntime()->setReleaseId('20170101015120');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$application->getRuntime()->forceFail('scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$ranCommands = $application->getRuntime()->getRanCommands();
|
||||
|
||||
$testCase = array(
|
||||
0 => 'git branch | grep "*"',
|
||||
1 => 'git checkout test',
|
||||
2 => 'git pull',
|
||||
3 => 'composer install --optimize-autoloader',
|
||||
4 => 'composer dump-autoload --optimize',
|
||||
5 => 'tar cfz /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\\"',
|
||||
7 => 'scp -P 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no /tmp/mageXYZ tester@testhost:/var/www/test/releases/1234567890/mageXYZ',
|
||||
);
|
||||
|
||||
// Check total of Executed Commands
|
||||
$this->assertEquals(count($testCase), count($ranCommands));
|
||||
|
||||
// Check Generated Commands
|
||||
foreach ($testCase as $index => $command) {
|
||||
$this->assertEquals($command, $ranCommands[$index]);
|
||||
}
|
||||
|
||||
$this->assertContains('Running [Deploy] Copying files with TarGZ ... FAIL', $tester->getDisplay());
|
||||
$this->assertContains('Stage "On Deploy" did not finished successfully, halting command.', $tester->getDisplay());
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testDeploymentFailCleanup()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/testhost.yml');
|
||||
|
||||
$application->getRuntime()->setReleaseId('20170101015120');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$application->getRuntime()->forceFail('rm /tmp/mageXYZ');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$ranCommands = $application->getRuntime()->getRanCommands();
|
||||
|
||||
$testCase = array(
|
||||
0 => 'git branch | grep "*"',
|
||||
1 => 'git checkout test',
|
||||
2 => 'git pull',
|
||||
3 => 'composer install --optimize-autoloader',
|
||||
4 => 'composer dump-autoload --optimize',
|
||||
5 => 'tar cfz /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\\"',
|
||||
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 xfz mageXYZ\\"',
|
||||
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"rm /var/www/test/releases/1234567890/mageXYZ\\"',
|
||||
10 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& bin/console cache:warmup --env=dev\\"',
|
||||
11 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& bin/console assets:install web --env=dev --symlink --relative\\"',
|
||||
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& bin/console assetic:dump --env=dev\\"',
|
||||
13 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& ln -snf releases/1234567890 current\\"',
|
||||
14 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"ls -1 /var/www/test/releases\\"',
|
||||
15 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"rm -rf /var/www/test/releases/20170101015110\\"',
|
||||
16 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"rm -rf /var/www/test/releases/20170101015111\\"',
|
||||
17 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"rm -rf /var/www/test/releases/20170101015112\\"',
|
||||
18 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"rm -rf /var/www/test/releases/20170101015113\\"',
|
||||
19 => 'rm /tmp/mageXYZ',
|
||||
);
|
||||
|
||||
// Check total of Executed Commands
|
||||
$this->assertEquals(count($testCase), count($ranCommands));
|
||||
|
||||
// Check Generated Commands
|
||||
foreach ($testCase as $index => $command) {
|
||||
$this->assertEquals($command, $ranCommands[$index]);
|
||||
}
|
||||
|
||||
$this->assertContains('Running [Deploy] Cleanup TarGZ file ... FAIL', $tester->getDisplay());
|
||||
$this->assertContains('Stage "Post Deploy" did not finished successfully, halting command.', $tester->getDisplay());
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testDeploymentFailMidway()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/testhost.yml');
|
||||
|
||||
$application->getRuntime()->setReleaseId('20170101015120');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$application->getRuntime()->forceFail('ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"ls -1 /var/www/test/releases\\"');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$ranCommands = $application->getRuntime()->getRanCommands();
|
||||
|
||||
$testCase = array(
|
||||
0 => 'git branch | grep "*"',
|
||||
1 => 'git checkout test',
|
||||
2 => 'git pull',
|
||||
3 => 'composer install --optimize-autoloader',
|
||||
4 => 'composer dump-autoload --optimize',
|
||||
5 => 'tar cfz /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\\"',
|
||||
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 xfz mageXYZ\\"',
|
||||
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"rm /var/www/test/releases/1234567890/mageXYZ\\"',
|
||||
10 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& bin/console cache:warmup --env=dev\\"',
|
||||
11 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& bin/console assets:install web --env=dev --symlink --relative\\"',
|
||||
12 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& bin/console assetic:dump --env=dev\\"',
|
||||
13 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& ln -snf releases/1234567890 current\\"',
|
||||
14 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"ls -1 /var/www/test/releases\\"',
|
||||
);
|
||||
|
||||
// Check total of Executed Commands
|
||||
$this->assertEquals(count($testCase), count($ranCommands));
|
||||
|
||||
// Check Generated Commands
|
||||
foreach ($testCase as $index => $command) {
|
||||
$this->assertEquals($command, $ranCommands[$index]);
|
||||
}
|
||||
|
||||
$this->assertContains('Running [Release] Cleaning up old Releases ... FAIL', $tester->getDisplay());
|
||||
$this->assertContains('Stage "Post Release" did not finished successfully, halting command.', $tester->getDisplay());
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the Magallanes package.
|
||||
*
|
||||
* (c) Andrés Montañez <andres@andresmontanez.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Mage\Tests\Command\BuiltIn;
|
||||
|
||||
use Mage\Command\BuiltIn\DeployCommand;
|
||||
use Mage\Command\AbstractCommand;
|
||||
use Mage\Tests\MageApplicationMockup;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class DeployCommandWithoutReleasesTest extends TestCase
|
||||
{
|
||||
public function testDeploymentWithoutReleasesCommands()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/testhost-without-releases.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$ranCommands = $application->getRuntime()->getRanCommands();
|
||||
|
||||
$testCase = array(
|
||||
0 => 'git branch | grep "*"',
|
||||
1 => 'git checkout test',
|
||||
2 => 'git pull',
|
||||
3 => 'composer install --optimize-autoloader',
|
||||
4 => 'composer dump-autoload --optimize',
|
||||
5 => 'rsync -e "ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -avz --exclude=.git --exclude=./var/cache/* --exclude=./var/log/* --exclude=./web/app_dev.php ./ tester@testhost:/var/www/test',
|
||||
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& bin/console cache:warmup --env=dev\\"',
|
||||
7 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& bin/console assets:install web --env=dev --symlink --relative\\"',
|
||||
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& bin/console assetic:dump --env=dev\\"',
|
||||
9 => 'git checkout master',
|
||||
);
|
||||
|
||||
// Check total of Executed Commands
|
||||
$this->assertEquals(count($testCase), count($ranCommands));
|
||||
|
||||
// Check Generated Commands
|
||||
foreach ($testCase as $index => $command) {
|
||||
$this->assertEquals($command, $ranCommands[$index]);
|
||||
}
|
||||
|
||||
$this->assertEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testDeploymentFailMidway()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/testhost-without-releases.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('deploy');
|
||||
$this->assertTrue($command instanceof DeployCommand);
|
||||
|
||||
$application->getRuntime()->forceFail('rsync -e "ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -avz --exclude=.git --exclude=./var/cache/* --exclude=./var/log/* --exclude=./web/app_dev.php ./ tester@testhost:/var/www/test');
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$ranCommands = $application->getRuntime()->getRanCommands();
|
||||
|
||||
$testCase = array(
|
||||
0 => 'git branch | grep "*"',
|
||||
1 => 'git checkout test',
|
||||
2 => 'git pull',
|
||||
3 => 'composer install --optimize-autoloader',
|
||||
4 => 'composer dump-autoload --optimize',
|
||||
5 => 'rsync -e "ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -avz --exclude=.git --exclude=./var/cache/* --exclude=./var/log/* --exclude=./web/app_dev.php ./ tester@testhost:/var/www/test',
|
||||
);
|
||||
|
||||
// Check total of Executed Commands
|
||||
$this->assertEquals(count($testCase), count($ranCommands));
|
||||
|
||||
// Check Generated Commands
|
||||
foreach ($testCase as $index => $command) {
|
||||
$this->assertEquals($command, $ranCommands[$index]);
|
||||
}
|
||||
|
||||
$this->assertContains('Stage "On Deploy" did not finished successfully, halting command.', $tester->getDisplay());
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the Magallanes package.
|
||||
*
|
||||
* (c) Andrés Montañez <andres@andresmontanez.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Mage\Tests\Command\BuiltIn\Releases;
|
||||
|
||||
use Mage\Command\BuiltIn\Releases\ListCommand;
|
||||
use Mage\Command\AbstractCommand;
|
||||
use Mage\Tests\MageApplicationMockup;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class ListCommandTest extends TestCase
|
||||
{
|
||||
public function testListReleasesCommands()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../../Resources/testhost.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('releases:list');
|
||||
$this->assertTrue($command instanceof ListCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
|
||||
$ranCommands = $application->getRuntime()->getRanCommands();
|
||||
|
||||
$testCase = array(
|
||||
0 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"ls -1 /var/www/test/releases\\"',
|
||||
1 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"readlink -f /var/www/test/current\\"',
|
||||
);
|
||||
|
||||
// Check total of Executed Commands
|
||||
$this->assertEquals(count($testCase), count($ranCommands));
|
||||
|
||||
// Check Generated Commands
|
||||
foreach ($testCase as $index => $command) {
|
||||
$this->assertEquals($command, $ranCommands[$index]);
|
||||
}
|
||||
}
|
||||
|
||||
public function testListReleasesWithInvalidEnvironment()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../../Resources/testhost.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('releases:list');
|
||||
$this->assertTrue($command instanceof ListCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'developers']);
|
||||
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
$this->assertContains('The environment "developers" does not exists.', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testListReleasesWithoutReleases()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../../Resources/testhost-without-releases.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('releases:list');
|
||||
$this->assertTrue($command instanceof ListCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
$this->assertContains('Releases are not enabled', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testFailToGetCurrentRelease()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../../Resources/testhost-fail-get-current.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('releases:list');
|
||||
$this->assertTrue($command instanceof ListCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
$this->assertContains('Unable to retrieve current release from host "host1"', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testNoReleasesAvailable()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../../Resources/testhost-no-releases.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('releases:list');
|
||||
$this->assertTrue($command instanceof ListCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
$this->assertContains('No releases available on host host2', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testFailGetReleases()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../../Resources/testhost-fail-get-releases.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('releases:list');
|
||||
$this->assertTrue($command instanceof ListCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
$this->assertContains('Unable to retrieve releases from host "host3"', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testNoHosts()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../../Resources/testhost-no-hosts.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('releases:list');
|
||||
$this->assertTrue($command instanceof ListCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
|
||||
$this->assertContains('No hosts defined', $tester->getDisplay());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the Magallanes package.
|
||||
*
|
||||
* (c) Andrés Montañez <andres@andresmontanez.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Mage\Tests\Command\BuiltIn\Releases;
|
||||
|
||||
use Mage\Command\BuiltIn\Releases\RollbackCommand;
|
||||
use Mage\Command\AbstractCommand;
|
||||
use Mage\Tests\MageApplicationMockup;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class RollbackCommandTest extends TestCase
|
||||
{
|
||||
public function testRollbackReleaseCommands()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../../Resources/testhost.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('releases:rollback');
|
||||
$this->assertTrue($command instanceof RollbackCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test', 'release' => '20170101015115']);
|
||||
|
||||
$ranCommands = $application->getRuntime()->getRanCommands();
|
||||
|
||||
$testCase = array(
|
||||
0 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"ls -1 /var/www/test/releases\\"',
|
||||
1 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& ln -snf releases/20170101015115 current\\"',
|
||||
);
|
||||
|
||||
// Check total of Executed Commands
|
||||
$this->assertEquals(count($testCase), count($ranCommands));
|
||||
|
||||
// Check Generated Commands
|
||||
foreach ($testCase as $index => $command) {
|
||||
$this->assertEquals($command, $ranCommands[$index]);
|
||||
}
|
||||
}
|
||||
|
||||
public function testRollbackReleaseWithInvalidEnvironment()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../../Resources/testhost.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('releases:rollback');
|
||||
$this->assertTrue($command instanceof RollbackCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'developers', 'release' => '20170101015115']);
|
||||
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
$this->assertContains('The environment "developers" does not exists.', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testRollbackReleaseWithoutReleases()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../../Resources/testhost-without-releases.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('releases:rollback');
|
||||
$this->assertTrue($command instanceof RollbackCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test', 'release' => '20170101015115']);
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
$this->assertContains('Releases are not enabled', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testRollbackReleaseNotAvailable()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../../Resources/testhost-not-have-release.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('releases:rollback');
|
||||
$this->assertTrue($command instanceof RollbackCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
|
||||
$tester->execute(['command' => $command->getName(), 'environment' => 'test', 'release' => '20170101015115']);
|
||||
$this->assertNotEquals(0, $tester->getStatusCode());
|
||||
$this->assertContains('Release "20170101015115" is not available on all hosts', $tester->getDisplay());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of the Magallanes package.
|
||||
*
|
||||
* (c) Andrés Montañez <andres@andresmontanez.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Mage\Tests\Command\BuiltIn;
|
||||
|
||||
use Mage\Command\AbstractCommand;
|
||||
use Mage\Command\BuiltIn\VersionCommand;
|
||||
use Mage\Tests\MageApplicationMockup;
|
||||
use Mage\Mage;
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use PHPUnit_Framework_TestCase as TestCase;
|
||||
|
||||
class VersionCommandTest extends TestCase
|
||||
{
|
||||
public function testVersionOutput()
|
||||
{
|
||||
$application = new MageApplicationMockup();
|
||||
$application->configure(__DIR__ . '/../../Resources/basic.yml');
|
||||
|
||||
/** @var AbstractCommand $command */
|
||||
$command = $application->find('version');
|
||||
$this->assertTrue($command instanceof VersionCommand);
|
||||
|
||||
$tester = new CommandTester($command);
|
||||
$tester->execute(['command' => $command->getName()]);
|
||||
|
||||
$output = trim($tester->getDisplay());
|
||||
$this->assertEquals(sprintf('Magallanes v%s [%s]', Mage::VERSION, Mage::CODENAME), $output);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user