1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Yiisoft\Mailer\SwiftMailer\Tests; |
4
|
|
|
|
5
|
|
|
use Yiisoft\Mailer\SwiftMailer\Message; |
6
|
|
|
|
7
|
|
|
class MailerTest extends TestCase |
8
|
|
|
{ |
9
|
|
|
public function testSetUp(): void |
10
|
|
|
{ |
11
|
|
|
$mailer = $this->getMailer(); |
12
|
|
|
$this->assertEquals($this->get(TestTransport::class), $mailer->getTransport()); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
public function testSend(): void |
16
|
|
|
{ |
17
|
|
|
$mailer = $this->getMailer(); |
18
|
|
|
$message = (new Message()) |
19
|
|
|
->setSubject('Hi') |
20
|
|
|
->setTo('[email protected]'); |
21
|
|
|
$this->assertNull($mailer->send($message)); |
22
|
|
|
|
23
|
|
|
$invalidMsg = (new Message()) |
24
|
|
|
->setSubject('') |
25
|
|
|
->setTo('[email protected]'); |
26
|
|
|
$this->expectException(\RuntimeException::class); |
27
|
|
|
$mailer->send($invalidMsg); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @dataProvider dataProviderPlugins |
32
|
|
|
*/ |
33
|
|
|
public function testRegisterPlugins(\Swift_Events_EventListener ... $plugins): void |
34
|
|
|
{ |
35
|
|
|
$mailer = $this->getMailer(); |
36
|
|
|
$mailer->registerPlugins($plugins); |
37
|
|
|
|
38
|
|
|
$transport = $mailer->getTransport(); |
39
|
|
|
$this->assertInstanceOf(TestTransport::class, $transport); |
40
|
|
|
|
41
|
|
|
foreach ($plugins as $plugin) { |
42
|
|
|
$this->assertContains($plugin, $transport->plugins); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function dataProviderPlugins(): array |
47
|
|
|
{ |
48
|
|
|
return [ |
49
|
|
|
[new \Swift_Plugins_LoggerPlugin(new \Swift_Plugins_Loggers_EchoLogger(false))], |
50
|
|
|
[ |
51
|
|
|
new \Swift_Plugins_LoggerPlugin(new \Swift_Plugins_Loggers_EchoLogger(false)), |
52
|
|
|
new \Swift_Plugins_AntiFloodPlugin(), |
53
|
|
|
], |
54
|
|
|
]; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|