Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests that show register shutdown function issue (#70) is invalid #108

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 4 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
51 changes: 51 additions & 0 deletions features/cron-event.feature
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,54 @@ Feature: Manage WP Cron events
"""
Error: Unscheduling events is only supported from WordPress 4.9.0 onwards.
"""

Scenario: Run cron event with a registered shutdown function
Given a wp-content/mu-plugins/setup_shutdown_function.php file:
"""
add_action('mycron', function() {
breakthings();
});

register_shutdown_function(function() {
$error = error_get_last();
if ($error['type'] === E_ERROR) {
WP_CLI::line('MY SHUTDOWN FUNCTION');
}
});
"""

When I run `wp cron event schedule mycron now`
And I try `wp cron event run --due-now`
Then STDOUT should contain:
"""
MY SHUTDOWN FUNCTION
"""

Scenario: Run cron event with a registered shutdown function that logs to a file
Given a wp-content/mu-plugins/setup_shutdown_function_log.php file:
"""
<?php
add_action('mycronlog', function() {
breakthings();
});

register_shutdown_function(function() {
error_log('LOG A SHUTDOWN FROM ERROR');
// file_put_contents( dirname( __FILE__ ) . '/log.log', print_r( 'Shutdown called correctly', true ) . "\r\n\r\n", FILE_APPEND );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can be removed.

swissspidy marked this conversation as resolved.
Show resolved Hide resolved
});
"""

And I run `wp config set WP_DEBUG true --raw`
And I run `wp config set WP_DEBUG_LOG '{RUN_DIR}/server.log'`

When I try `wp cron event schedule mycronlog now`
And I try `wp cron event run --due-now`
Then STDERR should contain:
"""
Call to undefined function breakthings()
"""
Then the {RUN_DIR}/server.log file should exist
And the {RUN_DIR}/server.log file should contain:
"""
LOG A SHUTDOWN FROM ERROR
"""