diff --git a/src/Bundle/ChillMainBundle/Service/Workflow/CancelStaleWorkflowCronJob.php b/src/Bundle/ChillMainBundle/Service/Workflow/CancelStaleWorkflowCronJob.php index 767af2c5c..be3dd2a5e 100644 --- a/src/Bundle/ChillMainBundle/Service/Workflow/CancelStaleWorkflowCronJob.php +++ b/src/Bundle/ChillMainBundle/Service/Workflow/CancelStaleWorkflowCronJob.php @@ -49,7 +49,7 @@ class CancelStaleWorkflowCronJob implements CronJobInterface $olderThanDate = $this->clock->now()->sub(new \DateInterval(self::KEEP_INTERVAL)); $staleWorkflowIds = $this->workflowRepository->findWorkflowsWithoutFinalStepAndOlderThan($olderThanDate); - $lastCanceled = self::LAST_CANCELED_WORKFLOW; + $lastCanceled = $lastExecutionData[self::LAST_CANCELED_WORKFLOW] ?? 0; $processedCount = 0; foreach ($staleWorkflowIds as $wId) { diff --git a/src/Bundle/ChillMainBundle/Tests/Services/Workflow/CancelStaleWorkflowCronJobTest.php b/src/Bundle/ChillMainBundle/Tests/Services/Workflow/CancelStaleWorkflowCronJobTest.php index 07bca6bc5..200b92099 100644 --- a/src/Bundle/ChillMainBundle/Tests/Services/Workflow/CancelStaleWorkflowCronJobTest.php +++ b/src/Bundle/ChillMainBundle/Tests/Services/Workflow/CancelStaleWorkflowCronJobTest.php @@ -13,13 +13,12 @@ namespace Services\Workflow; use Chill\MainBundle\Entity\CronJobExecution; use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository; -use Chill\MainBundle\Service\Workflow\CancelStaleWorkflow; use Chill\MainBundle\Service\Workflow\CancelStaleWorkflowCronJob; use Chill\MainBundle\Service\Workflow\CancelStaleWorkflowMessage; -use Doctrine\DBAL\Connection; use PHPUnit\Framework\MockObject\Exception; +use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; -use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; +use Psr\Log\NullLogger; use Symfony\Component\Clock\MockClock; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\MessageBusInterface; @@ -29,14 +28,8 @@ use Symfony\Component\Messenger\MessageBusInterface; * * @coversNothing */ -class CancelStaleWorkflowCronJobTest extends KernelTestCase +class CancelStaleWorkflowCronJobTest extends TestCase { - protected function setUp(): void - { - self::bootKernel(); - $this->connection = self::getContainer()->get(Connection::class); - } - /** * @dataProvider buildTestCanRunData * @@ -61,12 +54,11 @@ class CancelStaleWorkflowCronJobTest extends KernelTestCase { $clock = new MockClock((new \DateTimeImmutable('now', new \DateTimeZone('+00:00')))->add(new \DateInterval('P120D'))); $workflowRepository = $this->createMock(EntityWorkflowRepository::class); - $logger = $this->createMock(LoggerInterface::class); $workflowRepository->method('findWorkflowsWithoutFinalStepAndOlderThan')->willReturn([1, 3, 2]); $messageBus = $this->buildMessageBus(true); - $cronJob = new CancelStaleWorkflowCronJob($workflowRepository, $clock, $messageBus, $logger); + $cronJob = new CancelStaleWorkflowCronJob($workflowRepository, $clock, $messageBus, new NullLogger()); $results = $cronJob->run([]); @@ -101,7 +93,7 @@ class CancelStaleWorkflowCronJobTest extends KernelTestCase $messageBus = $this->createMock(MessageBusInterface::class); $methodDispatch = match ($expectDispatchAtLeastOnce) { - true => $messageBus->expects($this->atLeastOnce())->method('dispatch')->with($this->isInstanceOf(CancelStaleWorkflow::class)), + true => $messageBus->expects($this->atLeastOnce())->method('dispatch')->with($this->isInstanceOf(CancelStaleWorkflowMessage::class)), false => $messageBus->method('dispatch'), };