setMaxPerSecond example

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);
        $transport->send($message$envelope);
        


        $transport = new EsmtpTransport('example.com', 465, true, null, $logger);
        $transport->setLocalDomain('example.com');

        yield [
            new Dsn('smtps', 'example.com', '', '', 465, ['local_domain' => 'example.com']),
            $transport,
        ];

        $transport = new EsmtpTransport('example.com', 465, true, null, $logger);
        $transport->setMaxPerSecond(2.0);

        yield [
            new Dsn('smtps', 'example.com', '', '', 465, ['max_per_second' => '2']),
            $transport,
        ];

        $transport = new EsmtpTransport('example.com', 465, true, null, $logger);
        $transport->setRestartThreshold(10, 1);

        yield [
            new Dsn('smtps', 'example.com', '', '', 465, ['restart_threshold' => '10', 'restart_threshold_sleep' => '1']),
            


        if ($password = $dsn->getPassword()) {
            $transport->setPassword($password);
        }

        if (null !== ($localDomain = $dsn->getOption('local_domain'))) {
            $transport->setLocalDomain($localDomain);
        }

        if (null !== ($maxPerSecond = $dsn->getOption('max_per_second'))) {
            $transport->setMaxPerSecond((float) $maxPerSecond);
        }

        if (null !== ($restartThreshold = $dsn->getOption('restart_threshold'))) {
            $transport->setRestartThreshold((int) $restartThreshold(int) $dsn->getOption('restart_threshold_sleep', 0));
        }

        if (null !== ($pingThreshold = $dsn->getOption('ping_threshold'))) {
            $transport->setPingThreshold((int) $pingThreshold);
        }

        return $transport;
    }
Home | Imprint | This part of the site doesn't use cookies.