Skip to content

Commit 6f75301

Browse files
committed
Fix unrelated test case issue
1 parent bab2d13 commit 6f75301

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

__tests__/unit-tests/test-internal-events.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,27 @@ function test_prune_duplicate_events() {
7474
$duplicate_recurring_event2 = Utils::create_test_event( [ 'timestamp' => time() + 200, 'action' => 'recurring_event', 'schedule' => 'hourly', 'interval' => \HOUR_IN_SECONDS ] );
7575
$unique_recurring_event = Utils::create_test_event( [ 'timestamp' => time() + 100, 'action' => 'recurring_event', 'schedule' => 'hourly', 'interval' => \HOUR_IN_SECONDS, 'args' => [ 'unique' ] ] );
7676

77+
// This prevent events starting with `wp_` from being scheduled, like wp_version_check,
78+
// wp_update_plugins or wp_update_themes to avoid affecting the count assertions.
79+
$prevent_wp_cron_events = function ( $event ) {
80+
if ( str_starts_with( $event->hook, 'wp_' ) ) {
81+
return false;
82+
}
83+
return $event;
84+
};
85+
86+
// Filter to block any WordPress core cron events so the test events are isolated.
87+
add_filter( 'schedule_event', $prevent_wp_cron_events );
88+
7789
// Run the pruning.
7890
Cron_Control\Internal_Events::instance()->clean_legacy_data();
7991

92+
// Remove the filter after the pruning calls.
93+
remove_filter( 'schedule_event', $prevent_wp_cron_events );
94+
8095
// Should have 5 events left, and the oldest IDs should have been kept..
8196
$remaining_events = Cron_Control\Events::query( [ 'limit' => 100, 'orderby' => 'ID', 'order' => 'ASC' ] );
82-
$this->assertEquals( 5, count( $remaining_events ), 'correct number of registered events left after pruning' );
97+
$this->assertCount( 5, $remaining_events, 'correct number of registered events left after pruning' );
8398
$this->assertEquals( $remaining_events[0]->get_id(), $original_single_event->get_id(), 'original single event was kept' );
8499
$this->assertEquals( $remaining_events[1]->get_id(), $duplicate_single_event->get_id(), 'duplicate single event was also kept' );
85100
$this->assertEquals( $remaining_events[2]->get_id(), $unique_single_event->get_id(), 'unique single event was kept' );

0 commit comments

Comments
 (0)