|
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 ParallelTest extends AbstractTest |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
public const RECIPE = __DIR__ . '/recipe/parallel.php'; |
|
15
|
|
|
|
|
16
|
|
|
public static function setUpBeforeClass(): void |
|
17
|
|
|
{ |
|
18
|
|
|
parent::setUpBeforeClass(); |
|
19
|
|
|
putenv('DEPLOYER_LOCAL_WORKER=false'); // Allow to start workers. Don't forget to disable it later. |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public static function tearDownAfterClass(): void |
|
23
|
|
|
{ |
|
24
|
|
|
putenv('DEPLOYER_LOCAL_WORKER=true'); |
|
25
|
|
|
parent::tearDownAfterClass(); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testWorker() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->init(self::RECIPE); |
|
31
|
|
|
$this->tester->run([ |
|
32
|
|
|
'echo', |
|
33
|
|
|
'-f' => self::RECIPE, |
|
34
|
|
|
'selector' => 'all', |
|
35
|
|
|
], [ |
|
36
|
|
|
'verbosity' => Output::VERBOSITY_NORMAL, |
|
37
|
|
|
]); |
|
38
|
|
|
self::assertEquals(0, $this->tester->getStatusCode(), $this->tester->getDisplay()); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
public function testServer() |
|
42
|
|
|
{ |
|
43
|
|
|
$this->init(self::RECIPE); |
|
44
|
|
|
$this->tester->setInputs(['prod', 'Black bear']); |
|
45
|
|
|
$this->tester->run([ |
|
46
|
|
|
'ask', |
|
47
|
|
|
'-f' => self::RECIPE, |
|
48
|
|
|
], [ |
|
49
|
|
|
'verbosity' => Output::VERBOSITY_NORMAL, |
|
50
|
|
|
'interactive' => true, |
|
51
|
|
|
]); |
|
52
|
|
|
$display = $this->tester->getDisplay(); |
|
53
|
|
|
self::assertEquals(0, $this->tester->getStatusCode(), $display); |
|
54
|
|
|
self::assertStringContainsString('[prod] Question: What kind of bear is best?', $display); |
|
55
|
|
|
self::assertStringContainsString('[prod] Black bear', $display); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function testOption() |
|
59
|
|
|
{ |
|
60
|
|
|
$this->init(self::RECIPE); |
|
61
|
|
|
$this->tester->run( |
|
62
|
|
|
[ |
|
63
|
|
|
'echo', |
|
64
|
|
|
'selector' => 'all', |
|
65
|
|
|
'-o' => ['greet=Hello'], |
|
66
|
|
|
'-f' => self::RECIPE, |
|
67
|
|
|
//'-l' => 1, |
|
68
|
|
|
], |
|
69
|
|
|
[ |
|
70
|
|
|
'verbosity' => Output::VERBOSITY_DEBUG, |
|
71
|
|
|
'interactive' => false, |
|
72
|
|
|
], |
|
73
|
|
|
); |
|
74
|
|
|
|
|
75
|
|
|
$display = $this->tester->getDisplay(); |
|
76
|
|
|
self::assertEquals(0, $this->tester->getStatusCode(), $display); |
|
77
|
|
|
self::assertStringContainsString('[prod] Hello, prod!', $display); |
|
78
|
|
|
self::assertStringContainsString('[beta] Hello, beta!', $display); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function testCachedHostConfig() |
|
82
|
|
|
{ |
|
83
|
|
|
$this->init(self::RECIPE); |
|
84
|
|
|
$this->tester->run([ |
|
85
|
|
|
'cache_config_test', |
|
86
|
|
|
'-f' => self::RECIPE, |
|
87
|
|
|
'selector' => 'all', |
|
88
|
|
|
], [ |
|
89
|
|
|
'verbosity' => Output::VERBOSITY_NORMAL, |
|
90
|
|
|
]); |
|
91
|
|
|
|
|
92
|
|
|
$display = $this->tester->getDisplay(); |
|
93
|
|
|
self::assertEquals(0, $this->tester->getStatusCode(), $display); |
|
94
|
|
|
self::assertTrue(substr_count($display, 'worker on prod') == 1, $display); |
|
95
|
|
|
self::assertTrue(substr_count($display, 'worker on beta') == 1, $display); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function testHostConfigFromCallback() |
|
99
|
|
|
{ |
|
100
|
|
|
$this->init(self::RECIPE); |
|
101
|
|
|
$this->tester->run([ |
|
102
|
|
|
'host_config_from_callback', |
|
103
|
|
|
'-f' => self::RECIPE, |
|
104
|
|
|
'selector' => 'all', |
|
105
|
|
|
], [ |
|
106
|
|
|
'verbosity' => Output::VERBOSITY_NORMAL, |
|
107
|
|
|
]); |
|
108
|
|
|
|
|
109
|
|
|
$display = $this->tester->getDisplay(); |
|
110
|
|
|
self::assertEquals(0, $this->tester->getStatusCode(), $display); |
|
111
|
|
|
self::assertTrue(substr_count($display, '[prod] config value is from global') == 1, $display); |
|
112
|
|
|
self::assertTrue(substr_count($display, '[beta] config value is from callback') == 1, $display); |
|
113
|
|
|
} |
|
114
|
|
|
} |
|
115
|
|
|
|