mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-13 13:54:23 +00:00
Update PdfSignedMessageHandler to manage signature state
Additional dependencies have been added to the PdfSignedMessageHandler to handle the state of the signature. After writing the signed message content, the state is set to 'signed' and the state date is updated with the current time. Also, modifications are flushed in the EntityManager to save these changes to the database. Corresponding updates and tests have been made in the PdfSignedMessageHandlerTest file.
This commit is contained in:
parent
51ab4bef38
commit
3836d0dc9b
@ -12,9 +12,12 @@ declare(strict_types=1);
|
|||||||
namespace Chill\DocStoreBundle\Service\Signature\Driver\BaseSigner;
|
namespace Chill\DocStoreBundle\Service\Signature\Driver\BaseSigner;
|
||||||
|
|
||||||
use Chill\DocStoreBundle\Service\StoredObjectManagerInterface;
|
use Chill\DocStoreBundle\Service\StoredObjectManagerInterface;
|
||||||
|
use Chill\MainBundle\Entity\Workflow\EntityWorkflowSignatureStateEnum;
|
||||||
use Chill\MainBundle\Repository\Workflow\EntityWorkflowStepSignatureRepository;
|
use Chill\MainBundle\Repository\Workflow\EntityWorkflowStepSignatureRepository;
|
||||||
use Chill\MainBundle\Workflow\EntityWorkflowManager;
|
use Chill\MainBundle\Workflow\EntityWorkflowManager;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Symfony\Component\Clock\ClockInterface;
|
||||||
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
|
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
|
||||||
|
|
||||||
final readonly class PdfSignedMessageHandler implements MessageHandlerInterface
|
final readonly class PdfSignedMessageHandler implements MessageHandlerInterface
|
||||||
@ -29,6 +32,8 @@ final readonly class PdfSignedMessageHandler implements MessageHandlerInterface
|
|||||||
private EntityWorkflowManager $entityWorkflowManager,
|
private EntityWorkflowManager $entityWorkflowManager,
|
||||||
private StoredObjectManagerInterface $storedObjectManager,
|
private StoredObjectManagerInterface $storedObjectManager,
|
||||||
private EntityWorkflowStepSignatureRepository $entityWorkflowStepSignatureRepository,
|
private EntityWorkflowStepSignatureRepository $entityWorkflowStepSignatureRepository,
|
||||||
|
private EntityManagerInterface $entityManager,
|
||||||
|
private ClockInterface $clock,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function __invoke(PdfSignedMessage $message): void
|
public function __invoke(PdfSignedMessage $message): void
|
||||||
@ -48,5 +53,9 @@ final readonly class PdfSignedMessageHandler implements MessageHandlerInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->storedObjectManager->write($storedObject, $message->content);
|
$this->storedObjectManager->write($storedObject, $message->content);
|
||||||
|
|
||||||
|
$signature->setState(EntityWorkflowSignatureStateEnum::SIGNED)->setStateDate($this->clock->now());
|
||||||
|
$this->entityManager->flush();
|
||||||
|
$this->entityManager->clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,8 +22,10 @@ use Chill\MainBundle\Repository\Workflow\EntityWorkflowStepSignatureRepository;
|
|||||||
use Chill\MainBundle\Workflow\EntityWorkflowManager;
|
use Chill\MainBundle\Workflow\EntityWorkflowManager;
|
||||||
use Chill\MainBundle\Workflow\WorkflowTransitionContextDTO;
|
use Chill\MainBundle\Workflow\WorkflowTransitionContextDTO;
|
||||||
use Chill\PersonBundle\Entity\Person;
|
use Chill\PersonBundle\Entity\Person;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Psr\Log\NullLogger;
|
use Psr\Log\NullLogger;
|
||||||
|
use Symfony\Component\Clock\MockClock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
@ -48,12 +50,16 @@ class PdfSignedMessageHandlerTest extends TestCase
|
|||||||
new NullLogger(),
|
new NullLogger(),
|
||||||
$this->buildEntityWorkflowManager($storedObject),
|
$this->buildEntityWorkflowManager($storedObject),
|
||||||
$this->buildStoredObjectManager($storedObject, $expectedContent = '1234'),
|
$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
|
// we simply call the handler. The mocked StoredObjectManager will check that the "write" method is invoked once
|
||||||
// with the content "1234"
|
// with the content "1234"
|
||||||
$handler(new PdfSignedMessage(10, $expectedContent));
|
$handler(new PdfSignedMessage(10, $expectedContent));
|
||||||
|
|
||||||
|
self::assertEquals('signed', $signature->getState()->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildSignatureRepository(EntityWorkflowStepSignature $signature): EntityWorkflowStepSignatureRepository
|
private function buildSignatureRepository(EntityWorkflowStepSignature $signature): EntityWorkflowStepSignatureRepository
|
||||||
@ -81,4 +87,13 @@ class PdfSignedMessageHandlerTest extends TestCase
|
|||||||
|
|
||||||
return $storedObjectManager;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user