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
28 changes: 28 additions & 0 deletions features/cron-event.feature
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,31 @@ Feature: Manage WP Cron events
"""
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:
"""
3 changes: 3 additions & 0 deletions src/Cron_Event_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ public function run( $args, $assoc_args ) {
$total = round( microtime( true ) - $start, 3 );
++$executed;
WP_CLI::log( sprintf( "Executed the cron event '%s' in %ss.", $event->hook, $total ) );
if ( ! empty( $event->args ) ) {
WP_CLI::debug( sprintf( 'Arguments: %s', wp_json_encode( $event->args ) ), 'cron' );
}
}

$message = ( 1 === $executed ) ? 'Executed a total of %d cron event.' : 'Executed a total of %d cron events.';
Expand Down