1 | <?php |
||
2 | /* (c) Anton Medvedev <[email protected]> |
||
3 | * |
||
4 | * For the full copyright and license information, please view the LICENSE |
||
5 | * file that was distributed with this source code. |
||
6 | */ |
||
7 | |||
8 | namespace Deployer; |
||
9 | |||
10 | use Symfony\Component\Console\Output\Output; |
||
11 | |||
12 | class DeployTest extends AbstractTest |
||
0 ignored issues
–
show
Deprecated Code
introduced
by
![]() |
|||
13 | { |
||
14 | public const RECIPE = __DIR__ . '/recipe/deploy.php'; |
||
15 | |||
16 | public function testDeploy() |
||
17 | { |
||
18 | $display = $this->dep(self::RECIPE, 'deploy'); |
||
0 ignored issues
–
show
Are you sure the assignment to
$display is correct as $this->dep(self::RECIPE, 'deploy') targeting Deployer\AbstractTest::dep() seems to always return null.
This check looks for function or method calls that always return null and whose return value is assigned to a variable. class A
{
function getObject()
{
return null;
}
}
$a = new A();
$object = $a->getObject();
The method The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes. ![]() |
|||
19 | |||
20 | $display = $this->tester->getDisplay(); |
||
21 | self::assertEquals(0, $this->tester->getStatusCode(), $display); |
||
22 | |||
23 | foreach ($this->deployer->hosts as $host) { |
||
24 | $deployPath = $host->get('deploy_path'); |
||
25 | |||
26 | self::assertDirectoryExists($deployPath . '/.dep'); |
||
27 | self::assertDirectoryExists($deployPath . '/releases'); |
||
28 | self::assertDirectoryExists($deployPath . '/shared'); |
||
29 | self::assertDirectoryExists($deployPath . '/current'); |
||
30 | self::assertDirectoryExists($deployPath . '/current/'); |
||
31 | self::assertFileExists($deployPath . '/current/README.md'); |
||
32 | self::assertDirectoryExists($deployPath . '/current/storage/logs'); |
||
33 | self::assertDirectoryExists($deployPath . '/current/storage/db'); |
||
34 | self::assertDirectoryExists($deployPath . '/shared/storage/logs'); |
||
35 | self::assertDirectoryExists($deployPath . '/shared/storage/db'); |
||
36 | self::assertFileExists($deployPath . '/shared/uploads/poem.txt'); |
||
37 | self::assertFileExists($deployPath . '/shared/.env'); |
||
38 | self::assertFileExists($deployPath . '/current/config/test.yaml'); |
||
39 | self::assertFileExists($deployPath . '/shared/config/test.yaml'); |
||
40 | self::assertEquals(1, intval(exec("cd $deployPath && ls -1 releases | wc -l"))); |
||
41 | } |
||
42 | } |
||
43 | |||
44 | public function testDeploySelectHosts() |
||
45 | { |
||
46 | $this->init(self::RECIPE); |
||
47 | $this->tester->setInputs(['0,1']); |
||
48 | $this->tester->run(['deploy', '-f' => self::RECIPE, '-l' => 1], [ |
||
49 | 'verbosity' => Output::VERBOSITY_NORMAL, |
||
50 | 'interactive' => true, |
||
51 | ]); |
||
52 | self::assertEquals(0, $this->tester->getStatusCode(), $this->tester->getDisplay()); |
||
53 | } |
||
54 | |||
55 | public function testKeepReleases() |
||
56 | { |
||
57 | for ($i = 0; $i < 3; $i++) { |
||
58 | $this->dep(self::RECIPE, 'deploy'); |
||
59 | self::assertEquals(0, $this->tester->getStatusCode(), $this->tester->getDisplay()); |
||
60 | } |
||
61 | |||
62 | for ($i = 0; $i < 6; $i++) { |
||
63 | $this->dep(self::RECIPE, 'deploy:fail'); |
||
64 | self::assertEquals(1, $this->tester->getStatusCode(), $this->tester->getDisplay()); |
||
65 | } |
||
66 | |||
67 | for ($i = 0; $i < 3; $i++) { |
||
68 | $this->dep(self::RECIPE, 'deploy'); |
||
69 | self::assertEquals(0, $this->tester->getStatusCode(), $this->tester->getDisplay()); |
||
70 | } |
||
71 | |||
72 | foreach ($this->deployer->hosts as $host) { |
||
73 | $deployPath = $host->get('deploy_path'); |
||
74 | |||
75 | self::assertEquals(3, intval(exec("cd $deployPath && ls -1 releases | wc -l"))); |
||
76 | } |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * @depends testKeepReleases |
||
81 | */ |
||
82 | public function testRollback() |
||
83 | { |
||
84 | $this->dep(self::RECIPE, 'rollback'); |
||
85 | |||
86 | self::assertEquals(0, $this->tester->getStatusCode(), $this->tester->getDisplay()); |
||
87 | |||
88 | foreach ($this->deployer->hosts as $host) { |
||
89 | $deployPath = $host->get('deploy_path'); |
||
90 | |||
91 | self::assertEquals(3, intval(exec("cd $deployPath && ls -1 releases | wc -l"))); |
||
92 | } |
||
93 | } |
||
94 | |||
95 | public function testFail() |
||
96 | { |
||
97 | $this->dep(self::RECIPE, 'deploy:fail'); |
||
98 | |||
99 | $display = $this->tester->getDisplay(); |
||
100 | self::assertEquals(1, $this->tester->getStatusCode(), $display); |
||
101 | |||
102 | foreach ($this->deployer->hosts as $host) { |
||
103 | $deployPath = $host->get('deploy_path'); |
||
104 | |||
105 | self::assertEquals('ok', exec("cd $deployPath && [ -f .dep/deploy.lock ] || echo ok"), 'fail hooks deploy:unlock did not run'); |
||
106 | } |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * @depends testFail |
||
111 | */ |
||
112 | public function testCleanup() |
||
113 | { |
||
114 | $this->dep(self::RECIPE, 'deploy:cleanup'); |
||
115 | |||
116 | self::assertEquals(0, $this->tester->getStatusCode(), $this->tester->getDisplay()); |
||
117 | |||
118 | foreach ($this->deployer->hosts as $host) { |
||
119 | $deployPath = $host->get('deploy_path'); |
||
120 | |||
121 | self::assertFileDoesNotExist($deployPath . '/release'); |
||
122 | } |
||
123 | } |
||
124 | |||
125 | public function testIsUnlockedExitsWithOneWhenDeployIsLocked() |
||
126 | { |
||
127 | $this->dep(self::RECIPE, 'deploy:lock'); |
||
128 | $this->dep(self::RECIPE, 'deploy:is_locked'); |
||
129 | $display = $this->tester->getDisplay(); |
||
130 | |||
131 | self::assertStringContainsString('Deploy is locked by ', $display); |
||
132 | self::assertSame(1, $this->tester->getStatusCode()); |
||
133 | } |
||
134 | |||
135 | public function testIsUnlockedExitsWithZeroWhenDeployIsNotLocked() |
||
136 | { |
||
137 | $this->dep(self::RECIPE, 'deploy:unlock'); |
||
138 | $this->dep(self::RECIPE, 'deploy:is_locked'); |
||
139 | $display = $this->tester->getDisplay(); |
||
140 | |||
141 | self::assertStringContainsString('Deploy is unlocked.', $display); |
||
142 | self::assertSame(0, $this->tester->getStatusCode()); |
||
143 | } |
||
144 | } |
||
145 |