Completed
Push — master ( a87692...4e64ba )
by Ruud
81:47 queued 68:42
created

UrlValidatorTest::testIsEmailAddress()   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 2
1
<?php
2
3
namespace Kunstmaan\NodeBundle\Tests\Helper;
4
5
use Kunstmaan\NodeBundle\Validation\URLValidator;
6
use PHPUnit\Framework\MockObject\MockObject;
7
use PHPUnit\Framework\TestCase;
8
9
class UrlValidatorTest extends TestCase
10
{
11
    /**
12
     * @var URLValidator|MockObject
13
     */
14
    private $validatorMock;
15
16
    protected function setUp()
17
    {
18
        $this->validatorMock = $this->getMockForTrait(URLValidator::class);
19
    }
20
21
    /**
22
     * @dataProvider emailAddressProvider
23
     */
24
    public function testIsEmailAddress($email, $result)
25
    {
26
        $this->assertSame($result, $this->validatorMock->isEmailAddress($email));
0 ignored issues
show
Bug introduced by Jeroen Thora
The method isEmailAddress does only exist in Kunstmaan\NodeBundle\Validation\URLValidator, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
27
    }
28
29
    /**
30
     * @dataProvider internalLinkProvider
31
     */
32
    public function testIsInternalLink($link, $result)
33
    {
34
        $this->assertSame($result, $this->validatorMock->isInternalLink($link));
0 ignored issues
show
Bug introduced by Jeroen Thora
The method isInternalLink does only exist in Kunstmaan\NodeBundle\Validation\URLValidator, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
35
    }
36
37
    /**
38
     * @dataProvider internalMediaLinkProvider
39
     */
40
    public function testIsInternalMediaLink($link, $result)
41
    {
42
        $this->assertSame($result, $this->validatorMock->isInternalMediaLink($link));
0 ignored issues
show
Bug introduced by Jeroen Thora
The method isInternalMediaLink does only exist in Kunstmaan\NodeBundle\Validation\URLValidator, but not in PHPUnit\Framework\MockObject\MockObject.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
43
    }
44
45
    public function emailAddressProvider()
46
    {
47
        return [
48
            ['abc', false],
49
            ['[email protected]', '[email protected]'],
50
            ['[email protected]', false],
51
        ];
52
    }
53
54 View Code Duplication
    public function internalLinkProvider()
0 ignored issues
show
Duplication introduced by Jeroen Thora
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...
55
    {
56
        return [
57
            ['[NT:123]', false],
58
            ['[NT123]', true],
59
            ['[NTABC]', false],
60
            ['[NT123ABC]', false],
61
            ['[host_a:NT123]', true],
62
            ['http://www.google.com', false],
63
            ['[NT123][M20]', true],
64
        ];
65
    }
66
67 View Code Duplication
    public function internalMediaLinkProvider()
0 ignored issues
show
Duplication introduced by Jeroen Thora
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...
68
    {
69
        return [
70
            ['[M:123]', false],
71
            ['[M123]', true],
72
            ['[MABC]', false],
73
            ['[M123ABC]', false],
74
            ['[host_a:M23]', true],
75
            ['http://www.google.com', false],
76
            ['[M123][NT20]', true],
77
        ];
78
    }
79
}
80