mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-05 21:09:43 +00:00
Signature fixes
This commit is contained in:
@@ -11,8 +11,11 @@ declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Tests\Workflow\Messenger;
|
||||
|
||||
use Chill\DocStoreBundle\Entity\StoredObject;
|
||||
use Chill\DocStoreBundle\Service\StoredObjectToPdfConverter;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflowAttachment;
|
||||
use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository;
|
||||
use Chill\MainBundle\Workflow\EntityWorkflowHandlerInterface;
|
||||
use Chill\MainBundle\Workflow\EntityWorkflowManager;
|
||||
@@ -23,6 +26,7 @@ use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Prophecy\Argument;
|
||||
use Prophecy\PhpUnit\ProphecyTrait;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bridge\Twig\Mime\TemplatedEmail;
|
||||
use Symfony\Component\Mailer\MailerInterface;
|
||||
use Symfony\Component\Mime\Address;
|
||||
@@ -39,24 +43,54 @@ class PostSendExternalMessageHandlerTest extends TestCase
|
||||
public function testSendMessageHappyScenario(): void
|
||||
{
|
||||
$entityWorkflow = $this->buildEntityWorkflow();
|
||||
|
||||
// Prepare attachments (2 attachments)
|
||||
$attachmentStoredObject1 = new StoredObject();
|
||||
$attachmentStoredObject2 = new StoredObject();
|
||||
new EntityWorkflowAttachment('generic_doc', ['id' => 1], $entityWorkflow, $attachmentStoredObject1);
|
||||
new EntityWorkflowAttachment('generic_doc', ['id' => 2], $entityWorkflow, $attachmentStoredObject2);
|
||||
|
||||
// Prepare transition DTO and sends
|
||||
$dto = new WorkflowTransitionContextDTO($entityWorkflow);
|
||||
$dto->futureDestineeEmails = ['external@example.com'];
|
||||
$dto->futureDestineeThirdParties = [(new ThirdParty())->setEmail('3party@example.com')];
|
||||
$entityWorkflow->setStep('send_external', $dto, 'to_send_external', new \DateTimeImmutable(), new User());
|
||||
|
||||
// Repository returns our workflow
|
||||
$repository = $this->prophesize(EntityWorkflowRepository::class);
|
||||
$repository->find(1)->willReturn($entityWorkflow);
|
||||
|
||||
// Mailer must send to both recipients
|
||||
$mailer = $this->prophesize(MailerInterface::class);
|
||||
$mailer->send(Argument::that($this->buildCheckAddressCallback('3party@example.com')))->shouldBeCalledOnce();
|
||||
$mailer->send(Argument::that($this->buildCheckAddressCallback('external@example.com')))->shouldBeCalledOnce();
|
||||
|
||||
// Workflow manager and handler
|
||||
$workflowHandler = $this->prophesize(EntityWorkflowHandlerInterface::class);
|
||||
$workflowHandler->getEntityTitle($entityWorkflow, Argument::any())->willReturn('title');
|
||||
$workflowManager = $this->prophesize(EntityWorkflowManager::class);
|
||||
$workflowManager->getHandler($entityWorkflow)->willReturn($workflowHandler->reveal());
|
||||
|
||||
$handler = new PostSendExternalMessageHandler($repository->reveal(), $mailer->reveal(), $workflowManager->reveal());
|
||||
// Associated stored object for the workflow
|
||||
$associatedStoredObject = new StoredObject();
|
||||
$workflowManager->getAssociatedStoredObject($entityWorkflow)->willReturn($associatedStoredObject);
|
||||
|
||||
// Converter should be called for each attachment and the associated stored object
|
||||
$converter = $this->prophesize(StoredObjectToPdfConverter::class);
|
||||
$converter->addConvertedVersion($attachmentStoredObject1, 'fr')->shouldBeCalledOnce();
|
||||
$converter->addConvertedVersion($attachmentStoredObject2, 'fr')->shouldBeCalledOnce();
|
||||
$converter->addConvertedVersion($associatedStoredObject, 'fr')->shouldBeCalledOnce();
|
||||
|
||||
// Logger (not used in happy path, but required by handler)
|
||||
$logger = $this->prophesize(LoggerInterface::class);
|
||||
|
||||
$handler = new PostSendExternalMessageHandler(
|
||||
$repository->reveal(),
|
||||
$mailer->reveal(),
|
||||
$workflowManager->reveal(),
|
||||
$converter->reveal(),
|
||||
$logger->reveal(),
|
||||
);
|
||||
|
||||
$handler(new PostSendExternalMessage(1, 'fr'));
|
||||
|
||||
|
Reference in New Issue
Block a user