Passed
Pull Request — master (#194)
by
unknown
02:29
created

MailboxCheckValidationTest::testValidMailbox()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22

Duplication

Lines 22
Ratio 100 %

Importance

Changes 0
Metric Value
dl 22
loc 22
rs 9.568
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Egulias\Tests\EmailValidator\Validation;
4
5
use Egulias\EmailValidator\EmailLexer;
6
use Egulias\EmailValidator\Helper\SmtpSocketHelper;
7
use Egulias\EmailValidator\Validation\Error\IllegalMailbox;
8
use Egulias\EmailValidator\Validation\MailboxCheckValidation;
9
use Egulias\EmailValidator\Warning\NoDNSMXRecord;
10
use PHPUnit\Framework\TestCase;
11
12
class MailboxCheckValidationTest extends TestCase
13
{
14 View Code Duplication
    public function testValidMailbox()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
15
    {
16
        $socketHelperMock = $this->getMockBuilder(SmtpSocketHelper::class)
17
            ->disableOriginalConstructor()
18
            ->getMock();
19
20
        $socketHelperMock
21
            ->expects($this->any())
22
            ->method('isResource')
23
            ->willReturn(true)
24
        ;
25
26
        $socketHelperMock
27
            ->expects($this->any())
28
            ->method('getResponseCode')
29
            ->willReturnOnConsecutiveCalls(220, 250, 250, 250)
30
        ;
31
32
        $validation = new MailboxCheckValidation($socketHelperMock, '[email protected]');
33
34
        $this->assertTrue($validation->isValid('[email protected]', new EmailLexer()));
35
    }
36
37 View Code Duplication
    public function testDNSWarnings()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
38
    {
39
        $validation = new MailboxCheckValidation(new SmtpSocketHelper(), '[email protected]');
40
        $expectedWarnings = [NoDNSMXRecord::CODE => new NoDNSMXRecord()];
41
        $validation->isValid('[email protected]', new EmailLexer());
42
        $this->assertEquals($expectedWarnings, $validation->getWarnings());
43
    }
44
45 View Code Duplication
    public function testIllegalMailboxError()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    {
47
        $socketHelperMock = $this->getMockBuilder(SmtpSocketHelper::class)
48
            ->disableOriginalConstructor()
49
            ->getMock();
50
51
        $socketHelperMock
52
            ->expects($this->any())
53
            ->method('isResource')
54
            ->willReturn(true)
55
        ;
56
57
        $socketHelperMock
58
            ->expects($this->any())
59
            ->method('getResponseCode')
60
            ->willReturnOnConsecutiveCalls(220, 250, 250, 550)
61
        ;
62
63
        $validation = new MailboxCheckValidation($socketHelperMock, '[email protected]');
64
        $validation->isValid('[email protected]', new EmailLexer());
65
        $this->assertEquals(new IllegalMailbox(550), $validation->getError());
66
    }
67
}
68