Skip to content

Commit

Permalink
Merge pull request #1092 from woocommerce/add/has-pending-unit-tests
Browse files Browse the repository at this point in the history
Add unit tests for the has_pending_actions_due method
  • Loading branch information
coreymckrill authored Oct 31, 2024
2 parents d4e5dac + dd1550c commit d686bbd
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions tests/phpunit/jobstore/AbstractStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use ActionScheduler_Action;
use ActionScheduler_Callbacks;
use ActionScheduler_IntervalSchedule;
use ActionScheduler_Mocker;
use ActionScheduler_SimpleSchedule;
use ActionScheduler_Store;
use ActionScheduler_UnitTestCase;
Expand Down Expand Up @@ -117,4 +118,46 @@ public function test_query_actions_by_array_status() {
// phpcs:ignore Squiz.PHP.CommentedOutCode.Found
// End tests for \ActionScheduler_Store::query_actions().

/**
* The `has_pending_actions_due` method should return a boolean value depending on whether there are
* pending actions.
*
* @return void
*/
public function test_has_pending_actions_due() {
$store = $this->get_store();
$runner = ActionScheduler_Mocker::get_queue_runner( $store );

for ( $i = - 3; $i <= 3; $i ++ ) {
// Some past actions, some future actions.
$time = as_get_datetime_object( $i . ' hours' );
$schedule = new ActionScheduler_SimpleSchedule( $time );
$action = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, [ $i ], $schedule, 'my_group' );

$store->save_action( $action );
}
$this->assertTrue( $store->has_pending_actions_due() );

$runner->run();
$this->assertFalse( $store->has_pending_actions_due() );
}

/**
* The `has_pending_actions_due` method should return false when all pending actions are in the future.
*
* @return void
*/
public function test_has_pending_actions_due_only_future_actions() {
$store = $this->get_store();

for ( $i = 1; $i <= 3; $i ++ ) {
// Only future actions.
$time = as_get_datetime_object( $i . ' hours' );
$schedule = new ActionScheduler_SimpleSchedule( $time );
$action = new ActionScheduler_Action( ActionScheduler_Callbacks::HOOK_WITH_CALLBACK, [ $i ], $schedule, 'my_group' );

$store->save_action( $action );
}
$this->assertFalse( $store->has_pending_actions_due() );
}
}

0 comments on commit d686bbd

Please sign in to comment.