1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace FH\Bundle\MailerBundle\Tests\Transport\Smtp; |
5
|
|
|
|
6
|
|
|
use FH\Bundle\MailerBundle\Transport\Smtp\PlainSmtpTransportFactory; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Symfony\Component\Mailer\Transport\Dsn; |
9
|
|
|
use Symfony\Component\Mailer\Transport\Smtp\SmtpTransport; |
10
|
|
|
use Symfony\Component\Mailer\Transport\Smtp\Stream\SocketStream; |
11
|
|
|
|
12
|
|
|
final class PlainSmtpTransportFactoryTest extends TestCase |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
private $factory; |
16
|
|
|
|
17
|
|
|
protected function setUp(): void |
18
|
|
|
{ |
19
|
|
|
$this->factory = new PlainSmtpTransportFactory(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @covers \FH\Bundle\MailerBundle\Transport\Smtp\PlainSmtpTransportFactory |
24
|
|
|
*/ |
25
|
|
|
public function testSupported(): void |
26
|
|
|
{ |
27
|
|
|
$dsn = new Dsn('plainsmtp', 'localhost'); |
28
|
|
|
|
29
|
|
|
$supports = $this->factory->supports($dsn); |
30
|
|
|
|
31
|
|
|
$this->assertTrue($supports); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @covers \FH\Bundle\MailerBundle\Transport\Smtp\PlainSmtpTransportFactory |
36
|
|
|
*/ |
37
|
|
|
public function testUnsupported(): void |
38
|
|
|
{ |
39
|
|
|
$dsn = new Dsn('smtp', 'localhost'); |
40
|
|
|
|
41
|
|
|
$supports = $this->factory->supports($dsn); |
42
|
|
|
|
43
|
|
|
$this->assertFalse($supports); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @covers \FH\Bundle\MailerBundle\Transport\Smtp\PlainSmtpTransportFactory |
48
|
|
|
*/ |
49
|
|
|
public function testCreateTransport(): void |
50
|
|
|
{ |
51
|
|
|
$dsn = new Dsn('plainsmtp', 'localhost'); |
52
|
|
|
$transport = $this->factory->create($dsn); |
53
|
|
|
/** @var SocketStream $stream */ |
54
|
|
|
$stream = $transport->getStream(); |
55
|
|
|
|
56
|
|
|
$this->assertInstanceOf(SmtpTransport::class, $transport); |
57
|
|
|
$this->assertEquals('localhost', $stream->getHost()); |
58
|
|
|
$this->assertEquals(25, $stream->getPort()); |
59
|
|
|
$this->assertFalse($stream->isTLS(), 'TLS should not be enabled'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @covers \FH\Bundle\MailerBundle\Transport\Smtp\PlainSmtpTransportFactory |
64
|
|
|
*/ |
65
|
|
|
public function testCreateTransportNoDefaultPort(): void |
66
|
|
|
{ |
67
|
|
|
$dsn = new Dsn('plainsmtp', 'localhost', null, null, 30); |
68
|
|
|
$transport = $this->factory->create($dsn); |
69
|
|
|
/** @var SocketStream $stream */ |
70
|
|
|
$stream = $transport->getStream(); |
71
|
|
|
|
72
|
|
|
$this->assertInstanceOf(SmtpTransport::class, $transport); |
73
|
|
|
$this->assertEquals('localhost', $stream->getHost()); |
74
|
|
|
$this->assertEquals(30, $stream->getPort()); |
75
|
|
|
$this->assertFalse($stream->isTLS(), 'TLS should not be enabled'); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|