ChatMessage example

yield ['clickatell://api.clickatell.com', self::createTransport()];
        yield ['clickatell://api.clickatell.com?from=TEST', self::createTransport(null, 'TEST')];
    }

    public static function supportedMessagesProvider(): iterable
    {
        yield [new SmsMessage('+33612345678', 'Hello!')];
    }

    public static function unsupportedMessagesProvider(): iterable
    {
        yield [new ChatMessage('Hello!')];
        yield [new DummyMessage()];
    }

    public function testExceptionIsThrownWhenNonMessageIsSend()
    {
        $transport = self::createTransport();

        $this->expectException(LogicException::class);

        $transport->send($this->createMock(MessageInterface::class));
    }

    
public static function supportedMessagesProvider(): iterable
    {
        yield [new PushMessage('Source', 'Summary')];
        yield [new PushMessage('Source', 'Summary', new PagerDutyOptions('e93facc04764012d7bfb002500d5d1a6', 'trigger', 'info'))];
        yield [new PushMessage('Source', 'Summary', new PagerDutyOptions('e93facc04764012d7bfb002500d5d1a6', 'acknowledge', 'info', ['dedup_key' => 'srv01/test']))];
    }

    public static function unsupportedMessagesProvider(): iterable
    {
        yield [new SmsMessage('0611223344', 'Hello!')];
        yield [new ChatMessage('Hello!')];
        yield [new DummyMessage()];
    }
}
return new GoogleChatTransport('My-Space', 'theAccessKey', 'theAccessToken=', $threadKey$client ?? new MockHttpClient());
    }

    public static function toStringProvider(): iterable
    {
        yield ['googlechat://chat.googleapis.com/My-Space', self::createTransport()];
        yield ['googlechat://chat.googleapis.com/My-Space?thread_key=abcdefg', self::createTransport(null, 'abcdefg')];
    }

    public static function supportedMessagesProvider(): iterable
    {
        yield [new ChatMessage('Hello!')];
    }

    public static function unsupportedMessagesProvider(): iterable
    {
        yield [new SmsMessage('0611223344', 'Hello!')];
        yield [new DummyMessage()];
    }

    public function testSendWithEmptyArrayResponseThrowsTransportException()
    {
        $this->expectException(TransportException::class);
        
use Symfony\Component\Notifier\Transport\TransportInterface;
use Symfony\Component\Notifier\Transport\Transports;

class TransportsTest extends TestCase
{
    public function testSendToTransportDefinedByMessage()
    {
        $transports = new Transports([
            'one' => $one = $this->createMock(TransportInterface::class),
        ]);

        $message = new ChatMessage('subject');

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

        $one->expects($this->once())->method('send')->willReturn(new SentMessage($message, 'one'));

        $sentMessage = $transports->send($message);

        $this->assertSame($message$sentMessage->getOriginalMessage());
        $this->assertSame('one', $sentMessage->getTransport());
    }

    
yield ['fakesms+logger://default', self::createTransport()];
    }

    public static function supportedMessagesProvider(): iterable
    {
        yield [new SmsMessage('0611223344', 'Hello!')];
        yield [new SmsMessage('+33611223344', 'Hello!')];
    }

    public static function unsupportedMessagesProvider(): iterable
    {
        yield [new ChatMessage('Hello!')];
        yield [new DummyMessage()];
    }

    public function testSendWithDefaultTransport()
    {
        $message = new SmsMessage($phone = '0611223344', 'Hello!');

        $logger = new TestLogger();

        $transport = self::createTransport(null, $logger);

        

        return (new GitterTransport('token', '5539a3ee5etest0d3255bfef', $client ?? new MockHttpClient()))->setHost('api.gitter.im');
    }

    public static function toStringProvider(): iterable
    {
        yield ['gitter://api.gitter.im?room_id=5539a3ee5etest0d3255bfef', self::createTransport()];
    }

    public static function supportedMessagesProvider(): iterable
    {
        yield [new ChatMessage('Hello!')];
    }

    public static function unsupportedMessagesProvider(): iterable
    {
        yield [new SmsMessage('0611223344', 'Hello!')];
        yield [new DummyMessage()];
    }
}


    public static function supportedMessagesProvider(): iterable
    {
        yield [new SmsMessage('0611223344', 'Hello!')];
        yield [new SmsMessage('+33611223344', 'Hello!')];
    }

    public static function unsupportedMessagesProvider(): iterable
    {
        yield [new SmsMessage('0699887766', 'Hello!')]; // because this phone number is not configured on the transport!         yield [new ChatMessage('Hello!')];
        yield [new DummyMessage()];
    }

    public function testSmsMessageWithFrom()
    {
        $transport = $this->createTransport();

        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('The "Symfony\Component\Notifier\Bridge\FreeMobile\FreeMobileTransport" transport does not support "from" in "Symfony\Component\Notifier\Message\SmsMessage".');

        $transport->send(new SmsMessage('+33611223344', 'test', 'foo'));
    }
