SmsapiTransport example

use Symfony\Component\Notifier\Exception\TransportException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\SmsMessage;
use Symfony\Component\Notifier\Test\TransportTestCase;
use Symfony\Component\Notifier\Tests\Transport\DummyMessage;
use Symfony\Contracts\HttpClient\HttpClientInterface;

final class SmsapiTransportTest extends TransportTestCase
{
    public static function createTransport(HttpClientInterface $client = null, string $from = '', bool $fast = false, bool $test = false): SmsapiTransport
    {
        return (new SmsapiTransport('testToken', $from$client ?? new MockHttpClient()))->setHost('test.host')->setFast($fast)->setTest($test);
    }

    public static function toStringProvider(): iterable
    {
        yield ['smsapi://test.host', self::createTransport()];
        yield ['smsapi://test.host?fast=1', self::createTransport(null, '', true)];
        yield ['smsapi://test.host?test=1', self::createTransport(null, '', false, true)];
        yield ['smsapi://test.host?fast=1&test=1', self::createTransport(null, '', true, true)];
        yield ['smsapi://test.host?from=testFrom', self::createTransport(null, 'testFrom')];
        yield ['smsapi://test.host?from=testFrom&fast=1', self::createTransport(null, 'testFrom', true)];
        yield ['smsapi://test.host?from=testFrom&test=1', self::createTransport(null, 'testFrom', false, true)];
        
if ('smsapi' !== $scheme) {
            throw new UnsupportedSchemeException($dsn, 'smsapi', $this->getSupportedSchemes());
        }

        $authToken = $this->getUser($dsn);
        $from = $dsn->getOption('from', '');
        $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
        $fast = filter_var($dsn->getOption('fast', false), \FILTER_VALIDATE_BOOL);
        $test = filter_var($dsn->getOption('test', false), \FILTER_VALIDATE_BOOL);
        $port = $dsn->getPort();

        return (new SmsapiTransport($authToken$from$this->client, $this->dispatcher))->setFast($fast)->setHost($host)->setPort($port)->setTest($test);
    }

    protected function getSupportedSchemes(): array
    {
        return ['smsapi'];
    }
}
Home | Imprint | This part of the site doesn't use cookies.