Skip to content

Commit

Permalink
Merge pull request #1718 from wielebenwir/datengraben/fix-phpunit-sch…
Browse files Browse the repository at this point in the history
…eduler

Fix #1605 last php unit test
  • Loading branch information
hansmorb authored Jan 9, 2025
2 parents a78e074 + ca7d520 commit 56f8e8e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
7 changes: 7 additions & 0 deletions src/Service/Scheduler.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ public function getJobhook(): string {
return $this->jobhook;
}

/**
* @return int timestamp of scheduled event
*/
public function getTimestamp(): int {
return $this->timestamp;
}

/**
* Unschedules the current job.
* This can have multiple reasons:
Expand Down
24 changes: 15 additions & 9 deletions tests/php/Service/SchedulerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,35 @@ public function testReSchedule() {
);
}

/**
* Tests custom recurrences via wp cron interfaces
*/
public function testCustomRecurrence() {

$thirty_minutes = 'thirty_minutes';

$customSchedule = new Scheduler(
'test2',
'CommonsBooking\Tests\Service\dummyFunction',
'thirty_minutes',
$thirty_minutes,
'',
array($this->dummyOptionsKey,$this->dummyFieldId),
$this->dummyUpdateHook
);
$this->jobhooks[] = $customSchedule->getJobhook();

// Should contain custom cron intervals, because Scheduler(...) adds filter
$this->assertContains( 'thirty_minutes', array_keys( wp_get_schedules() ) );

$now = new DateTime('now', new \DateTimeZone('UTC'));
$nowTS = $now->getTimestamp();
// Should contain custom cron intervals, because Scheduler(...) adds filter
$this->assertContains( $thirty_minutes, array_keys( wp_get_schedules() ) );

$this->assertEquals(
$nowTS,
wp_next_scheduled($customSchedule->getJobhook())
// returns timestamp which is used to set internal event object (via wp_schedule_event in Scheduler class)
$customSchedule->getTimestamp(),
// returns timestamp from internal event object identified by job hook
wp_next_scheduled( $customSchedule->getJobhook() )
);

$event = wp_get_scheduled_event($customSchedule->getJobhook());
$this->assertEquals('thirty_minutes',$event->schedule);
$this->assertEquals( $thirty_minutes , $event->schedule );

}

Expand Down

0 comments on commit 56f8e8e

Please sign in to comment.