mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
fixup! Add message handling for public view creation
This commit is contained in:
parent
9d722110a6
commit
c329a1f1f8
@ -20,6 +20,7 @@ use Chill\MainBundle\Workflow\Messenger\PostPublicViewMessage;
|
|||||||
use Chill\MainBundle\Workflow\Messenger\PostPublicViewMessageHandler;
|
use Chill\MainBundle\Workflow\Messenger\PostPublicViewMessageHandler;
|
||||||
use Chill\MainBundle\Workflow\WorkflowTransitionContextDTO;
|
use Chill\MainBundle\Workflow\WorkflowTransitionContextDTO;
|
||||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Prophecy\PhpUnit\ProphecyTrait;
|
use Prophecy\PhpUnit\ProphecyTrait;
|
||||||
use Psr\Log\NullLogger;
|
use Psr\Log\NullLogger;
|
||||||
@ -77,6 +78,19 @@ class PostPublicViewMessageHandlerTest extends TestCase
|
|||||||
return $registry;
|
return $registry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function buildEntityManager(bool $mustBeFlushed = false): EntityManagerInterface
|
||||||
|
{
|
||||||
|
$entityManager = $this->prophesize(EntityManagerInterface::class);
|
||||||
|
$flush = $entityManager->flush();
|
||||||
|
$entityManager->clear()->shouldBeCalled();
|
||||||
|
|
||||||
|
if ($mustBeFlushed) {
|
||||||
|
$flush->shouldBeCalled();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $entityManager->reveal();
|
||||||
|
}
|
||||||
|
|
||||||
public function testHandleTransitionToPostViewSuccessful(): void
|
public function testHandleTransitionToPostViewSuccessful(): void
|
||||||
{
|
{
|
||||||
$entityWorkflow = new EntityWorkflow();
|
$entityWorkflow = new EntityWorkflow();
|
||||||
@ -90,7 +104,7 @@ class PostPublicViewMessageHandlerTest extends TestCase
|
|||||||
$repository = $this->prophesize(EntityWorkflowSendViewRepository::class);
|
$repository = $this->prophesize(EntityWorkflowSendViewRepository::class);
|
||||||
$repository->find(6)->willReturn($view);
|
$repository->find(6)->willReturn($view);
|
||||||
|
|
||||||
$handler = new PostPublicViewMessageHandler($repository->reveal(), $this->buildRegistry(), new NullLogger());
|
$handler = new PostPublicViewMessageHandler($repository->reveal(), $this->buildRegistry(), new NullLogger(), $this->buildEntityManager(true));
|
||||||
|
|
||||||
$handler(new PostPublicViewMessage(6));
|
$handler(new PostPublicViewMessage(6));
|
||||||
|
|
||||||
@ -115,7 +129,7 @@ class PostPublicViewMessageHandlerTest extends TestCase
|
|||||||
$repository = $this->prophesize(EntityWorkflowSendViewRepository::class);
|
$repository = $this->prophesize(EntityWorkflowSendViewRepository::class);
|
||||||
$repository->find(6)->willReturn($view);
|
$repository->find(6)->willReturn($view);
|
||||||
|
|
||||||
$handler = new PostPublicViewMessageHandler($repository->reveal(), $this->buildRegistry(), new NullLogger());
|
$handler = new PostPublicViewMessageHandler($repository->reveal(), $this->buildRegistry(), new NullLogger(), $this->buildEntityManager());
|
||||||
|
|
||||||
$handler(new PostPublicViewMessage(6));
|
$handler(new PostPublicViewMessage(6));
|
||||||
|
|
||||||
@ -136,7 +150,7 @@ class PostPublicViewMessageHandlerTest extends TestCase
|
|||||||
$repository = $this->prophesize(EntityWorkflowSendViewRepository::class);
|
$repository = $this->prophesize(EntityWorkflowSendViewRepository::class);
|
||||||
$repository->find(6)->willReturn($view);
|
$repository->find(6)->willReturn($view);
|
||||||
|
|
||||||
$handler = new PostPublicViewMessageHandler($repository->reveal(), $this->buildRegistry(), new NullLogger());
|
$handler = new PostPublicViewMessageHandler($repository->reveal(), $this->buildRegistry(), new NullLogger(), $this->buildEntityManager());
|
||||||
|
|
||||||
$handler(new PostPublicViewMessage(6));
|
$handler(new PostPublicViewMessage(6));
|
||||||
|
|
||||||
|
@ -13,6 +13,7 @@ namespace Chill\MainBundle\Workflow\Messenger;
|
|||||||
|
|
||||||
use Chill\MainBundle\Repository\EntityWorkflowSendViewRepository;
|
use Chill\MainBundle\Repository\EntityWorkflowSendViewRepository;
|
||||||
use Chill\MainBundle\Workflow\WorkflowTransitionContextDTO;
|
use Chill\MainBundle\Workflow\WorkflowTransitionContextDTO;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
|
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
|
||||||
use Symfony\Component\Workflow\Registry;
|
use Symfony\Component\Workflow\Registry;
|
||||||
@ -32,6 +33,7 @@ final readonly class PostPublicViewMessageHandler implements MessageHandlerInter
|
|||||||
private EntityWorkflowSendViewRepository $sendViewRepository,
|
private EntityWorkflowSendViewRepository $sendViewRepository,
|
||||||
private Registry $registry,
|
private Registry $registry,
|
||||||
private LoggerInterface $logger,
|
private LoggerInterface $logger,
|
||||||
|
private EntityManagerInterface $entityManager,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function __invoke(PostPublicViewMessage $message): void
|
public function __invoke(PostPublicViewMessage $message): void
|
||||||
@ -51,6 +53,8 @@ final readonly class PostPublicViewMessageHandler implements MessageHandlerInter
|
|||||||
'entityWorkflow' => $entityWorkflow->getId(),
|
'entityWorkflow' => $entityWorkflow->getId(),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$this->entityManager->clear();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,6 +74,9 @@ final readonly class PostPublicViewMessageHandler implements MessageHandlerInter
|
|||||||
'transition' => $placeMetadata[self::TRANSITION_ON_VIEW],
|
'transition' => $placeMetadata[self::TRANSITION_ON_VIEW],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$this->entityManager->flush();
|
||||||
|
$this->entityManager->clear();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->logger->info(self::LOG_PREFIX.'Not able to apply this transition', ['transition' => $placeMetadata[self::TRANSITION_ON_VIEW],
|
$this->logger->info(self::LOG_PREFIX.'Not able to apply this transition', ['transition' => $placeMetadata[self::TRANSITION_ON_VIEW],
|
||||||
@ -77,5 +84,7 @@ final readonly class PostPublicViewMessageHandler implements MessageHandlerInter
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->entityManager->clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user