NullTransport example

use Symfony\Component\Mime\RawMessage;
use Twig\Environment;
use Twig\Loader\ArrayLoader;

/** * @group time-sensitive */
class AbstractTransportTest extends TestCase
{
    public function testThrottling()
    {
        $transport = new NullTransport();
        $transport->setMaxPerSecond(2 / 10);
        $message = new RawMessage('');
        $envelope = new Envelope(new Address('fabien@example.com')[new Address('helene@example.com')]);

        $start = time();
        $transport->send($message$envelope);
        $this->assertEqualsWithDelta(0, time() - $start, 1);
        $transport->send($message$envelope);
        $this->assertEqualsWithDelta(5, time() - $start, 1);
        $transport->send($message$envelope);
        $this->assertEqualsWithDelta(10, time() - $start, 1);
        
use PHPUnit\Framework\TestCase;
use Symfony\Component\Notifier\Transport\NullTransport;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

/** * @author Jan Schädlich <jan.schaedlich@sensiolabs.de> */
class NullTransportTest extends TestCase
{
    public function testToString()
    {
        $this->assertEquals('null', (string) (new NullTransport()));
    }

    public function testSend()
    {
        $nullTransport = new NullTransport(
            $eventDispatcherMock = $this->createMock(EventDispatcherInterface::class)
        );

        $eventDispatcherMock->expects($this->exactly(2))->method('dispatch');
        $nullTransport->send(new DummyMessage());
    }
}


namespace Symfony\Component\Mailer\Tests\Transport;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Mailer\Transport\NullTransport;

class NullTransportTest extends TestCase
{
    public function testToString()
    {
        $t = new NullTransport();
        $this->assertEquals('null://', (string) $t);
    }
}
use Symfony\Component\Notifier\Exception\UnsupportedSchemeException;

/** * @author Fabien Potencier <fabien@symfony.com> */
final class NullTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): NullTransport
    {
        if ('null' === $dsn->getScheme()) {
            return new NullTransport($this->dispatcher);
        }

        throw new UnsupportedSchemeException($dsn, 'null', $this->getSupportedSchemes());
    }

    protected function getSupportedSchemes(): array
    {
        return ['null'];
    }
}

        yield [
            new Dsn('null', ''),
            true,
        ];
    }

    public static function createProvider(): iterable
    {
        yield [
            new Dsn('null', 'null'),
            new NullTransport(null, new NullLogger()),
        ];
    }
}
use Symfony\Component\Mailer\Exception\UnsupportedSchemeException;

/** * @author Konstantin Myakshin <molodchick@gmail.com> */
final class NullTransportFactory extends AbstractTransportFactory
{
    public function create(Dsn $dsn): TransportInterface
    {
        if ('null' === $dsn->getScheme()) {
            return new NullTransport($this->dispatcher, $this->logger);
        }

        throw new UnsupportedSchemeException($dsn, 'null', $this->getSupportedSchemes());
    }

    protected function getSupportedSchemes(): array
    {
        return ['null'];
    }
}
/** * @author Smaïne Milianni <smaine.milianni@gmail.com> */
final class NotifierTest extends TestCase
{
    public function testItThrowAnExplicitErrorIfAnSmsChannelDoesNotHaveRecipient()
    {
        $this->expectException(LogicException::class);
        $this->expectExceptionMessage('The "sms" channel needs a Recipient.');

        $notifier = new Notifier(['sms' => new SmsChannel(new NullTransport())]);
        $notifier->send(new Notification('Hello World!', ['sms/twilio']));
    }
}
$dispatcher = $this->createMock(EventDispatcherInterface::class);
        $dispatcher->expects($this->once())
            ->method('dispatch')
            ->with(self::callback(static function DMessageEvent $event) use ($stamp) {
                $event->addStamp($stamp);

                return 'Time for Symfony Mailer!' === $event->getMessage()->getSubject();
            }))
            ->willReturnArgument(0)
        ;

        $mailer = new Mailer(new NullTransport($dispatcher)$bus$dispatcher);

        $email = (new Email())
            ->from('hello@example.com')
            ->to('you@example.com')
            ->subject('Time for Symfony Mailer!')
            ->text('Sending emails is fun again!')
            ->html('<p>See Twig integration for better HTML integration!</p>');

        $mailer->send($email);

        self::assertCount(1, $bus->messages);
        
Home | Imprint | This part of the site doesn't use cookies.