Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@
},
"require-dev": {
"wp-cli/entity-command": "^1.3 || ^2",
"wp-cli/server-command": "^2.0",
"wp-cli/wp-cli-tests": "^3.1"
},
"config": {
"process-timeout": 7200,
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"extra": {
"branch-alias": {
Expand Down
33 changes: 30 additions & 3 deletions features/cron.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Feature: Manage WP-Cron events and schedules

Background:
Given a WP install
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 ** //'`
And I run `wp config set DISABLE_WP_CRON false --raw --type=constant --anchor="if ( ! defined( 'DISABLE_WP_CRON' ) )"`

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

Scenario: Testing WP-Cron
When I try `wp cron test`
Then STDERR should not contain:
Given a php.ini file:
"""
error_log = {RUN_DIR}/server.log
log_errors = on
"""
And I launch in the background `wp server --host=localhost --port=8080 --config=php.ini`
And a wp-content/mu-plugins/set_cron_site_url.php file:
"""
<?php
add_filter( 'cron_request', static function ( $cron_request_array ) {
$cron_request_array['url'] = 'http://localhost:8080';
$cron_request_array['args']['sslverify'] = false;
return $cron_request_array;
} );
"""

When I run `wp cron event schedule wp_cli_test_event_1 '+1 hour 5 minutes' --0=banana`
Then STDOUT should contain:
"""
Success: Scheduled event with hook 'wp_cli_test_event_1'
"""

When I run `wp cron test`
Then STDOUT should contain:
"""
Success: WP-Cron spawning is working as expected.
"""
And STDERR should not contain:
"""
Error:
"""
And the {RUN_DIR}/server.log file should not exist

Scenario: Run multiple cron events
When I try `wp cron event run`
Expand Down
2 changes: 1 addition & 1 deletion src/Cron_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function test() {
if ( 200 === $code ) {
WP_CLI::success( 'WP-Cron spawning is working as expected.' );
} else {
WP_CLI::warning( sprintf( 'WP-Cron spawn succeeded but returned HTTP status code: %1$s %2$s', $code, $message ) );
WP_CLI::error( sprintf( 'WP-Cron spawn returned HTTP status code: %1$s %2$s', $code, $message ) );
}

}
Expand Down