Completed
Push — 3.0.0-dev ( 34d49c...6abede )
by Eduardo Gulias
02:52 queued 01:22
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
    public function testMultipleValidation()
29
    {
30
        $validator = new EmailValidator();
31
        $validation = $this->getMockBuilder(EmailValidation::class)->getMock();
32
        $validation->expects($this->once())->method("isValid")->willReturn(true);
33
        $validation->expects($this->once())->method("getWarnings")->willReturn([]);
34
        $validation->expects($this->never(2))->method("getError");
0 ignored issues
show
Unused Code introduced by
The call to EmailValidatorTest::never() has too many arguments starting with 2.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
35
        $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...
36
37
        $this->assertTrue($validator->isValid("[email protected]", $multiple));
38
    }
39
40 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...
41
    {
42
        $invalidEmail = new InvalidEmail(new DummyReason(), '');
43
        $validator = new EmailValidator();
44
        $validation = $this->getMockBuilder(EmailValidation::class)->getMock();
45
        $validation->expects($this->once())->method("isValid")->willReturn(false);
46
        $validation->expects($this->once())->method("getWarnings")->willReturn([]);
47
        $validation->expects($this->once())->method("getError")->willReturn($invalidEmail);
48
49
        $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...
50
    }
51
}
52