These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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
|
|||
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
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
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
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
Loading history...
|
|||
43 | } |
||
44 | |||
45 | public function emailAddressProvider() |
||
46 | { |
||
47 | return [ |
||
48 | ['abc', false], |
||
49 | ['[email protected]', '[email protected]'], |
||
50 | ['test@local', false], |
||
51 | ]; |
||
52 | } |
||
53 | |||
54 | View Code Duplication | public function internalLinkProvider() |
|
0 ignored issues
–
show
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
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 |
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:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: