PushoverTransport example

use Symfony\Component\Notifier\Message\PushMessage;
use Symfony\Component\Notifier\Notification\Notification;
use Symfony\Component\Notifier\Test\TransportTestCase;
use Symfony\Component\Notifier\Tests\Transport\DummyMessage;
use Symfony\Contracts\HttpClient\HttpClientInterface;
use Symfony\Contracts\HttpClient\ResponseInterface;

final class PushoverTransportTest extends TransportTestCase
{
    public static function createTransport(HttpClientInterface $client = null): PushoverTransport
    {
        return new PushoverTransport('userKey', 'appToken', $client ?? new MockHttpClient());
    }

    public static function toStringProvider(): iterable
    {
        yield ['pushover://api.pushover.net', self::createTransport()];
    }

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

    
public function create(Dsn $dsn): TransportInterface
    {
        if ('pushover' !== $dsn->getScheme()) {
            throw new UnsupportedSchemeException($dsn, 'pushover', $this->getSupportedSchemes());
        }

        $userKey = $dsn->getUser();
        $appToken = $dsn->getPassword();
        $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
        $port = $dsn->getPort();

        return (new PushoverTransport($userKey$appToken$this->client, $this->dispatcher))->setHost($host)->setPort($port);
    }

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