mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Refactor CancelStaleWorkflowCronJobTest to simplify setup
Replaced KernelTestCase with TestCase to simplify test setup and removed dependency on the database connection. Added NullLogger to replace mocked LoggerInterface during testing. Updated method call in tests to correctly reference CancelStaleWorkflowMessage class.
This commit is contained in:
parent
f4356ac249
commit
2fb46c65c2
@ -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) {
|
||||
|
@ -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'),
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user