mirror of
https://github.com/hauke68/Magallanes.git
synced 2026-08-29 10:38:57 +02:00
Change structure.
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user