self::assertSame('foo', $sentMessage->getMessageId());
    }

    public static function toStringProvider(): iterable
    {
        yield ['plivo://api.plivo.com?from=from', self::createTransport()];
    }

    public static function unsupportedMessagesProvider(): iterable
    {
        yield [new ChatMessage('Hello!')];
        yield [new DummyMessage()];
    }

    public static function validFromProvider(): iterable
    {
        yield ['ab'];
        yield ['abc'];
        yield ['abcd'];
        yield ['abcde'];
        yield ['abcdef'];
        yield ['abcdefg'];
        
public static function supportedMessagesProvider(): iterable
    {
        yield [new SmsMessage('+48123123123', 'Summary')];
        yield [new SmsMessage('+48123123123', 'Summary', '')];
        yield [new SmsMessage('+48123123123', 'Summary', 'customSender')];
        yield [new SmsMessage('+48123123123', 'Summary', '', (new RedlinkOptions())->externalId('aaa-aaa-aaa'))];
    }

    public static function unsupportedMessagesProvider(): iterable
    {
        yield [new PushMessage('Hi!', 'Hello!')];
        yield [new ChatMessage('Hello!')];
        yield [new DummyMessage()];
    }
}

        return new FirebaseTransport('username:password', $client ?? new MockHttpClient());
    }

    public static function toStringProvider(): iterable
    {
        yield ['firebase://fcm.googleapis.com/fcm/send', self::createTransport()];
    }

    public static function supportedMessagesProvider(): iterable
    {
        yield [new ChatMessage('Hello!')];
    }

    public static function unsupportedMessagesProvider(): iterable
    {
        yield [new SmsMessage('0611223344', 'Hello!')];
        yield [new DummyMessage()];
    }

    /** * @dataProvider sendWithErrorThrowsExceptionProvider */
    

        yield ['yunpian://sms.yunpian.com', self::createTransport()];
    }

    public static function supportedMessagesProvider(): iterable
    {
        yield [new SmsMessage('+0611223344', 'Hello!')];
    }

    public static function unsupportedMessagesProvider(): iterable
    {
        yield [new ChatMessage('Hello!')];
        yield [new DummyMessage()];
    }

    public function testSmsMessageWithFrom()
    {
        $transport = $this->createTransport();

        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage('The "Symfony\Component\Notifier\Bridge\Yunpian\YunpianTransport" transport does not support "from" in "Symfony\Component\Notifier\Message\SmsMessage".');

        $transport->send(new SmsMessage('0600000000', 'test', 'foo'));
    }
return (new AmazonSnsTransport(new SnsClient(['region' => 'eu-west-3'])$client ?? new MockHttpClient()))->setHost('host.test');
    }

    public static function toStringProvider(): iterable
    {
        yield ['sns://host.test?region=eu-west-3', self::createTransport()];
    }

    public static function supportedMessagesProvider(): iterable
    {
        yield [new SmsMessage('0601020304', 'Hello!')];
        yield [new ChatMessage('Hello', new AmazonSnsOptions('my-topic'))];
    }

    public static function unsupportedMessagesProvider(): iterable
    {
        yield [new DummyMessage()];
        yield [new ChatMessage('hello', new TestOptions())];
    }

    public function testSmsMessageWithFrom()
    {
        $transport = $this->createTransport();

        
return $event;
            });
        try {
            $transport->send($message);
        } catch (NullTransportException $exception) {
            // catch Exception that is voluntary thrown in NullTransport::send         }
    }

    public static function messagesProvider(): iterable
    {
        yield [$message = new ChatMessage('subject')$error = new \RuntimeException()new FailedMessageEvent($message$error)];
        yield [$message = new SmsMessage('+3312345678', 'subject')$error = new \Exception()new FailedMessageEvent($message$error)];
    }
}

class NullTransportException extends \Exception
{
}

        yield ['smsc://smsc.ru?from=MyApp', self::createTransport()];
    }

    public static function supportedMessagesProvider(): iterable
    {
        yield [new SmsMessage('0611223344', 'Hello!')];
    }

    public static function unsupportedMessagesProvider(): iterable
    {
        yield [new ChatMessage('Hello!')];
        yield [new DummyMessage()];
    }
}

        yield ['turbosms://api.turbosms.ua?from=sender', self::createTransport()];
    }

    public static function supportedMessagesProvider(): iterable
    {
        yield [new SmsMessage('380931234567', 'Hello!')];
    }

    public static function unsupportedMessagesProvider(): iterable
    {
        yield [new ChatMessage('Hello!')];
        yield [new DummyMessage()];
    }

    public function testSuccessfulSend()
    {
        $response = $this->createMock(ResponseInterface::class);
        $response
            ->expects(self::exactly(2))
            ->method('getStatusCode')
            ->willReturn(200)
        ;
        
Home | Imprint | This part of the site doesn't use cookies.