MailBeforeSentEvent example



            $this->eventDispatcher->dispatch($event);
            $this->logger->error(
                'mail body is null',
                $templateData
            );

            return null;
        }

        $event = new MailBeforeSentEvent($data$mail$context$templateData['eventName'] ?? null);
        $this->eventDispatcher->dispatch($event);

        if ($event->isPropagationStopped()) {
            return null;
        }

        $this->mailSender->send($mail);

        $event = new MailSentEvent($data['subject']$recipients$contents$context$templateData['eventName'] ?? null);
        $this->eventDispatcher->dispatch($event);

        

        $storedData = [[]];
        $data = [
            'subject' => 'Hi',
            'senderName' => 'shopware',
            'contentPlain' => 'test',
        ];

        $mail = new Email();
        $mail->html('text/plain');

        $event = new MailBeforeSentEvent(
            $data,
            $mail,
            Context::createDefaultContext()
        );

        $storer = new MessageStorer();
        $stored = $storer->store($event$storedData);

        static::assertArrayHasKey(MessageAware::MESSAGE, $stored);
        static::assertIsString($stored[MessageAware::MESSAGE]);
    }

    
use Symfony\Component\Mime\Email;

/** * @internal * * @covers \Shopware\Core\Content\MailTemplate\Service\Event\MailBeforeSentEvent */
class MailBeforeSentEventTest extends TestCase
{
    public function testScalarValuesCorrectly(): void
    {
        $event = new MailBeforeSentEvent(
            ['foo' => 'bar'],
            new Email(),
            Context::createDefaultContext()
        );

        $storer = new ScalarValuesStorer();

        $stored = $storer->store($event[]);

        $flow = new StorableFlow('foo', Context::createDefaultContext()$stored);

        
Home | Imprint | This part of the site doesn't use cookies.