clock = $this->createMock(ClockInterface::class); $this->connection = $this->createMock(Connection::class); $this->messageBus = $this->createMock(MessageBusInterface::class); $this->logger = $this->createMock(LoggerInterface::class); $this->cronjob = new DailyNotificationDigestCronjob( $this->clock, $this->connection, $this->messageBus, $this->logger ); } public function testGetKey(): void { $this->assertEquals('daily-notification-digest', $this->cronjob->getKey()); } /** * @dataProvider canRunTimeDataProvider */ public function testCanRunWithNullCronJobExecution(int $hour, bool $expected): void { $now = new \DateTimeImmutable("2024-01-01 {$hour}:00:00"); $this->clock->expects($this->once()) ->method('now') ->willReturn($now); $result = $this->cronjob->canRun(null); $this->assertEquals($expected, $result); } public static function canRunTimeDataProvider(): array { return [ 'hour 5 - should not run' => [5, false], 'hour 6 - should run' => [6, true], 'hour 7 - should run' => [7, true], 'hour 8 - should run' => [8, true], 'hour 9 - should not run' => [9, false], 'hour 10 - should not run' => [10, false], 'hour 23 - should not run' => [23, false], ]; } }