forked from drush-ops/drush
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DeployHookTest.php
97 lines (81 loc) · 4.4 KB
/
DeployHookTest.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
<?php
namespace Unish;
use Webmozart\PathUtil\Path;
/**
* @group slow
* @group commands
*/
class DeployHookTest extends CommandUnishTestCase
{
use TestModuleHelperTrait;
public function testDeployHooks()
{
$this->setUpDrupal(1, true);
$options = [
'yes' => null,
];
$this->setupModulesForTests(['woot'], Path::join(__DIR__, '/../fixtures/modules'));
$this->drush('pm-install', ['woot'], $options);
// Run deploy hooks.
$this->drush('deploy:hook', [], $options, null, null, self::EXIT_ERROR);
$this->assertStringContainsString('woot a Successful deploy hook.', $this->getOutput());
$this->assertStringContainsString('woot batch Successful batched deploy hook.', $this->getOutput());
$this->assertStringContainsString('woot failing Failing deploy hook.', $this->getOutput());
$this->assertStringContainsString('[notice] Deploy hook started: woot_deploy_a', $this->getErrorOutput());
$this->assertStringContainsString('[notice] This is the update message from woot_deploy_a', $this->getErrorOutput());
$this->assertStringContainsString('[notice] Deploy hook started: woot_deploy_batch', $this->getErrorOutput());
$this->assertStringContainsString('[notice] Iteration 1.', $this->getErrorOutput());
$this->assertStringContainsString('[notice] Iteration 2.', $this->getErrorOutput());
$this->assertStringContainsString('[notice] Finished at 3.', $this->getErrorOutput());
$this->assertStringContainsString('[notice] Deploy hook started: woot_deploy_failing', $this->getErrorOutput());
$this->assertStringContainsString('[error] This is the exception message thrown in woot_deploy_failing', $this->getErrorOutput());
$this->assertStringContainsString('[error] Finished performing deploy hooks.', $this->getErrorOutput());
// Set the drupal state so that the failing hook passes
$this->drush('state:set', ['woot_deploy_pass', 'true'], [], null, null, self::EXIT_SUCCESS);
// Run deploy hooks again.
$this->drush('deploy:hook', [], $options, null, null, self::EXIT_SUCCESS);
$this->assertStringContainsString('woot failing Failing deploy hook.', $this->getOutput());
$this->assertStringContainsString('[notice] Deploy hook started: woot_deploy_failing', $this->getErrorOutput());
$this->assertStringContainsString('[notice] Now woot_deploy_failing is passing', $this->getErrorOutput());
$this->assertStringContainsString('[success] Finished performing deploy hooks.', $this->getErrorOutput());
// This time there is nothing more to run.
$this->drush('deploy:hook', [], [], null, null, self::EXIT_SUCCESS);
$this->assertStringContainsString('[success] No pending deploy hooks.', $this->getErrorOutput());
$this->assertStringNotContainsString('Finished performing deploy hooks.', $this->getErrorOutput());
}
public function testSkipDeployHooks()
{
$this->setUpDrupal(1, true);
$this->setupModulesForTests(['woot'], Path::join(__DIR__, '/../fixtures/modules'));
$this->drush('pm-install', ['woot'], ['yes' => null]);
$options = [
'format' => 'json'
];
$hooks = [
[
"module" => "woot",
"hook" => "a",
"description" => "Successful deploy hook.",
],
[
"module" => "woot",
"hook" => "batch",
"description" => "Successful batched deploy hook.",
],
[
"module" => "woot",
"hook" => "failing",
"description" => "Failing deploy hook.",
],
];
// Check pending deploy hooks.
$this->drush('deploy:hook-status', [], $options, null, null, self::EXIT_SUCCESS);
$this->assertEquals($hooks, $this->getOutputFromJSON());
// Mark them all as having run.
$this->drush('deploy:mark-complete', [], [], null, null, self::EXIT_SUCCESS);
$this->assertStringContainsString('[success] Marked 3 pending deploy hooks as complete.', $this->getErrorOutput());
// Check again to see no pending hooks.
$this->drush('deploy:hook-status', [], $options, null, null, self::EXIT_SUCCESS);
$this->assertStringContainsString('[]', $this->getOutput());
}
}