Skip to content

Commit bb9fd96

Browse files
authored
Merge pull request #66 from johnbillion/fix/cron-test
2 parents 23a22ba + 6a34611 commit bb9fd96

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-5
lines changed

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@
1616
},
1717
"require-dev": {
1818
"wp-cli/entity-command": "^1.3 || ^2",
19+
"wp-cli/server-command": "^2.0",
1920
"wp-cli/wp-cli-tests": "^3.1"
2021
},
2122
"config": {
2223
"process-timeout": 7200,
23-
"sort-packages": true
24+
"sort-packages": true,
25+
"allow-plugins": {
26+
"dealerdirect/phpcodesniffer-composer-installer": true
27+
}
2428
},
2529
"extra": {
2630
"branch-alias": {

features/cron.feature

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Feature: Manage WP-Cron events and schedules
22

33
Background:
44
Given a WP install
5-
And I run `wp config set DISABLE_WP_CRON false --raw --type=constant --anchor='// ** MySQL settings - You can get this info from your web host ** //'`
5+
And I run `wp config set DISABLE_WP_CRON false --raw --type=constant --anchor="if ( ! defined( 'DISABLE_WP_CRON' ) )"`
66

77
Scenario: Scheduling and then deleting an event
88
When I run `wp cron event schedule wp_cli_test_event_1 '+1 hour 5 minutes' --0=banana`
@@ -190,11 +190,38 @@ Feature: Manage WP-Cron events and schedules
190190
| hourly | 3600 |
191191

192192
Scenario: Testing WP-Cron
193-
When I try `wp cron test`
194-
Then STDERR should not contain:
193+
Given a php.ini file:
194+
"""
195+
error_log = {RUN_DIR}/server.log
196+
log_errors = on
197+
"""
198+
And I launch in the background `wp server --host=localhost --port=8080 --config=php.ini`
199+
And a wp-content/mu-plugins/set_cron_site_url.php file:
200+
"""
201+
<?php
202+
add_filter( 'cron_request', static function ( $cron_request_array ) {
203+
$cron_request_array['url'] = 'http://localhost:8080';
204+
$cron_request_array['args']['sslverify'] = false;
205+
return $cron_request_array;
206+
} );
207+
"""
208+
209+
When I run `wp cron event schedule wp_cli_test_event_1 '+1 hour 5 minutes' --0=banana`
210+
Then STDOUT should contain:
211+
"""
212+
Success: Scheduled event with hook 'wp_cli_test_event_1'
213+
"""
214+
215+
When I run `wp cron test`
216+
Then STDOUT should contain:
217+
"""
218+
Success: WP-Cron spawning is working as expected.
219+
"""
220+
And STDERR should not contain:
195221
"""
196222
Error:
197223
"""
224+
And the {RUN_DIR}/server.log file should not exist
198225

199226
Scenario: Run multiple cron events
200227
When I try `wp cron event run`

src/Cron_Command.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function test() {
5050
if ( 200 === $code ) {
5151
WP_CLI::success( 'WP-Cron spawning is working as expected.' );
5252
} else {
53-
WP_CLI::warning( sprintf( 'WP-Cron spawn succeeded but returned HTTP status code: %1$s %2$s', $code, $message ) );
53+
WP_CLI::error( sprintf( 'WP-Cron spawn returned HTTP status code: %1$s %2$s', $code, $message ) );
5454
}
5555

5656
}

0 commit comments

Comments
 (0)