NullMessage example

/** * @author Jan Schädlich <jan.schaedlich@sensiolabs.de> */
class NullMessageTest extends TestCase
{
    /** * @dataProvider messageDataProvider */
    public function testCanBeConstructed(MessageInterface $message)
    {
        $nullMessage = new NullMessage($message);

        $this->assertSame($message->getSubject()$nullMessage->getSubject());
        $this->assertSame($message->getRecipientId()$nullMessage->getRecipientId());
        $this->assertSame($message->getOptions()$nullMessage->getOptions());

        (null === $message->getTransport())
            ? $this->assertSame('null', $nullMessage->getTransport())
            : $this->assertSame($message->getTransport()$nullMessage->getTransport());
    }

    public static function messageDataProvider(): \Generator
    {
class NullTransport implements TransportInterface
{
    private ?EventDispatcherInterface $dispatcher;

    public function __construct(EventDispatcherInterface $dispatcher = null)
    {
        $this->dispatcher = $dispatcher;
    }

    public function send(MessageInterface $message): SentMessage
    {
        $message = new NullMessage($message);
        $sentMessage = new SentMessage($message(string) $this);

        if (null === $this->dispatcher) {
            return $sentMessage;
        }

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

        return $sentMessage;
    }

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