-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDeleteContext.php
More file actions
96 lines (85 loc) · 2.75 KB
/
DeleteContext.php
File metadata and controls
96 lines (85 loc) · 2.75 KB
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
<?php
use Behat\Behat\Context\Context;
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
/**
* Defines behat context for ``ee cron delete``.
*/
class DeleteContext implements Context
{
private SharedContext $shared_context;
/**
* Initializes context.
*/
public function __construct()
{
}
/**
* @BeforeScenario
*/
public function gatherSharedContext(BeforeScenarioScope $scope)
{
$this->shared_context = $scope->getEnvironment()->getContext(SharedContext::class);
}
/**
* @When I delete that cron job
*/
function delete_created_cron()
{
$this->shared_context->command = "ee cron delete {$this->shared_context->cron_created}";
exec($this->shared_context->command, $output, $return_status);
$this->shared_context->output = implode($output);
$this->shared_context->return_status = $return_status;
}
/**
* @Then I should see success message for deleting cron job
* @throws Exception: If the output is not as expected
*/
function success_message_for_deleting_cron()
{
$id_to_delete = $this->shared_context->cron_created;
if (false === strpos($this->shared_context->output, "Success: Deleted cron with id $id_to_delete")) {
throw new Exception("Expected output to contain `Deleted cron job` but got:\n\n" . $this->shared_context->output);
}
}
/**
* @Then I should not see the cron job in the list of crons
* @throws Exception: If the output is not as expected
*/
function cron_deleted()
{
exec("ee cron list --all | awk '{print $1}'", $output, $return_status);
$output = array_map(
function ($line) {
return trim($line);
},
$output
);
if (in_array((string) $this->shared_context->cron_created, $output)) {
throw new Exception("Cron job was not deleted. Expected output to not contain `{$this->shared_context->sites_created[0]}` but got:\n\n" . $output);
}
}
/**
* @When I delete a cron job that does not exist
* @throws Exception: If the randomness is not random?
*/
function delete_non_existent_cron() {
$this->shared_context->cron_created = random_int(1, 65535);
$this->shared_context->command = "ee cron delete {$this->shared_context->cron_created}";
exec($this->shared_context->command, $output, $return_status);
$this->shared_context->output = implode($output);
$this->shared_context->return_status = $return_status;
}
/**
* @Then I should see an error message for deleting cron job
* @throws Exception: If the output is not empty
*/
function error_message_for_deleting_non_existent_cron() {
if ("" === trim($this->shared_context->output)) {
// Error is directly thrown to stderr
return;
}
throw new Exception("Expected an error message for deleting a non-existent cron job but got an empty output.");
}
}