magallanes/src/Mage/Tests/Command/BuiltIn/Releases/RollbackCommandTest.php

97 lines
3.9 KiB
PHP
Raw Normal View History

2017-01-01 05:28:58 +01:00
<?php
2017-01-01 22:20:43 +01:00
/*
* 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.
*/
2017-01-01 05:28:58 +01:00
namespace Mage\Tests\Command\BuiltIn\Releases;
use Mage\Command\BuiltIn\Releases\RollbackCommand;
use Mage\Command\AbstractCommand;
2017-01-05 01:46:40 +01:00
use Mage\Tests\MageApplicationMockup;
2017-01-01 05:28:58 +01:00
use Symfony\Component\Console\Tester\CommandTester;
use PHPUnit_Framework_TestCase as TestCase;
2017-01-01 05:28:58 +01:00
class RollbackCommandTest extends TestCase
{
public function testRollbackReleaseCommands()
{
2017-01-05 01:46:40 +01:00
$application = new MageApplicationMockup();
$application->configure(__DIR__ . '/../../../Resources/testhost.yml');
2017-01-01 05:28:58 +01:00
/** @var AbstractCommand $command */
$command = $application->find('releases:rollback');
2017-01-05 01:46:40 +01:00
$this->assertTrue($command instanceof RollbackCommand);
2017-01-01 05:28:58 +01:00
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName(), 'environment' => 'test', 'release' => '20170101015115']);
2017-01-05 01:46:40 +01:00
$ranCommands = $application->getRuntime()->getRanCommands();
2017-01-01 05:28:58 +01:00
2017-01-01 05:34:14 +01:00
$testCase = array(
2017-01-01 05:28:58 +01:00
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
2017-01-01 22:20:43 +01:00
$this->assertEquals(count($testCase), count($ranCommands));
2017-01-01 05:28:58 +01:00
// Check Generated Commands
foreach ($testCase as $index => $command) {
2017-01-01 22:20:43 +01:00
$this->assertEquals($command, $ranCommands[$index]);
2017-01-01 05:28:58 +01:00
}
}
2017-01-05 02:21:38 +01:00
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);
2017-01-06 02:14:35 +01:00
$tester = new CommandTester($command);
2017-01-07 05:53:57 +01:00
$tester->execute(['command' => $command->getName(), 'environment' => 'test', 'release' => '20170101015115']);
$this->assertNotEquals(0, $tester->getStatusCode());
$this->assertContains('Releases are not enabled', $tester->getDisplay());
2017-01-05 02:21:38 +01:00
}
2017-01-06 02:14:35 +01:00
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);
2017-01-07 05:53:57 +01:00
$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());
2017-01-06 02:14:35 +01:00
}
2017-01-01 05:34:14 +01:00
}