disableTls example

$sut->create(Dsn::fromString($dsn));
    }

    public static function provideCreate(): \Generator
    {
        yield ['native://default', '/usr/sbin/sendmail -t -i', '', '', new SendmailTransport('/usr/sbin/sendmail -t -i')];

        if ('\\' === \DIRECTORY_SEPARATOR) {
            $socketStream = new SocketStream();
            $socketStream->setHost('myhost.tld');
            $socketStream->setPort(25);
            $socketStream->disableTls();
            yield ['native://default', '', 'myhost.tld', '25', new SmtpTransport($socketStream)];

            $socketStreamTls = new SocketStream();
            $socketStreamTls->setHost('myhost.tld');
            $socketStreamTls->setPort(465);
            yield ['native://default', '', 'myhost.tld', '465', new SmtpTransport($socketStreamTls)];
        }
    }

    /** * @dataProvider provideCreate */
/** @var SocketStream $stream */
        $stream = $this->getStream();

        if (null === $tls) {
            if (465 === $port) {
                $tls = true;
            } else {
                $tls = \defined('OPENSSL_VERSION_NUMBER') && 0 === $port && 'localhost' !== $host;
            }
        }
        if (!$tls) {
            $stream->disableTls();
        }
        if (0 === $port) {
            $port = $tls ? 465 : 25;
        }

        $stream->setHost($host);
        $stream->setPort($port);
    }

    /** * @return $this */
/** * @group time-sensitive */
class SmtpTransportTest extends TestCase
{
    public function testToString()
    {
        $t = new SmtpTransport();
        $this->assertEquals('smtps://localhost', (string) $t);

        $t = new SmtpTransport((new SocketStream())->setHost('127.0.0.1')->setPort(2525)->disableTls());
        $this->assertEquals('smtp://127.0.0.1:2525', (string) $t);
    }

    public function testSendDoesNotPingBelowThreshold()
    {
        $stream = new DummyStream();
        $envelope = new Envelope(new Address('sender@example.org')[new Address('recipient@example.org')]);

        $transport = new SmtpTransport($stream);
        $transport->send(new RawMessage('Message 1')$envelope);
        $transport->send(new RawMessage('Message 2')$envelope);
        
        $host = ini_get('SMTP');
        $port = (int) ini_get('smtp_port');

        if (!$host || !$port) {
            throw new TransportException('smtp or smtp_port is not configured in php.ini.');
        }

        $socketStream = new SocketStream();
        $socketStream->setHost($host);
        $socketStream->setPort($port);
        if (465 !== $port) {
            $socketStream->disableTls();
        }

        return new SmtpTransport($socketStream$this->dispatcher, $this->logger);
    }

    protected function getSupportedSchemes(): array
    {
        return ['native'];
    }
}
Home | Imprint | This part of the site doesn't use cookies.