diff --git a/features/cron-event.feature b/features/cron-event.feature index 86356f20..2512d887 100644 --- a/features/cron-event.feature +++ b/features/cron-event.feature @@ -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: + """ diff --git a/src/Cron_Event_Command.php b/src/Cron_Event_Command.php index e789267c..e3e74720 100644 --- a/src/Cron_Event_Command.php +++ b/src/Cron_Event_Command.php @@ -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.';