Test Failed
Pull Request — master (#179)
by
unknown
02:08
created

testEmptyListIsNotAllowed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
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\Exception\CommaInDomain;
6
use Egulias\EmailValidator\Exception\NoDomainPart;
7
use Egulias\EmailValidator\Validation\MultipleErrors;
8
use Egulias\EmailValidator\Validation\MultipleValidationWithAnd;
9
use Egulias\EmailValidator\Warning\AddressLiteral;
10
use Egulias\EmailValidator\Warning\DomainLiteral;
11
use PHPUnit\Framework\TestCase;
12
13
class MultipleValidationWithAndTest extends TestCase
14
{
15
    public function testUsesAndLogicalOperation()
16
    {
17
        $lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
18
        $validationTrue = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
19
        $validationTrue->expects($this->any())->method("isValid")->willReturn(true);
20
        $validationTrue->expects($this->any())->method("getWarnings")->willReturn([]);
21
        $validationFalse = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
22
        $validationFalse->expects($this->any())->method("isValid")->willReturn(false);
23
        $validationFalse->expects($this->any())->method("getWarnings")->willReturn([]);
24
        $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...
25
        $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...
26
    }
27
28
    /**
29
     * @expectedException \Egulias\EmailValidator\Validation\Exception\EmptyValidationList
30
     */
31
    public function testEmptyListIsNotAllowed()
32
    {
33
        new MultipleValidationWithAnd([]);
34
    }
35
36 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...
37
    {
38
        $lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
39
40
        $validation = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
41
        $validation->expects($this->any())->method("isValid")->willReturn(true);
42
        $validation->expects($this->once())->method("getWarnings")->willReturn([]);
43
44
        $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...
45
        $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...
46
        $this->assertNull($multipleValidation->getError());
47
    }
48
49
    public function testAccumulatesWarnings()
50
    {
51
        $warnings1 = [
52
            AddressLiteral::CODE => new AddressLiteral()
53
        ];
54
        $warnings2 = [
55
            DomainLiteral::CODE => new DomainLiteral()
56
        ];
57
        $expectedResult = array_merge($warnings1, $warnings2);
58
59
        $lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
60
        $validation1 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
61
        $validation1->expects($this->any())->method("isValid")->willReturn(true);
62
        $validation1->expects($this->once())->method("getWarnings")->willReturn($warnings1);
63
64
        $validation2 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
65
66
        $validation2->expects($this->any())->method("isValid")->willReturn(false);
67
        $validation2->expects($this->once())->method("getWarnings")->willReturn($warnings2);
68
69
        $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...
70
        $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...
71
        $this->assertEquals($expectedResult, $multipleValidation->getWarnings());
72
    }
73
74 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...
75
    {
76
        $error1 = new CommaInDomain();
77
        $error2 = new NoDomainPart();
78
79
        $expectedResult = new MultipleErrors([$error1, $error2]);
80
81
        $lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
82
83
        $validation1 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
84
        $validation1->expects($this->any())->method("isValid")->willReturn(true);
85
        $validation1->expects($this->once())->method("getWarnings")->willReturn([]);
86
        $validation1->expects($this->once())->method("getError")->willReturn($error1);
87
88
        $validation2 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
89
        $validation2->expects($this->any())->method("isValid")->willReturn(false);
90
        $validation2->expects($this->once())->method("getWarnings")->willReturn([]);
91
        $validation2->expects($this->once())->method("getError")->willReturn($error2);
92
93
        $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...
94
        $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...
95
        $this->assertEquals($expectedResult, $multipleValidation->getError());
96
    }
97
98 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...
99
    {
100
        $error1 = new CommaInDomain();
101
        $error2 = new NoDomainPart();
102
103
        $expectedResult = new MultipleErrors([$error1]);
104
105
        $lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
106
107
        $validation1 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
108
        $validation1->expects($this->any())->method("isValid")->willReturn(true);
109
        $validation1->expects($this->once())->method("getWarnings")->willReturn([]);
110
        $validation1->expects($this->once())->method("getError")->willReturn($error1);
111
112
        $validation2 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
113
        $validation2->expects($this->any())->method("isValid")->willReturn(false);
114
        $validation2->expects($this->once())->method("getWarnings")->willReturn([]);
115
        $validation2->expects($this->once())->method("getError")->willReturn($error2);
116
117
        $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...
118
        $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...
119
        $this->assertEquals($expectedResult, $multipleValidation->getError());
120
    }
121
122
    public function testBreakOutOfLoopWhenError()
123
    {
124
        $error = new CommaInDomain();
125
126
        $expectedResult = new MultipleErrors([$error]);
127
128
        $lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock();
129
130
        $validation1 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
131
        $validation1->expects($this->any())->method("isValid")->willReturn(false);
132
        $validation1->expects($this->once())->method("getWarnings")->willReturn([]);
133
        $validation1->expects($this->once())->method("getError")->willReturn($error);
134
135
        $validation2 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
136
        $validation2->expects($this->never())->method("isValid");
137
        $validation2->expects($this->never())->method("getWarnings");
138
        $validation2->expects($this->never())->method("getError");
139
140
        $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...
141
        $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...
142
        $this->assertEquals($expectedResult, $multipleValidation->getError());
143
    }
144
}
145