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
59 changes: 36 additions & 23 deletions features/cron-event.feature
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,21 @@ Feature: Manage WP Cron events
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');
}
});
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`
Expand All @@ -114,13 +119,18 @@ Feature: Manage WP Cron events
Given a wp-content/mu-plugins/setup_shutdown_function_log.php file:
"""
<?php
add_action('mycronlog', function() {
breakthings();
});
add_action(
'mycronlog',
function () {
breakthings();
}
);

register_shutdown_function(function() {
error_log('LOG A SHUTDOWN FROM ERROR');
});
register_shutdown_function(
function () {
error_log( 'LOG A SHUTDOWN FROM ERROR' );
}
);
"""

And I run `wp config set WP_DEBUG true --raw`
Expand Down Expand Up @@ -211,18 +221,21 @@ Feature: Manage WP Cron events
<?php
add_action( 'wp_cli_test_hook', 'wp_cli_test_function' );
add_action( 'wp_cli_test_hook', array( 'MyTestClass', 'my_method' ) );
add_action( 'wp_cli_test_hook_closure', function() {
// Test closure
} );
add_action(
'wp_cli_test_hook_closure',
function () {
// Test closure
}
);

function wp_cli_test_function() {
// Test function
// Test function
}

class MyTestClass {
public static function my_method() {
// Test method
}
public static function my_method() {
// Test method
}
}
"""

Expand Down
74 changes: 40 additions & 34 deletions features/cron.feature
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ Feature: Manage WP-Cron events and schedules
"""
<?php
add_filter(
'cron_schedules',
function( $schedules ) {
$schedules['test_schedule'] = array(
'interval' => 3600,
'display' => __( 'Every Hour' ),
);
return $schedules;
}
'cron_schedules',
function ( $schedules ) {
$schedules['test_schedule'] = array(
'interval' => 3600,
'display' => __( 'Every Hour' ),
);
return $schedules;
}
);
"""

Expand Down Expand Up @@ -235,11 +235,14 @@ Feature: Manage WP-Cron events and schedules
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;
} );
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`
Expand Down Expand Up @@ -390,11 +393,14 @@ Feature: Manage WP-Cron events and schedules
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'] = str_replace( site_url(), 'http://localhost:8081', $cron_request_array['url'] );
$cron_request_array['args']['sslverify'] = false;
return $cron_request_array;
} );
add_filter(
'cron_request',
static function ( $cron_request_array ) {
$cron_request_array['url'] = str_replace( site_url(), 'http://localhost:8081', $cron_request_array['url'] );
$cron_request_array['args']['sslverify'] = false;
return $cron_request_array;
}
);
"""

When I run `wp eval 'var_export( ALTERNATE_WP_CRON );'`
Expand Down Expand Up @@ -451,23 +457,23 @@ Feature: Manage WP-Cron events and schedules
"""
<?php
$val = array(
1647914509 => array(
'postindexer_secondpass_cron' => array(
'40cd750bba9870f18aada2478b24840a' => array(
'schedule' => '5mins',
'args' => array(),
'interval' => 100,
),
1647914509 => array(
'postindexer_secondpass_cron' => array(
'40cd750bba9870f18aada2478b24840a' => array(
'schedule' => '5mins',
'args' => array(),
'interval' => 100,
),
),
),
'wp_batch_split_terms' => array(
1442323165 => array(
'40cd750bba9870f18aada2478b24840a' => array(
'schedule' => false,
'args' => array(),
),
),
),
),
'wp_batch_split_terms' => array(
1442323165 => array(
'40cd750bba9870f18aada2478b24840a' => array(
'schedule' => false,
'args' => array()
)
)
)
);
update_option( 'cron', $val );
"""
Expand Down