Completed
Push — master ( e56856...67d12b )
by Antonio
04:26
created

SmtpCredentialsValidatorTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 5
dl 0
loc 49
rs 10
1
<?php
2
namespace Da\Mailer\Test\Validator;
3
4
use Da\Mailer\Validator\SmtpCredentialsValidator;
5
use Exception;
6
use Mockery;
7
use PHPUnit_Framework_TestCase;
8
use Swift_SmtpTransport;
9
10
/**
11
 * @runTestsInSeparateProcesses
12
 * @preserveGlobalState disabled
13
 */
14
class SmtpCredentialsValidatorTest extends PHPUnit_Framework_TestCase
15
{
16
    public function testValidationPassed()
17
    {
18
        $mock = Mockery::mock('overload:' . Swift_SmtpTransport::class);
19
        $mock->shouldReceive('start')->once()->andReturn(true);
20
        $mock->shouldReceive('setUsername')->once()->with('Obiwoan');
21
        $mock->shouldReceive('setPassword')->once()->with('Kenovi');
22
        $mock->shouldReceive('setEncryption')->once()->with('ssl');
23
        $mock->shouldReceive('setAuthMode')->once()->with('Plain');
24
25
        $validator = SmtpCredentialsValidator::fromArray(
26
            [
27
                'host' => 'localhost',
28
                'port' => 587,
29
                'username' => 'Obiwoan',
30
                'password' => 'Kenovi',
31
                'encryption' => 'ssl',
32
                'authMode' => 'Plain',
33
            ]
34
        );
35
36
        $this->assertTrue($validator->validate());
37
    }
38
39
    public function testValidationThrowsException()
40
    {
41
        $mock = Mockery::mock('overload:' . Swift_SmtpTransport::class);
42
43
        $mock->shouldReceive('start')->once()->andThrow(Exception::class);
44
        $mock->shouldReceive('setUsername')->once()->with('Obiwoan');
45
        $mock->shouldReceive('setPassword')->once()->with('Kenovi');
46
        $mock->shouldReceive('setEncryption')->once()->with('ssl');
47
        $mock->shouldReceive('setAuthMode')->once()->with('Plain');
48
49
        $validator = SmtpCredentialsValidator::fromArray(
50
            [
51
                'host' => 'localhost',
52
                'port' => 587,
53
                'username' => 'Obiwoan',
54
                'password' => 'Kenovi',
55
                'encryption' => 'ssl',
56
                'authMode' => 'Plain',
57
            ]
58
        );
59
60
        $this->assertTrue($validator->validate() === false);
61
    }
62
}
63