fix tests about PdfSignedMessageHandler.php

This commit is contained in:
Julien Fastré 2024-12-16 16:50:07 +01:00
parent c939ff4a4e
commit 4933d2251c
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
2 changed files with 17 additions and 5 deletions

View File

@ -53,7 +53,6 @@ final readonly class PdfSignedMessageHandler implements MessageHandlerInterface
$this->entityManager->wrapInTransaction(function () use ($storedObject, $message, $signature) {
$this->storedObjectManager->write($storedObject, $message->content);
$this->signatureStepStateChanger->markSignatureAsSigned($signature, $message->signatureZoneIndex);
});

View File

@ -25,6 +25,8 @@ use Chill\MainBundle\Workflow\WorkflowTransitionContextDTO;
use Chill\PersonBundle\Entity\Person;
use Doctrine\ORM\EntityManagerInterface;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Log\NullLogger;
/**
@ -34,6 +36,8 @@ use Psr\Log\NullLogger;
*/
class PdfSignedMessageHandlerTest extends TestCase
{
use ProphecyTrait;
public function testThatObjectIsWrittenInStoredObjectManagerHappyScenario(): void
{
// a dummy stored object
@ -91,10 +95,19 @@ class PdfSignedMessageHandlerTest extends TestCase
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');
$em = $this->prophesize(EntityManagerInterface::class);
$clear = $em->clear();
$wrap = $em->wrapInTransaction(Argument::type('callable'))->will(function ($args) {
$callable = $args[0];
return $em;
return call_user_func($callable);
});
if ($willFlush) {
$clear->shouldBeCalled();
$wrap->shouldBeCalled();
}
return $em->reveal();
}
}