Skip to content

Commit 96d82ae

Browse files
committed
Add unit tests for the has_pending_actions_due method
In #1077 we're making some performance improvements to the `has_pending_actions_due` method, but there are no unit tests to protect against regressions, so this is simply adding some. Because the tests are in the abstract class, they will get run for each data store type.
1 parent d4e5dac commit 96d82ae

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tests/phpunit/jobstore/AbstractStoreTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use ActionScheduler_Action;
66
use ActionScheduler_Callbacks;
77
use ActionScheduler_IntervalSchedule;
8+
use ActionScheduler_Mocker;
89
use ActionScheduler_SimpleSchedule;
910
use ActionScheduler_Store;
1011
use ActionScheduler_UnitTestCase;
@@ -117,4 +118,49 @@ public function test_query_actions_by_array_status() {
117118
// phpcs:ignore Squiz.PHP.CommentedOutCode.Found
118119
// End tests for \ActionScheduler_Store::query_actions().
119120

121+
/**
122+
* The `has_pending_actions_due` method should return a boolean value depending on whether there are
123+
* pending actions.
124+
*
125+
* @return void
126+
*/
127+
public function test_has_pending_actions_due() {
128+
$store = $this->get_store();
129+
$runner = ActionScheduler_Mocker::get_queue_runner( $store );
130+
131+
for ( $i = - 3; $i <= 3; $i ++ ) {
132+
// Some past actions, some future actions.
133+
$time = as_get_datetime_object( $i . ' hours' );
134+
$schedule = new ActionScheduler_SimpleSchedule( $time );
135+
$action = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, [ $i ], $schedule, 'my_group' );
136+
137+
$store->save_action( $action );
138+
}
139+
140+
$this->assertTrue( $store->has_pending_actions_due() );
141+
142+
$runner->run();
143+
144+
$this->assertFalse( $store->has_pending_actions_due() );
145+
}
146+
147+
/**
148+
* The `has_pending_actions_due` method should return false when all pending actions are in the future.
149+
*
150+
* @return void
151+
*/
152+
public function test_has_pending_actions_due_only_future_actions() {
153+
$store = $this->get_store();
154+
155+
for ( $i = 1; $i <= 3; $i ++ ) {
156+
// Only future actions.
157+
$time = as_get_datetime_object( $i . ' hours' );
158+
$schedule = new ActionScheduler_SimpleSchedule( $time );
159+
$action = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, [ $i ], $schedule, 'my_group' );
160+
161+
$store->save_action( $action );
162+
}
163+
164+
$this->assertFalse( $store->has_pending_actions_due() );
165+
}
120166
}

0 commit comments

Comments
 (0)