transport example


    public function notify(Notification $notification, RecipientInterface $recipient, string $transportName = null): void
    {
        $message = null;
        if ($notification instanceof ChatNotificationInterface) {
            $message = $notification->asChatMessage($recipient$transportName);
        }

        $message ??= ChatMessage::fromNotification($notification);

        if (null !== $transportName) {
            $message->transport($transportName);
        }

        if (null === $this->bus) {
            $this->transport->send($message);
        } else {
            $this->bus->dispatch($message);
        }
    }

    public function supports(Notification $notification, RecipientInterface $recipient): bool
    {
        
public function testSetContent()
    {
        $message = new PushMessage('Hello', 'World');
        $message->content('dlrow olleH');

        $this->assertSame('dlrow olleH', $message->getContent());
    }

    public function testSetTransport()
    {
        $message = new PushMessage('Hello', 'World');
        $message->transport('next_one');

        $this->assertSame('next_one', $message->getTransport());
    }

    public function testCreateFromNotification()
    {
        $notification = new Notification('Hello');
        $notification->content('World');

        $message = PushMessage::fromNotification($notification);

        
if (!$email->getTo()) {
                $email->to($recipient->getEmail());
            }
        }

        if (null !== $this->envelope) {
            $message->envelope($this->envelope);
        }

        if (null !== $transportName) {
            $message->transport($transportName);
        }

        if (null === $this->bus) {
            $this->transport->send($message->getMessage()$message->getEnvelope());
        } else {
            $this->bus->dispatch(new SendEmailMessage($message->getMessage()$message->getEnvelope()));
        }
    }

    public function supports(Notification $notification, RecipientInterface $recipient): bool
    {
        

    public function notify(Notification $notification, RecipientInterface $recipient, string $transportName = null): void
    {
        $message = null;
        if ($notification instanceof PushNotificationInterface) {
            $message = $notification->asPushMessage($recipient$transportName);
        }

        $message ??= PushMessage::fromNotification($notification);

        if (null !== $transportName) {
            $message->transport($transportName);
        }

        if (null === $this->bus) {
            $this->transport->send($message);
        } else {
            $this->bus->dispatch($message);
        }
    }

    public function supports(Notification $notification, RecipientInterface $recipient): bool
    {
        
$transports->send($message);
    }

    public function testThrowExceptionIfTransportDefinedByMessageIsNotSupported()
    {
        $transports = new Transports([
            'one' => $one = $this->createMock(TransportInterface::class),
            'two' => $two = $this->createMock(TransportInterface::class),
        ]);

        $message = new ChatMessage('subject');
        $message->transport('one');

        $one->method('supports')->with($message)->willReturn(false);
        $two->method('supports')->with($message)->willReturn(true);

        $this->expectException(LogicException::class);
        $this->expectExceptionMessage('The "one" transport does not support the given message.');

        $transports->send($message);
    }

    public function testThrowExceptionIfTransportDefinedByMessageDoesNotExist()
    {

    public function notify(Notification $notification, RecipientInterface $recipient, string $transportName = null): void
    {
        $message = null;
        if ($notification instanceof SmsNotificationInterface) {
            $message = $notification->asSmsMessage($recipient$transportName);
        }

        $message ??= SmsMessage::fromNotification($notification$recipient);

        if (null !== $transportName) {
            $message->transport($transportName);
        }

        if (null === $this->bus) {
            $this->transport->send($message);
        } else {
            $this->bus->dispatch($message);
        }
    }

    public function supports(Notification $notification, RecipientInterface $recipient): bool
    {
        
Home | Imprint | This part of the site doesn't use cookies.