entityManager = self::$container->get(EntityManagerInterface::class); $this->cronJobExecutionRepository = self::$container->get(CronJobExecutionRepository::class); } public static function tearDownAfterClass(): void { self::bootKernel(); $entityManager = self::$container->get(EntityManagerInterface::class); $entityManager->createQuery('DELETE '.CronJobExecution::class.' cje WHERE cje.key LIKE :key') ->setParameter('key', 'test-with-data') ->execute(); } public function testCompleteLifeCycle(): void { $cronjob = $this->prophesize(CronJobInterface::class); $cronjob->canRun(null)->willReturn(true); $cronjob->canRun(Argument::type(CronJobExecution::class))->willReturn(true); $cronjob->getKey()->willReturn('test-with-data'); $cronjob->run([])->willReturn(['test' => 'execution-0']); $cronjob->run(['test' => 'execution-0'])->willReturn(['test' => 'execution-1']); $cronjob->run([])->shouldBeCalledOnce(); $cronjob->run(['test' => 'execution-0'])->shouldBeCalledOnce(); $manager = new CronManager( $this->cronJobExecutionRepository, $this->entityManager, [$cronjob->reveal()], new NullLogger() ); // run a first time $manager->run(); // run a second time $manager->run(); } } class JobWithReturn implements CronJobInterface { public function canRun(?CronJobExecution $cronJobExecution): bool { return true; } public function getKey(): string { return 'with-data'; } public function run(array $lastExecutionData): ?array { return ['data' => 'test']; } }