Test Failed
Pull Request — master (#194)
by
unknown
01:45
created

MailboxCheckValidationTest::testDNSWarnings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
dl 7
loc 7
rs 10
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->createMock(SmtpSocketHelper::class);
17
18
        $socketHelperMock
19
            ->expects($this->any())
20
            ->method('isResource')
21
            ->willReturn(true)
22
        ;
23
24
        $socketHelperMock
25
            ->expects($this->any())
26
            ->method('getResponseCode')
27
            ->willReturnOnConsecutiveCalls(220, 250, 250, 250)
28
        ;
29
30
        $validation = new MailboxCheckValidation($socketHelperMock, '[email protected]');
0 ignored issues
show
Documentation introduced by
$socketHelperMock is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Egulias\EmailVali...elper\SmtpSocketHelper>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
31
32
        $this->assertTrue($validation->isValid('[email protected]', new EmailLexer()));
33
    }
34
35 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...
36
    {
37
        $validation = new MailboxCheckValidation(new SmtpSocketHelper(), '[email protected]');
38
        $expectedWarnings = [NoDNSMXRecord::CODE => new NoDNSMXRecord()];
39
        $validation->isValid('[email protected]', new EmailLexer());
40
        $this->assertEquals($expectedWarnings, $validation->getWarnings());
41
    }
42
43 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...
44
    {
45
        $socketHelperMock = $this->createMock(SmtpSocketHelper::class);
46
47
        $socketHelperMock
48
            ->expects($this->any())
49
            ->method('isResource')
50
            ->willReturn(true)
51
        ;
52
53
        $socketHelperMock
54
            ->expects($this->any())
55
            ->method('getResponseCode')
56
            ->willReturnOnConsecutiveCalls(220, 250, 250, 550)
57
        ;
58
59
        $validation = new MailboxCheckValidation($socketHelperMock, '[email protected]');
0 ignored issues
show
Documentation introduced by
$socketHelperMock is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Egulias\EmailVali...elper\SmtpSocketHelper>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
60
        $validation->isValid('[email protected]', new EmailLexer());
61
        $this->assertEquals(new IllegalMailbox(550), $validation->getError());
62
    }
63
}
64