RoundRobinTransport example

use Symfony\Component\Mailer\Transport\TransportInterface;
use Symfony\Component\Mime\RawMessage;

/** * @group time-sensitive */
class RoundRobinTransportTest extends TestCase
{
    public function testSendNoTransports()
    {
        $this->expectException(TransportException::class);
        new RoundRobinTransport([]);
    }

    public function testToString()
    {
        $t1 = $this->createMock(TransportInterface::class);
        $t1->expects($this->once())->method('__toString')->willReturn('t1://local');
        $t2 = $this->createMock(TransportInterface::class);
        $t2->expects($this->once())->method('__toString')->willReturn('t2://local');
        $t = new RoundRobinTransport([$t1$t2]);
        $this->assertEquals('roundrobin(t1://local t2://local)', (string) $t);
    }

    


    public function fromString(#[\SensitiveParameter] string $dsn): TransportInterface     {
        $dsns = preg_split('/\s++\|\|\s++/', $dsn);
        if (\count($dsns) > 1) {
            return new FailoverTransport($this->createFromDsns($dsns));
        }

        $dsns = preg_split('/\s++&&\s++/', $dsn);
        if (\count($dsns) > 1) {
            return new RoundRobinTransport($this->createFromDsns($dsns));
        }

        return $this->fromDsnObject(new Dsn($dsn));
    }

    public function fromDsnObject(Dsn $dsn): TransportInterface
    {
        foreach ($this->factories as $factory) {
            if ($factory->supports($dsn)) {
                return $factory->create($dsn);
            }
        }
'dummy://a',
            $transportA,
        ];

        yield 'failover transport' => [
            'failover(dummy://a dummy://b)',
            new FailoverTransport([$transportA$transportB]),
        ];

        yield 'round robin transport' => [
            'roundrobin(dummy://a dummy://b)',
            new RoundRobinTransport([$transportA$transportB]),
        ];

        yield 'mixed transport' => [
            'roundrobin(dummy://a failover(dummy://b dummy://a) dummy://b)',
            new RoundRobinTransport([$transportAnew FailoverTransport([$transportB$transportA])$transportB]),
        ];
    }

    /** * @dataProvider fromDsnProvider */
    
Home | Imprint | This part of the site doesn't use cookies.