MailerTransportDecorator example

if ($hasOrderSettingAttachment) {
            $event->getContext()->addExtension(
                MailSendSubscriberConfig::MAIL_CONFIG_EXTENSION,
                new MailSendSubscriberConfig(
                    false,
                    $documentIds,
                )
            );
        }

        $transportDecorator = new MailerTransportDecorator(
            $this->createMock(TransportInterface::class),
            $this->getContainer()->get(MailAttachmentsBuilder::class),
            $this->getContainer()->get('shopware.filesystem.public'),
            $this->getContainer()->get('document.repository')
        );
        $mailService = new TestEmailService($this->getContainer()->get(MailFactory::class)$transportDecorator);
        $subscriber = new SendMailAction(
            $mailService,
            $this->getContainer()->get('mail_template.repository'),
            $this->getContainer()->get('logger'),
            $this->getContainer()->get('event_dispatcher'),
            
private MockObject&EntityRepository $documentRepository;

    private MailerTransportDecorator $decorator;

    protected function setUp(): void
    {
        $this->decorated = $this->createMock(TransportInterface::class);
        $this->attachmentsBuilder = $this->createMock(MailAttachmentsBuilder::class);
        $this->filesystem = new Filesystem(new MemoryFilesystemAdapter());
        $this->documentRepository = $this->createMock(EntityRepository::class);

        $this->decorator = new MailerTransportDecorator(
            $this->decorated,
            $this->attachmentsBuilder,
            $this->filesystem,
            $this->documentRepository
        );
    }

    public function testMailerTransportDecoratorDefault(): void
    {
        $mail = $this->createMock(Email::class);
        $envelope = $this->createMock(Envelope::class);

        
try {
            $transportConfig = trim($this->configService->getString('core.mailerSettings.emailAgent'));

            if ($transportConfig === '') {
                return $this->createTransportUsingDSN($dsn);
            }
        } catch (DriverException) {
            // We don't have a database connection right now             return $this->createTransportUsingDSN($dsn);
        }

        return new MailerTransportDecorator(
            $this->create(),
            $this->attachmentsBuilder,
            $this->filesystem,
            $this->documentRepository
        );
    }

    public function createTransportUsingDSN(string $dsn): MailerTransportDecorator
    {
        return new MailerTransportDecorator(
            $this->envBasedTransport->fromString($dsn),
            
Home | Imprint | This part of the site doesn't use cookies.