-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
AbstractTransportTest.php
49 lines (43 loc) · 1.57 KB
/
AbstractTransportTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Mailer\Tests\Transport;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Mailer\SmtpEnvelope;
use Symfony\Component\Mailer\Transport\NullTransport;
use Symfony\Component\Mime\Address;
use Symfony\Component\Mime\RawMessage;
/**
* @group time-sensitive
*/
class AbstractTransportTest extends TestCase
{
public function testThrottling()
{
$transport = new NullTransport();
$transport->setMaxPerSecond(2 / 10);
$message = new RawMessage('');
$envelope = new SmtpEnvelope(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);
$this->assertEqualsWithDelta(15, time() - $start, 1);
$start = time();
$transport->setMaxPerSecond(-3);
$transport->send($message, $envelope);
$this->assertEqualsWithDelta(0, time() - $start, 1);
$transport->send($message, $envelope);
$this->assertEqualsWithDelta(0, time() - $start, 1);
}
}