Test Failed
Pull Request — master (#194)
by
unknown
02:39
created

MailboxCheckValidationTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 62
Duplicated Lines 91.94 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 7
dl 57
loc 62
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testValidMailbox() 25 25 1
A testDNSWarnings() 7 7 1
A testIllegalMailboxError() 25 25 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
            ->disableOriginalClone()
19
            ->disableArgumentCloning()
20
            ->disallowMockingUnknownTypes()
21
            ->getMock();
22
23
        $socketHelperMock
24
            ->expects($this->any())
25
            ->method('isResource')
26
            ->willReturn(true)
27
        ;
28
29
        $socketHelperMock
30
            ->expects($this->any())
31
            ->method('getResponseCode')
32
            ->willReturnOnConsecutiveCalls(220, 250, 250, 250)
33
        ;
34
35
        $validation = new MailboxCheckValidation($socketHelperMock, '[email protected]');
36
37
        $this->assertTrue($validation->isValid('[email protected]', new EmailLexer()));
38
    }
39
40 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...
41
    {
42
        $validation = new MailboxCheckValidation(new SmtpSocketHelper(), '[email protected]');
43
        $expectedWarnings = [NoDNSMXRecord::CODE => new NoDNSMXRecord()];
44
        $validation->isValid('[email protected]', new EmailLexer());
45
        $this->assertEquals($expectedWarnings, $validation->getWarnings());
46
    }
47
48 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...
49
    {
50
        $socketHelperMock = $this->getMockBuilder(SmtpSocketHelper::class)
51
            ->disableOriginalConstructor()
52
            ->disableOriginalClone()
53
            ->disableArgumentCloning()
54
            ->disallowMockingUnknownTypes()
55
            ->getMock();
56
57
        $socketHelperMock
58
            ->expects($this->any())
59
            ->method('isResource')
60
            ->willReturn(true)
61
        ;
62
63
        $socketHelperMock
64
            ->expects($this->any())
65
            ->method('getResponseCode')
66
            ->willReturnOnConsecutiveCalls(220, 250, 250, 550)
67
        ;
68
69
        $validation = new MailboxCheckValidation($socketHelperMock, '[email protected]');
70
        $validation->isValid('[email protected]', new EmailLexer());
71
        $this->assertEquals(new IllegalMailbox(550), $validation->getError());
72
    }
73
}
74