Test Setup Failed
Push — parse-domain-literal ( 97f1d2...01bc94 )
by Eduardo Gulias
01:46
created

EmailValidatorTest::testValidationIsFalse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
dl 11
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Egulias\Tests\EmailValidator;
4
5
use Egulias\EmailValidator\EmailValidator;
6
use Egulias\EmailValidator\Result\InvalidEmail;
7
use Egulias\EmailValidator\Validation\EmailValidation;
8
use Egulias\EmailValidator\Validation\MultipleValidationWithAnd;
9
use Egulias\Tests\EmailValidator\Dummy\DummyReason;
10
use PHPUnit\Framework\TestCase;
11
12
class EmailValidatorTest extends TestCase
13
{
14
15
16 View Code Duplication
    public function testValidationIsUsed()
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...
17
    {
18
        $invalidEmail = new InvalidEmail(new DummyReason(), '');
19
        $validator = new EmailValidator();
20
        $validation = $this->getMockBuilder(EmailValidation::class)->getMock();
21
        $validation->expects($this->once())->method("isValid")->willReturn(true);
22
        $validation->expects($this->once())->method("getWarnings")->willReturn([]);
23
        $validation->expects($this->once())->method("getError")->willReturn($invalidEmail);
24
25
        $this->assertTrue($validator->isValid("[email protected]", $validation));
0 ignored issues
show
Documentation introduced by
$validation is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Egulias\EmailVali...dation\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...
26
    }
27
28 View Code Duplication
    public function testMultipleValidation()
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...
29
    {
30
        $invalidEmail = new InvalidEmail(new DummyReason(), '');
31
        $validator = new EmailValidator();
32
        $validation = $this->getMockBuilder(EmailValidation::class)->getMock();
33
        $validation->expects($this->once())->method("isValid")->willReturn(true);
34
        $validation->expects($this->once())->method("getWarnings")->willReturn([]);
35
        $validation->expects($this->exactly(2))->method("getError")->willReturn($invalidEmail);
36
        $multiple = 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...
37
38
        $this->assertTrue($validator->isValid("[email protected]", $multiple));
39
    }
40
41 View Code Duplication
    public function testValidationIsFalse()
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...
42
    {
43
        $invalidEmail = new InvalidEmail(new DummyReason(), '');
44
        $validator = new EmailValidator();
45
        $validation = $this->getMockBuilder(EmailValidation::class)->getMock();
46
        $validation->expects($this->once())->method("isValid")->willReturn(false);
47
        $validation->expects($this->once())->method("getWarnings")->willReturn([]);
48
        $validation->expects($this->once())->method("getError")->willReturn($invalidEmail);
49
50
        $this->assertFalse($validator->isValid("[email protected]", $validation));
0 ignored issues
show
Documentation introduced by
$validation is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Egulias\EmailVali...dation\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...
51
    }
52
}
53