|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace FinalizerTest\Constraint; |
|
4
|
|
|
|
|
5
|
|
|
use Finalizer\Constraint\IsFinalizable; |
|
6
|
|
|
use FinalizerTestAsset\Finalizable; |
|
7
|
|
|
use FinalizerTestAsset\NonFinalizable; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @covers \Finalizer\Constraint\IsFinalizable |
|
12
|
|
|
*/ |
|
13
|
|
|
class IsFinalizableTest extends TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @dataProvider finalizableClassesProvider |
|
17
|
|
|
* |
|
18
|
|
|
* @param string $className |
|
19
|
|
|
* @param string[] $definedClasses |
|
20
|
|
|
*/ |
|
21
|
|
|
public function testIsFinalizable($className, array $definedClasses) |
|
22
|
|
|
{ |
|
23
|
|
|
$finalizable = false === strpos($className, 'NonFinalizable'); |
|
24
|
|
|
|
|
25
|
|
|
$this->assertSame( |
|
26
|
|
|
$finalizable, |
|
27
|
|
|
(new IsFinalizable()) |
|
28
|
|
|
->__invoke( |
|
29
|
|
|
new \ReflectionClass($className), |
|
30
|
|
|
...array_map( |
|
31
|
|
|
function ($className) { |
|
32
|
|
|
return new \ReflectionClass($className); |
|
33
|
|
|
}, |
|
34
|
|
|
$definedClasses |
|
35
|
|
|
) |
|
36
|
|
|
) |
|
37
|
|
|
); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @return \ReflectionClass[][]|\ReflectionClass[][][] |
|
42
|
|
|
*/ |
|
43
|
|
|
public function finalizableClassesProvider() |
|
44
|
|
|
{ |
|
45
|
|
|
return [ |
|
46
|
|
|
NonFinalizable\EmptyParentClass::class => [ |
|
47
|
|
|
NonFinalizable\EmptyParentClass::class, |
|
48
|
|
|
[ |
|
49
|
|
|
Finalizable\EmptyChildClass::class, |
|
50
|
|
|
], |
|
51
|
|
|
], |
|
52
|
|
|
Finalizable\EmptyChildClass::class => [ |
|
53
|
|
|
Finalizable\EmptyChildClass::class, |
|
54
|
|
|
[], |
|
55
|
|
|
], |
|
56
|
|
|
NonFinalizable\ClassWithNoMethods::class => [ |
|
57
|
|
|
NonFinalizable\ClassWithNoMethods::class, |
|
58
|
|
|
[], |
|
59
|
|
|
], |
|
60
|
|
|
Finalizable\ClassWithNoMethods::class => [ |
|
61
|
|
|
Finalizable\ClassWithNoMethods::class, |
|
62
|
|
|
[], |
|
63
|
|
|
], |
|
64
|
|
|
Finalizable\FooMethodClass::class => [ |
|
65
|
|
|
Finalizable\FooMethodClass::class, |
|
66
|
|
|
[], |
|
67
|
|
|
], |
|
68
|
|
|
Finalizable\FooBarMethodClass::class => [ |
|
69
|
|
|
Finalizable\FooBarMethodClass::class, |
|
70
|
|
|
[], |
|
71
|
|
|
], |
|
72
|
|
|
NonFinalizable\FooBarMethodClass::class => [ |
|
73
|
|
|
NonFinalizable\FooBarMethodClass::class, |
|
74
|
|
|
[], |
|
75
|
|
|
], |
|
76
|
|
|
Finalizable\InvokableClass::class => [ |
|
77
|
|
|
Finalizable\InvokableClass::class, |
|
78
|
|
|
[], |
|
79
|
|
|
], |
|
80
|
|
|
NonFinalizable\InvokableClassWithAdditionalMethods::class => [ |
|
81
|
|
|
NonFinalizable\InvokableClassWithAdditionalMethods::class, |
|
82
|
|
|
[], |
|
83
|
|
|
], |
|
84
|
|
|
Finalizable\InvokableClassWithConstructor::class => [ |
|
85
|
|
|
Finalizable\InvokableClassWithConstructor::class, |
|
86
|
|
|
[], |
|
87
|
|
|
], |
|
88
|
|
|
Finalizable\ClassWithConstructor::class => [ |
|
89
|
|
|
Finalizable\ClassWithConstructor::class, |
|
90
|
|
|
[], |
|
91
|
|
|
], |
|
92
|
|
|
Finalizable\FooBarConstructorMethodClass::class => [ |
|
93
|
|
|
Finalizable\FooBarConstructorMethodClass::class, |
|
94
|
|
|
[], |
|
95
|
|
|
], |
|
96
|
|
|
Finalizable\ClassWithPrivateMethod::class => [ |
|
97
|
|
|
Finalizable\ClassWithPrivateMethod::class, |
|
98
|
|
|
[], |
|
99
|
|
|
], |
|
100
|
|
|
Finalizable\ClassWithProtectedMethod::class => [ |
|
101
|
|
|
Finalizable\ClassWithProtectedMethod::class, |
|
102
|
|
|
[], |
|
103
|
|
|
], |
|
104
|
|
|
]; |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|