mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-29 02:53:50 +00:00
Suffix message class with 'Message' and add check on workflow to assert no transitions were applied since message placed in queue
This commit is contained in:
@@ -15,6 +15,10 @@ 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 DateInvalidTimeZoneException;
|
||||
use DateMalformedStringException;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use PHPUnit\Framework\MockObject\Exception;
|
||||
use Psr\Log\LoggerInterface;
|
||||
@@ -43,7 +47,7 @@ class CancelStaleWorkflowCronJobTest extends KernelTestCase
|
||||
*/
|
||||
public function testCanRun(?CronJobExecution $cronJobExecution, bool $expected): void
|
||||
{
|
||||
$clock = new MockClock(new \DateTimeImmutable('2024-01-01 00:00:00', new \DateTimeZone('+00:00')));
|
||||
$clock = new MockClock(new DateTimeImmutable('2024-01-01 00:00:00', new \DateTimeZone('+00:00')));
|
||||
$logger = $this->createMock(LoggerInterface::class);
|
||||
|
||||
$cronJob = new CancelStaleWorkflowCronJob($this->createMock(EntityWorkflowRepository::class), $clock, $this->buildMessageBus(), $logger);
|
||||
@@ -52,17 +56,17 @@ class CancelStaleWorkflowCronJobTest extends KernelTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \DateMalformedStringException
|
||||
* @throws \DateInvalidTimeZoneException
|
||||
* @throws Exception
|
||||
* @throws DateMalformedStringException
|
||||
* @throws DateInvalidTimeZoneException
|
||||
* @throws \Exception|Exception
|
||||
*/
|
||||
public function testRun(): void
|
||||
{
|
||||
$clock = new MockClock((new \DateTimeImmutable('now', new \DateTimeZone('+00:00')))->add(new \DateInterval('P120D')));
|
||||
$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, 2, 3]);
|
||||
$workflowRepository->method('findWorkflowsWithoutFinalStepAndOlderThan')->willReturn([1, 3, 2]);
|
||||
$messageBus = $this->buildMessageBus(true);
|
||||
|
||||
$cronJob = new CancelStaleWorkflowCronJob($workflowRepository, $clock, $messageBus, $logger);
|
||||
@@ -80,17 +84,17 @@ class CancelStaleWorkflowCronJobTest extends KernelTestCase
|
||||
public static function buildTestCanRunData(): iterable
|
||||
{
|
||||
yield [
|
||||
(new CronJobExecution('last-canceled-workflow-id'))->setLastEnd(new \DateTimeImmutable('2023-12-31 00:00:00', new \DateTimeZone('+00:00'))),
|
||||
(new CronJobExecution('last-canceled-workflow-id'))->setLastEnd(new DateTimeImmutable('2023-12-31 00:00:00', new \DateTimeZone('+00:00'))),
|
||||
true,
|
||||
];
|
||||
|
||||
yield [
|
||||
(new CronJobExecution('last-canceled-workflow-id'))->setLastEnd(new \DateTimeImmutable('2023-12-30 23:59:59', new \DateTimeZone('+00:00'))),
|
||||
(new CronJobExecution('last-canceled-workflow-id'))->setLastEnd(new DateTimeImmutable('2023-12-30 23:59:59', new \DateTimeZone('+00:00'))),
|
||||
true,
|
||||
];
|
||||
|
||||
yield [
|
||||
(new CronJobExecution('last-canceled-workflow-id'))->setLastEnd(new \DateTimeImmutable('2023-12-31 00:00:01', new \DateTimeZone('+00:00'))),
|
||||
(new CronJobExecution('last-canceled-workflow-id'))->setLastEnd(new DateTimeImmutable('2023-12-31 00:00:01', new \DateTimeZone('+00:00'))),
|
||||
false,
|
||||
];
|
||||
}
|
||||
@@ -104,7 +108,7 @@ class CancelStaleWorkflowCronJobTest extends KernelTestCase
|
||||
false => $messageBus->method('dispatch'),
|
||||
};
|
||||
|
||||
$methodDispatch->willReturnCallback(function (CancelStaleWorkflow $message) {
|
||||
$methodDispatch->willReturnCallback(function (CancelStaleWorkflowMessage $message) {
|
||||
return new Envelope($message);
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user