|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace ApiGen\Tests\Templating\Filters; |
|
4
|
|
|
|
|
5
|
|
|
use ApiGen\Templating\Filters\Filters; |
|
6
|
|
|
use ApiGen\Tests\MethodInvoker; |
|
7
|
|
|
use ApiGen\Tests\Templating\Filters\FiltersSource\FooFilters; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
|
|
10
|
|
|
final class FiltersTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var Filters |
|
14
|
|
|
*/ |
|
15
|
|
|
private $filters; |
|
16
|
|
|
|
|
17
|
|
|
protected function setUp(): void |
|
18
|
|
|
{ |
|
19
|
|
|
$this->filters = new FooFilters; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function testLoader(): void |
|
23
|
|
|
{ |
|
24
|
|
|
$this->assertSame('Filtered: foo', $this->filters->loader('bazFilter', 'foo')); |
|
25
|
|
|
$this->assertNull($this->filters->loader('nonExisting')); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @dataProvider typeNameProvider() |
|
30
|
|
|
*/ |
|
31
|
|
|
public function testGetTypeName(string $name, string $expectedName): void |
|
32
|
|
|
{ |
|
33
|
|
|
$this->assertSame( |
|
34
|
|
|
$expectedName, |
|
35
|
|
|
MethodInvoker::callMethodOnObject($this->filters, 'getTypeName', [$name]) |
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @return string[] |
|
41
|
|
|
*/ |
|
42
|
|
|
public function typeNameProvider(): array |
|
43
|
|
|
{ |
|
44
|
|
|
return [ |
|
45
|
|
|
['bool', 'boolean'], |
|
46
|
|
|
['double', 'float'], |
|
47
|
|
|
['void', ''], |
|
48
|
|
|
['FALSE', 'false'], |
|
49
|
|
|
['TRUE', 'true'], |
|
50
|
|
|
['NULL', 'null'], |
|
51
|
|
|
['callback', 'callable'], |
|
52
|
|
|
['integer', 'integer'], |
|
53
|
|
|
['boolean', 'boolean'], |
|
54
|
|
|
['My\\Class', 'My\\Class'], |
|
55
|
|
|
['\\My\\Class', 'My\\Class'] |
|
56
|
|
|
]; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function testGetTypeNameWithTrimOff(): void |
|
60
|
|
|
{ |
|
61
|
|
|
$this->assertSame( |
|
62
|
|
|
'\\Namespace', |
|
63
|
|
|
MethodInvoker::callMethodOnObject($this->filters, 'getTypeName', ['\\Namespace', false]) |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function testUrlize(): void |
|
68
|
|
|
{ |
|
69
|
|
|
$this->assertSame( |
|
70
|
|
|
'Some.class', |
|
71
|
|
|
MethodInvoker::callMethodOnObject($this->filters, 'urlize', ['Some class']) |
|
72
|
|
|
); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
public function testUrl(): void |
|
76
|
|
|
{ |
|
77
|
|
|
$this->assertSame( |
|
78
|
|
|
'Some%20class', |
|
79
|
|
|
MethodInvoker::callMethodOnObject($this->filters, 'url', ['Some class']) |
|
80
|
|
|
); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|