MandrillApiTransport example


    public function testToString(MandrillApiTransport $transport, string $expected)
    {
        $this->assertSame($expected(string) $transport);
    }

    public static function getTransportData()
    {
        return [
            [
                new MandrillApiTransport('KEY'),
                'mandrill+api://mandrillapp.com',
            ],
            [
                (new MandrillApiTransport('KEY'))->setHost('example.com'),
                'mandrill+api://example.com',
            ],
            [
                (new MandrillApiTransport('KEY'))->setHost('example.com')->setPort(99),
                'mandrill+api://example.com:99',
            ],
        ];
    }

final class MandrillTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): TransportInterface
    {
        $scheme = $dsn->getScheme();
        $user = $this->getUser($dsn);
        $host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
        $port = $dsn->getPort();

        if ('mandrill+api' === $scheme) {
            return (new MandrillApiTransport($user$this->client, $this->dispatcher, $this->logger))->setHost($host)->setPort($port);
        }

        if ('mandrill+https' === $scheme || 'mandrill' === $scheme) {
            return (new MandrillHttpTransport($user$this->client, $this->dispatcher, $this->logger))->setHost($host)->setPort($port);
        }

        if ('mandrill+smtp' === $scheme || 'mandrill+smtps' === $scheme) {
            $password = $this->getPassword($dsn);

            return new MandrillSmtpTransport($user$password$this->dispatcher, $this->logger);
        }

        
true,
        ];
    }

    public static function createProvider(): iterable
    {
        $client = new MockHttpClient();
        $logger = new NullLogger();

        yield [
            new Dsn('mandrill+api', 'default', self::USER),
            new MandrillApiTransport(self::USER, $client, null, $logger),
        ];

        yield [
            new Dsn('mandrill+api', 'example.com', self::USER, '', 8080),
            (new MandrillApiTransport(self::USER, $client, null, $logger))->setHost('example.com')->setPort(8080),
        ];

        yield [
            new Dsn('mandrill', 'default', self::USER),
            new MandrillHttpTransport(self::USER, $client, null, $logger),
        ];

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