|
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)); |
|
|
|
|
|
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @dataProvider internalLinkProvider |
|
31
|
|
|
*/ |
|
32
|
|
|
public function testIsInternalLink($link, $result) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->assertSame($result, $this->validatorMock->isInternalLink($link)); |
|
|
|
|
|
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @dataProvider internalMediaLinkProvider |
|
39
|
|
|
*/ |
|
40
|
|
|
public function testIsInternalMediaLink($link, $result) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->assertSame($result, $this->validatorMock->isInternalMediaLink($link)); |
|
|
|
|
|
|
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() |
|
|
|
|
|
|
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() |
|
|
|
|
|
|
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: