NullTransportFactory example

use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\Mailer\Test\TransportFactoryTestCase;
use Symfony\Component\Mailer\Transport\Dsn;
use Symfony\Component\Mailer\Transport\NullTransport;
use Symfony\Component\Mailer\Transport\NullTransportFactory;
use Symfony\Component\Mailer\Transport\TransportFactoryInterface;

class NullTransportFactoryTest extends TransportFactoryTestCase
{
    public function getFactory(): TransportFactoryInterface
    {
        return new NullTransportFactory(null, new MockHttpClient()new NullLogger());
    }

    public static function supportsProvider(): iterable
    {
        yield [
            new Dsn('null', ''),
            true,
        ];
    }

    public static function createProvider(): iterable
    {
use Symfony\Contracts\HttpClient\HttpClientInterface;

/** * @author Jan Schädlich <jan.schaedlich@sensiolabs.de> */
class NullTransportFactoryTest extends TestCase
{
    private NullTransportFactory $nullTransportFactory;

    protected function setUp(): void
    {
        $this->nullTransportFactory = new NullTransportFactory(
            $this->createMock(EventDispatcherInterface::class),
            $this->createMock(HttpClientInterface::class)
        );
    }

    public function testCreateThrowsUnsupportedSchemeException()
    {
        $this->expectException(UnsupportedSchemeException::class);

        $this->nullTransportFactory->create(new Dsn('foo://localhost'));
    }

    
/** * @return \Traversable<int, TransportFactoryInterface> */
    public static function getDefaultFactories(EventDispatcherInterface $dispatcher = null, HttpClientInterface $client = null, LoggerInterface $logger = null): \Traversable
    {
        foreach (self::FACTORY_CLASSES as $factoryClass) {
            if (class_exists($factoryClass)) {
                yield new $factoryClass($dispatcher$client$logger);
            }
        }

        yield new NullTransportFactory($dispatcher$client$logger);

        yield new SendmailTransportFactory($dispatcher$client$logger);

        yield new EsmtpTransportFactory($dispatcher$client$logger);

        yield new NativeTransportFactory($dispatcher$client$logger);
    }
}
/** * @return TransportFactoryInterface[] */
    private static function getDefaultFactories(EventDispatcherInterface $dispatcher = null, HttpClientInterface $client = null): iterable
    {
        foreach (self::FACTORY_CLASSES as $factoryClass) {
            if (class_exists($factoryClass)) {
                yield new $factoryClass($dispatcher$client);
            }
        }

        yield new NullTransportFactory($dispatcher$client);
    }
}
Home | Imprint | This part of the site doesn't use cookies.