/
RollbackCommandTest.php
115 lines (105 loc) · 4.94 KB
/
RollbackCommandTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?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\MageTestApplication;
use Mage\Tests\Runtime\RuntimeMockup;
use Symfony\Component\Console\Tester\CommandTester;
use PHPUnit_Framework_TestCase as TestCase;
class RollbackCommandTest extends TestCase
{
public function testRollbackReleaseCommands()
{
$application = new MageTestApplication();
$application->add(new RollbackCommand());
$runtime = new RuntimeMockup();
$runtime->setConfiguration(array(
'environments' =>
array(
'test' =>
array(
'user' => 'tester',
'branch' => 'test',
'host_path' => '/var/www/test',
'releases' => 4,
'exclude' =>
array(
0 => 'vendor',
1 => 'app/cache',
2 => 'app/log',
3 => 'web/app_dev.php',
),
'hosts' =>
array(
0 => 'testhost',
),
'pre-deploy' =>
array(
0 => 'git/update',
1 => 'composer/install',
2 => 'composer/generate-autoload',
),
'on-deploy' =>
array(
0 =>
array(
'symfony/cache-clear' =>
array(
'env' => 'dev',
),
),
1 =>
array(
'symfony/cache-warmup' =>
array(
'env' => 'dev',
),
),
2 =>
array(
'symfony/assets-install' =>
array(
'env' => 'dev',
),
),
3 =>
array(
'symfony/assetic-dump' =>
array(
'env' => 'dev',
),
),
),
'on-release' => null,
'post-release' => null,
'post-deploy' => null,
),
),
)
);
/** @var AbstractCommand $command */
$command = $application->find('releases:rollback');
$command->setRuntime($runtime);
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName(), 'environment' => 'test', 'release' => '20170101015115']);
$ranCommands = $runtime->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]);
}
}
}