diff --git a/src/Bundle/ChillDocStoreBundle/Service/Signature/Driver/BaseSigner/PdfSignedMessageHandler.php b/src/Bundle/ChillDocStoreBundle/Service/Signature/Driver/BaseSigner/PdfSignedMessageHandler.php index 81fb97dbf..5cb31de96 100644 --- a/src/Bundle/ChillDocStoreBundle/Service/Signature/Driver/BaseSigner/PdfSignedMessageHandler.php +++ b/src/Bundle/ChillDocStoreBundle/Service/Signature/Driver/BaseSigner/PdfSignedMessageHandler.php @@ -12,9 +12,12 @@ declare(strict_types=1); namespace Chill\DocStoreBundle\Service\Signature\Driver\BaseSigner; use Chill\DocStoreBundle\Service\StoredObjectManagerInterface; +use Chill\MainBundle\Entity\Workflow\EntityWorkflowSignatureStateEnum; use Chill\MainBundle\Repository\Workflow\EntityWorkflowStepSignatureRepository; use Chill\MainBundle\Workflow\EntityWorkflowManager; +use Doctrine\ORM\EntityManagerInterface; use Psr\Log\LoggerInterface; +use Symfony\Component\Clock\ClockInterface; use Symfony\Component\Messenger\Handler\MessageHandlerInterface; final readonly class PdfSignedMessageHandler implements MessageHandlerInterface @@ -29,6 +32,8 @@ final readonly class PdfSignedMessageHandler implements MessageHandlerInterface private EntityWorkflowManager $entityWorkflowManager, private StoredObjectManagerInterface $storedObjectManager, private EntityWorkflowStepSignatureRepository $entityWorkflowStepSignatureRepository, + private EntityManagerInterface $entityManager, + private ClockInterface $clock, ) {} public function __invoke(PdfSignedMessage $message): void @@ -48,5 +53,9 @@ final readonly class PdfSignedMessageHandler implements MessageHandlerInterface } $this->storedObjectManager->write($storedObject, $message->content); + + $signature->setState(EntityWorkflowSignatureStateEnum::SIGNED)->setStateDate($this->clock->now()); + $this->entityManager->flush(); + $this->entityManager->clear(); } } diff --git a/src/Bundle/ChillDocStoreBundle/Tests/Service/Signature/Driver/BaseSigner/PdfSignedMessageHandlerTest.php b/src/Bundle/ChillDocStoreBundle/Tests/Service/Signature/Driver/BaseSigner/PdfSignedMessageHandlerTest.php index 62d50c03f..eb2142175 100644 --- a/src/Bundle/ChillDocStoreBundle/Tests/Service/Signature/Driver/BaseSigner/PdfSignedMessageHandlerTest.php +++ b/src/Bundle/ChillDocStoreBundle/Tests/Service/Signature/Driver/BaseSigner/PdfSignedMessageHandlerTest.php @@ -22,8 +22,10 @@ use Chill\MainBundle\Repository\Workflow\EntityWorkflowStepSignatureRepository; use Chill\MainBundle\Workflow\EntityWorkflowManager; use Chill\MainBundle\Workflow\WorkflowTransitionContextDTO; use Chill\PersonBundle\Entity\Person; +use Doctrine\ORM\EntityManagerInterface; use PHPUnit\Framework\TestCase; use Psr\Log\NullLogger; +use Symfony\Component\Clock\MockClock; /** * @internal @@ -48,12 +50,16 @@ class PdfSignedMessageHandlerTest extends TestCase new NullLogger(), $this->buildEntityWorkflowManager($storedObject), $this->buildStoredObjectManager($storedObject, $expectedContent = '1234'), - $this->buildSignatureRepository($signature) + $this->buildSignatureRepository($signature), + $this->buildEntityManager(true), + new MockClock('now'), ); // we simply call the handler. The mocked StoredObjectManager will check that the "write" method is invoked once // with the content "1234" $handler(new PdfSignedMessage(10, $expectedContent)); + + self::assertEquals('signed', $signature->getState()->value); } private function buildSignatureRepository(EntityWorkflowStepSignature $signature): EntityWorkflowStepSignatureRepository @@ -81,4 +87,13 @@ class PdfSignedMessageHandlerTest extends TestCase return $storedObjectManager; } + + private function buildEntityManager(bool $willFlush): EntityManagerInterface + { + $em = $this->createMock(EntityManagerInterface::class); + $em->expects($willFlush ? $this->once() : $this->never())->method('flush'); + $em->expects($willFlush ? $this->once() : $this->never())->method('clear'); + + return $em; + } }