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
|
|
|
/** |
13
|
|
|
* @covers \FH\Bundle\MailerBundle\Transport\Smtp\PlainSmtpTransportFactory |
14
|
|
|
*/ |
15
|
|
|
final class PlainSmtpTransportFactoryTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
private $factory; |
19
|
|
|
|
20
|
|
|
protected function setUp(): void |
21
|
|
|
{ |
22
|
|
|
$this->factory = new PlainSmtpTransportFactory(); |
23
|
|
|
} |
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
|
|
|
public function testUnsupported(): void |
35
|
|
|
{ |
36
|
|
|
$dsn = new Dsn('smtp', 'localhost'); |
37
|
|
|
|
38
|
|
|
$supports = $this->factory->supports($dsn); |
39
|
|
|
|
40
|
|
|
$this->assertFalse($supports); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testCreateTransport(): void |
44
|
|
|
{ |
45
|
|
|
$dsn = new Dsn('plainsmtp', 'localhost'); |
46
|
|
|
$transport = $this->factory->create($dsn); |
47
|
|
|
/** @var SocketStream $stream */ |
48
|
|
|
$stream = $transport->getStream(); |
49
|
|
|
|
50
|
|
|
$this->assertInstanceOf(SmtpTransport::class, $transport); |
51
|
|
|
$this->assertEquals('localhost', $stream->getHost()); |
52
|
|
|
$this->assertEquals(25, $stream->getPort()); |
53
|
|
|
$this->assertFalse($stream->isTLS(), 'TLS should not be enabled'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testCreateTransportNoDefaultPort(): void |
57
|
|
|
{ |
58
|
|
|
$dsn = new Dsn('plainsmtp', 'localhost', null, null, 30); |
59
|
|
|
$transport = $this->factory->create($dsn); |
60
|
|
|
/** @var SocketStream $stream */ |
61
|
|
|
$stream = $transport->getStream(); |
62
|
|
|
|
63
|
|
|
$this->assertInstanceOf(SmtpTransport::class, $transport); |
64
|
|
|
$this->assertEquals('localhost', $stream->getHost()); |
65
|
|
|
$this->assertEquals(30, $stream->getPort()); |
66
|
|
|
$this->assertFalse($stream->isTLS(), 'TLS should not be enabled'); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|