-
Notifications
You must be signed in to change notification settings - Fork 164
/
DeployCommandMiscTasksTest.php
151 lines (111 loc) · 6.14 KB
/
DeployCommandMiscTasksTest.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?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(__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 "cd /var/www/test && bin/console cache:warmup --env=testenv"',
2 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "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 "cd /var/www/test && bin/console assetic:dump --env=testenv"',
4 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost "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(__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(__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(__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(__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(__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());
}
}