@@ -88,3 +88,53 @@ Feature: Manage WP Cron events
8888 """
8989 Error: Unscheduling events is only supported from WordPress 4.9.0 onwards.
9090 """
91+
92+ Scenario : Run cron event with a registered shutdown function
93+ Given a wp-content/mu-plugins/setup_shutdown_function.php file:
94+ """
95+ add_action('mycron', function() {
96+ breakthings();
97+ });
98+
99+ register_shutdown_function(function() {
100+ $error = error_get_last();
101+ if ($error['type'] === E_ERROR) {
102+ WP_CLI::line('MY SHUTDOWN FUNCTION');
103+ }
104+ });
105+ """
106+
107+ When I run `wp cron event schedule mycron now`
108+ And I try `wp cron event run --due-now`
109+ Then STDOUT should contain:
110+ """
111+ MY SHUTDOWN FUNCTION
112+ """
113+
114+ Scenario : Run cron event with a registered shutdown function that logs to a file
115+ Given a wp-content/mu-plugins/setup_shutdown_function_log.php file:
116+ """
117+ <?php
118+ add_action('mycronlog', function() {
119+ breakthings();
120+ });
121+
122+ register_shutdown_function(function() {
123+ error_log('LOG A SHUTDOWN FROM ERROR');
124+ });
125+ """
126+
127+ And I run `wp config set WP_DEBUG true --raw`
128+ And I run `wp config set WP_DEBUG_LOG '{RUN_DIR}/server.log' `
129+
130+ When I try `wp cron event schedule mycronlog now`
131+ And I try `wp cron event run --due-now`
132+ Then STDERR should contain:
133+ """
134+ Call to undefined function breakthings()
135+ """
136+ Then the {RUN_DIR}/server.log file should exist
137+ And the {RUN_DIR}/server.log file should contain:
138+ """
139+ LOG A SHUTDOWN FROM ERROR
140+ """
0 commit comments