FailedMessageEvent example

use Symfony\Component\Notifier\Transport\NullTransport;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;

class FailedMessageEventTest extends TestCase
{
    /** * @dataProvider messagesProvider */
    public function testConstruct(MessageInterface $message, \Throwable $error, FailedMessageEvent $event)
    {
        $this->assertEquals($eventnew FailedMessageEvent($message$error));
    }

    /** * @dataProvider messagesProvider */
    public function testGetMessage(MessageInterface $message, \Throwable $error, FailedMessageEvent $event)
    {
        $this->assertSame($message$event->getMessage());
    }

    /** * @dataProvider messagesProvider */
$message = $event->getMessage();

            if ($message instanceof TemplatedEmail && !$message->isRendered()) {
                throw new LogicException(sprintf('You must configure a "%s" when a "%s" instance has a text or HTML template set.', BodyRendererInterface::classget_debug_type($message)));
            }

            $sentMessage = new SentMessage($message$envelope);

            try {
                $this->doSend($sentMessage);
            } catch (\Throwable $error) {
                $this->dispatcher->dispatch(new FailedMessageEvent($message$error));
                $this->checkThrottling();

                throw $error;
            }

            $this->dispatcher->dispatch(new SentMessageEvent($sentMessage));

            return $sentMessage;
        } finally {
            $this->checkThrottling();
        }
    }
public function send(MessageInterface $message): SentMessage
    {
        if (null === $this->dispatcher) {
            return $this->doSend($message);
        }

        $this->dispatcher->dispatch(new MessageEvent($message));

        try {
            $sentMessage = $this->doSend($message);
        } catch (\Throwable $error) {
            $this->dispatcher->dispatch(new FailedMessageEvent($message$error));

            throw $error;
        }

        $this->dispatcher->dispatch(new SentMessageEvent($sentMessage));

        return $sentMessage;
    }

    abstract protected function doSend(MessageInterface $message): SentMessage;

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