Completed
Pull Request — develop (#11)
by Misha
02:31
created

testCreateTransport()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 11
rs 10
c 1
b 0
f 1
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
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\Composer\ApplyEmailMessageOptions
24
     */
25
    public function testCreateTransport(): void
26
    {
27
        $dsn = new Dsn('smtp', 'localhost');
28
        $transport = $this->factory->create($dsn);
29
        /** @var SocketStream $stream */
30
        $stream = $transport->getStream();
31
32
        $this->assertInstanceOf(SmtpTransport::class, $transport);
33
        $this->assertEquals('localhost', $stream->getHost());
34
        $this->assertEquals(25, $stream->getPort());
35
        $this->assertFalse($stream->isTLS(), 'TLS should not be enabled');
36
    }
37
38
    /**
39
     * @covers \FH\Bundle\MailerBundle\Composer\ApplyEmailMessageOptions
40
     */
41
    public function testCreateTransportNoDefaultPort(): void
42
    {
43
        $dsn = new Dsn('smtp', 'localhost', null, null, 30);
44
        $transport = $this->factory->create($dsn);
45
        /** @var SocketStream $stream */
46
        $stream = $transport->getStream();
47
48
        $this->assertInstanceOf(SmtpTransport::class, $transport);
49
        $this->assertEquals('localhost', $stream->getHost());
50
        $this->assertEquals(30, $stream->getPort());
51
        $this->assertFalse($stream->isTLS(), 'TLS should not be enabled');
52
    }
53
}
54