Passed
Push — master ( e68c26...709f21 )
by Eduardo Gulias
02:00
created

testGathersAllTheErrors()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23

Duplication

Lines 23
Ratio 100 %

Importance

Changes 0
Metric Value
dl 23
loc 23
rs 9.552
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\EmailValidator;
6
use Egulias\EmailValidator\Exception\CommaInDomain;
7
use Egulias\EmailValidator\Exception\NoDomainPart;
8
use Egulias\EmailValidator\Validation\MultipleErrors;
9
use Egulias\EmailValidator\Validation\MultipleValidationWithAnd;
10
use Egulias\EmailValidator\Validation\NoRFCWarningsValidation;
11
use Egulias\EmailValidator\Validation\RFCValidation;
12
use Egulias\EmailValidator\Warning\AddressLiteral;
13
use Egulias\EmailValidator\Warning\DomainLiteral;
14
use PHPUnit\Framework\TestCase;
15
16
class MultipleValidationWithAndTest extends TestCase
17
{
18
    public function testUsesAndLogicalOperation()
19
    {
20
        $lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
21
        $validationTrue = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
22
        $validationTrue->expects($this->any())->method("isValid")->willReturn(true);
23
        $validationTrue->expects($this->any())->method("getWarnings")->willReturn([]);
24
        $validationFalse = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
25
        $validationFalse->expects($this->any())->method("isValid")->willReturn(false);
26
        $validationFalse->expects($this->any())->method("getWarnings")->willReturn([]);
27
        $multipleValidation = new MultipleValidationWithAnd([$validationTrue, $validationFalse]);
0 ignored issues
show
Documentation introduced by
array($validationTrue, $validationFalse) is of type array<integer,object<PHP...kObject\\MockObject>"}>, but the function expects a array<integer,object<Egu...ation\EmailValidation>>.

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...
28
        $this->assertFalse($multipleValidation->isValid("[email protected]", $lexer));
0 ignored issues
show
Documentation introduced by
$lexer is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Egulias\EmailValidator\EmailLexer>.

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...
29
    }
30
31
    /**
32
     * @expectedException \Egulias\EmailValidator\Validation\Exception\EmptyValidationList
33
     */
34
    public function testEmptyListIsNotAllowed()
35
    {
36
        new MultipleValidationWithAnd([]);
37
    }
38
39 View Code Duplication
    public function testValidationIsValid()
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...
40
    {
41
        $lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
42
43
        $validation = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
44
        $validation->expects($this->any())->method("isValid")->willReturn(true);
45
        $validation->expects($this->once())->method("getWarnings")->willReturn([]);
46
47
        $multipleValidation = new MultipleValidationWithAnd([$validation]);
0 ignored issues
show
Documentation introduced by
array($validation) is of type array<integer,object<PHP...kObject\\MockObject>"}>, but the function expects a array<integer,object<Egu...ation\EmailValidation>>.

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...
48
        $this->assertTrue($multipleValidation->isValid("[email protected]", $lexer));
0 ignored issues
show
Documentation introduced by
$lexer is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Egulias\EmailValidator\EmailLexer>.

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...
49
        $this->assertNull($multipleValidation->getError());
50
    }
51
52
    public function testAccumulatesWarnings()
53
    {
54
        $warnings1 = [
55
            AddressLiteral::CODE => new AddressLiteral()
56
        ];
57
        $warnings2 = [
58
            DomainLiteral::CODE => new DomainLiteral()
59
        ];
60
        $expectedResult = array_merge($warnings1, $warnings2);
61
62
        $lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
63
        $validation1 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
64
        $validation1->expects($this->any())->method("isValid")->willReturn(true);
65
        $validation1->expects($this->once())->method("getWarnings")->willReturn($warnings1);
66
67
        $validation2 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
68
69
        $validation2->expects($this->any())->method("isValid")->willReturn(false);
70
        $validation2->expects($this->once())->method("getWarnings")->willReturn($warnings2);
71
72
        $multipleValidation = new MultipleValidationWithAnd([$validation1, $validation2]);
0 ignored issues
show
Documentation introduced by
array($validation1, $validation2) is of type array<integer,object<PHP...kObject\\MockObject>"}>, but the function expects a array<integer,object<Egu...ation\EmailValidation>>.

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...
73
        $multipleValidation->isValid("[email protected]", $lexer);
0 ignored issues
show
Documentation introduced by
$lexer is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Egulias\EmailValidator\EmailLexer>.

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...
74
        $this->assertEquals($expectedResult, $multipleValidation->getWarnings());
75
    }
76
77 View Code Duplication
    public function testGathersAllTheErrors()
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...
78
    {
79
        $error1 = new CommaInDomain();
80
        $error2 = new NoDomainPart();
81
82
        $expectedResult = new MultipleErrors([$error1, $error2]);
83
84
        $lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
85
86
        $validation1 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
87
        $validation1->expects($this->once())->method("isValid")->willReturn(false);
88
        $validation1->expects($this->once())->method("getWarnings")->willReturn([]);
89
        $validation1->expects($this->once())->method("getError")->willReturn($error1);
90
91
        $validation2 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
92
        $validation2->expects($this->once())->method("isValid")->willReturn(false);
93
        $validation2->expects($this->once())->method("getWarnings")->willReturn([]);
94
        $validation2->expects($this->once())->method("getError")->willReturn($error2);
95
96
        $multipleValidation = new MultipleValidationWithAnd([$validation1, $validation2]);
0 ignored issues
show
Documentation introduced by
array($validation1, $validation2) is of type array<integer,object<PHP...kObject\\MockObject>"}>, but the function expects a array<integer,object<Egu...ation\EmailValidation>>.

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...
97
        $multipleValidation->isValid("[email protected]", $lexer);
0 ignored issues
show
Documentation introduced by
$lexer is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Egulias\EmailValidator\EmailLexer>.

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...
98
        $this->assertEquals($expectedResult, $multipleValidation->getError());
99
    }
100
101 View Code Duplication
    public function testStopsAfterFirstError()
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...
102
    {
103
        $error1 = new CommaInDomain();
104
        $error2 = new NoDomainPart();
105
106
        $expectedResult = new MultipleErrors([$error1]);
107
108
        $lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
109
110
        $validation1 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
111
        $validation1->expects($this->any())->method("isValid")->willReturn(false);
112
        $validation1->expects($this->once())->method("getWarnings")->willReturn([]);
113
        $validation1->expects($this->once())->method("getError")->willReturn($error1);
114
115
        $validation2 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
116
        $validation2->expects($this->any())->method("isValid")->willReturn(false);
117
        $validation2->expects($this->never())->method("getWarnings")->willReturn([]);
118
        $validation2->expects($this->never())->method("getError")->willReturn($error2);
119
120
        $multipleValidation = new MultipleValidationWithAnd([$validation1, $validation2], MultipleValidationWithAnd::STOP_ON_ERROR);
0 ignored issues
show
Documentation introduced by
array($validation1, $validation2) is of type array<integer,object<PHP...kObject\\MockObject>"}>, but the function expects a array<integer,object<Egu...ation\EmailValidation>>.

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...
121
        $multipleValidation->isValid("[email protected]", $lexer);
0 ignored issues
show
Documentation introduced by
$lexer is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Egulias\EmailValidator\EmailLexer>.

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...
122
        $this->assertEquals($expectedResult, $multipleValidation->getError());
123
    }
124
125
    public function testBreakOutOfLoopWhenError()
126
    {
127
        $error = new CommaInDomain();
128
129
        $expectedResult = new MultipleErrors([$error]);
130
131
        $lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
132
133
        $validation1 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
134
        $validation1->expects($this->any())->method("isValid")->willReturn(false);
135
        $validation1->expects($this->once())->method("getWarnings")->willReturn([]);
136
        $validation1->expects($this->once())->method("getError")->willReturn($error);
137
138
        $validation2 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
139
        $validation2->expects($this->never())->method("isValid");
140
        $validation2->expects($this->never())->method("getWarnings");
141
        $validation2->expects($this->never())->method("getError");
142
143
        $multipleValidation = new MultipleValidationWithAnd([$validation1, $validation2], MultipleValidationWithAnd::STOP_ON_ERROR);
0 ignored issues
show
Documentation introduced by
array($validation1, $validation2) is of type array<integer,object<PHP...kObject\\MockObject>"}>, but the function expects a array<integer,object<Egu...ation\EmailValidation>>.

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...
144
        $multipleValidation->isValid("[email protected]", $lexer);
0 ignored issues
show
Documentation introduced by
$lexer is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Egulias\EmailValidator\EmailLexer>.

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...
145
        $this->assertEquals($expectedResult, $multipleValidation->getError());
146
    }
147
148
    public function testBreakoutOnInvalidEmail()
149
    {
150
        $lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
151
152
        $validationNotCalled = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
153
        $validationNotCalled->expects($this->never())->method("isValid");
154
        $validationNotCalled->expects($this->never())->method("getWarnings");
155
        $validationNotCalled->expects($this->never())->method("getError");
156
        $multipleValidation = new MultipleValidationWithAnd([new RFCValidation(), $validationNotCalled], MultipleValidationWithAnd::STOP_ON_ERROR);
0 ignored issues
show
Documentation introduced by
array(new \Egulias\Email..., $validationNotCalled) is of type array<integer,object<Egu...kObject\\MockObject>"}>, but the function expects a array<integer,object<Egu...ation\EmailValidation>>.

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...
157
        $this->assertFalse($multipleValidation->isValid("invalid-email", $lexer));
0 ignored issues
show
Documentation introduced by
$lexer is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Egulias\EmailValidator\EmailLexer>.

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...
158
    }
159
}
160