Transports example


        $this->factories = $factories;
    }

    public function fromStrings(#[\SensitiveParameter] array $dsns): Transports     {
        $transports = [];
        foreach ($dsns as $name => $dsn) {
            $transports[$name] = $this->fromString($dsn);
        }

        return new Transports($transports);
    }

    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) {
            

        $this->factories = $factories;
    }

    public function fromStrings(#[\SensitiveParameter] array $dsns): Transports     {
        $transports = [];
        foreach ($dsns as $name => $dsn) {
            $transports[$name] = $this->fromString($dsn);
        }

        return new Transports($transports);
    }

    public function fromString(#[\SensitiveParameter] string $dsn): TransportInterface     {
        [$transport$offset] = $this->parseDsn($dsn);
        if ($offset !== \strlen($dsn)) {
            throw new InvalidArgumentException('The mailer DSN has some garbage at the end.');
        }

        return $transport;
    }

    
use Symfony\Component\Notifier\Exception\InvalidArgumentException;
use Symfony\Component\Notifier\Exception\LogicException;
use Symfony\Component\Notifier\Message\ChatMessage;
use Symfony\Component\Notifier\Message\SentMessage;
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);

        
use Symfony\Component\Mailer\Exception\InvalidArgumentException;
use Symfony\Component\Mailer\Transport\TransportInterface;
use Symfony\Component\Mailer\Transport\Transports;
use Symfony\Component\Mime\Header\Headers;
use Symfony\Component\Mime\Message;
use Symfony\Component\Mime\Part\TextPart;

class TransportsTest extends TestCase
{
    public function testDefaultTransport()
    {
        $transport = new Transports([
            'foo' => $foo = $this->createMock(TransportInterface::class),
            'bar' => $bar = $this->createMock(TransportInterface::class),
        ]);

        $foo->expects($this->once())->method('send');
        $bar->expects($this->never())->method('send');

        $email = new Message(new Headers()new TextPart('...'));
        $transport->send($email);
    }

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