Mailer example


                return 'dummy://local';
            }

            protected function doSend(SentMessage $message): void
            {
                $onDoSend = $this->onDoSend;
                $onDoSend($message);
            }
        };

        $mailer = new Mailer($testTransport);

        $message = (new Email())
            ->subject('Test subject')
            ->text('Hello world')
            ->from('from@example.org')
            ->to('to@example.org');

        $mailer->send($message);
    }

    public function testMailerAssertions()
    {
use Symfony\Component\Messenger\Stamp\StampInterface;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\RawMessage;

class MailerTest extends TestCase
{
    public function testSendingRawMessages()
    {
        $this->expectException(LogicException::class);

        $transport = new Mailer($this->createMock(TransportInterface::class)$this->createMock(MessageBusInterface::class)$this->createMock(EventDispatcherInterface::class));
        $transport->send(new RawMessage('Some raw email message'));
    }

    public function testSendMessageToBus()
    {
        $bus = new class() implements MessageBusInterface {
            public array $messages = [];
            public array $stamps = [];

            public function dispatch($message, array $stamps = []): Envelope
            {
                
Home | Imprint | This part of the site doesn't use cookies.