-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathcron-event.feature
More file actions
160 lines (139 loc) · 4.71 KB
/
Copy pathcron-event.feature
File metadata and controls
160 lines (139 loc) · 4.71 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
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
152
153
154
155
156
157
158
159
160
Feature: Manage WP Cron events
Background:
Given a WP install
# Fails on WordPress 4.9 because `wp cron event run --due-now`
# executes the "wp_privacy_delete_old_export_files" event there.
@require-wp-5.0
Scenario: --due-now with supplied events should only run those
# WP throws a notice here for older versions of core.
When I try `wp cron event run --all`
Then STDOUT should contain:
"""
Success: Executed a total of
"""
When I run `wp cron event run --due-now`
Then STDOUT should contain:
"""
Executed a total of 0 cron events
"""
When I run `wp cron event schedule wp_cli_test_event_1 now hourly`
Then STDOUT should contain:
"""
Success: Scheduled event with hook 'wp_cli_test_event_1'
"""
When I run `wp cron event schedule wp_cli_test_event_2 now hourly`
Then STDOUT should contain:
"""
Success: Scheduled event with hook 'wp_cli_test_event_2'
"""
When I run `wp cron event run wp_cli_test_event_1 --due-now`
Then STDOUT should contain:
"""
Executed the cron event 'wp_cli_test_event_1'
"""
And STDOUT should contain:
"""
Executed a total of 1 cron event
"""
When I run `wp cron event run --due-now --exclude=wp_cli_test_event_2`
Then STDOUT should contain:
"""
Executed a total of 0 cron events
"""
When I run `wp cron event run wp_cli_test_event_2 --due-now`
Then STDOUT should contain:
"""
Executed the cron event 'wp_cli_test_event_2'
"""
And STDOUT should contain:
"""
Executed a total of 1 cron event
"""
@require-wp-4.9.0
Scenario: Unschedule cron event
When I run `wp cron event schedule wp_cli_test_event_1 now hourly`
And I try `wp cron event unschedule wp_cli_test_event_1`
Then STDOUT should contain:
"""
Success: Unscheduled 1 event for hook 'wp_cli_test_event_1'.
"""
When I run `wp cron event schedule wp_cli_test_event_2 now hourly`
And I run `wp cron event schedule wp_cli_test_event_2 '+1 hour' hourly`
And I try `wp cron event unschedule wp_cli_test_event_2`
Then STDOUT should contain:
"""
Success: Unscheduled 2 events for hook 'wp_cli_test_event_2'.
"""
When I try `wp cron event unschedule wp_cli_test_event`
Then STDERR should be:
"""
Error: No events found for hook 'wp_cli_test_event'.
"""
Scenario: Run cron event with a registered shutdown function
Given a wp-content/mu-plugins/setup_shutdown_function.php file:
"""
add_action('mycron', function() {
breakthings();
});
register_shutdown_function(function() {
$error = error_get_last();
if ($error['type'] === E_ERROR) {
WP_CLI::line('MY SHUTDOWN FUNCTION');
}
});
"""
When I run `wp cron event schedule mycron now`
And I try `wp cron event run --due-now`
Then STDOUT should contain:
"""
MY SHUTDOWN FUNCTION
"""
Scenario: Run cron event with a registered shutdown function that logs to a file
Given a wp-content/mu-plugins/setup_shutdown_function_log.php file:
"""
<?php
add_action('mycronlog', function() {
breakthings();
});
register_shutdown_function(function() {
error_log('LOG A SHUTDOWN FROM ERROR');
});
"""
And I run `wp config set WP_DEBUG true --raw`
And I run `wp config set WP_DEBUG_LOG '{RUN_DIR}/server.log'`
When I try `wp cron event schedule mycronlog now`
And I try `wp cron event run --due-now`
Then STDERR should contain:
"""
Call to undefined function breakthings()
"""
And the {RUN_DIR}/server.log file should exist
And the {RUN_DIR}/server.log file should contain:
"""
LOG A SHUTDOWN FROM ERROR
"""
Scenario: Run cron event with arguments and debug output
When I run `wp cron event schedule wp_cli_test_event_with_args now --0=123 --1=test-value`
Then STDOUT should contain:
"""
Success: Scheduled event with hook 'wp_cli_test_event_with_args'
"""
When I try `wp cron event run wp_cli_test_event_with_args --due-now --debug=cron`
Then STDOUT should contain:
"""
Executed the cron event 'wp_cli_test_event_with_args'
"""
And STDERR should contain:
"""
Debug: Arguments: ["123","test-value"]
"""
When I run `wp cron event schedule wp_cli_test_event_no_args now`
And I try `wp cron event run wp_cli_test_event_no_args --due-now --debug=cron`
Then STDOUT should contain:
"""
Executed the cron event 'wp_cli_test_event_no_args'
"""
And STDERR should not contain:
"""
Debug: Arguments:
"""