-
-
Notifications
You must be signed in to change notification settings - Fork 152
Expand file tree
/
Copy pathReflection.getDeclaringMethod.alias.phpt
More file actions
112 lines (81 loc) · 2.11 KB
/
Reflection.getDeclaringMethod.alias.phpt
File metadata and controls
112 lines (81 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* Test: Nette\Utils\Reflection::getDeclaringMethod
*/
declare(strict_types=1);
use Nette\Utils\Reflection;
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
trait A
{
public function foo()
{
}
}
trait B
{
use A {
A::foo as foo2;
}
}
trait B2
{
use A {
A::foo as foo2;
}
public function foo2()
{
}
}
class E1
{
use B {
B::foo2 as alias;
}
}
class E2
{
use B {
B::foo2 as alias;
}
public function foo2()
{
}
public function alias()
{
}
}
class E3
{
use B2 {
B2::foo as foo3;
}
}
function get(ReflectionMethod $m)
{
$res = Reflection::getMethodDeclaringMethod($m);
return $res->getDeclaringClass()->name . '::' . $res->name;
}
// new ReflectionMethod and getMethod returns different method names, PHP #79636
// Method in trait
Assert::same('A::foo', get((new ReflectionClass('E3'))->getMethod('foo3')));
Assert::same('A::foo', get(new ReflectionMethod('E3', 'foo3')));
Assert::same('B2::foo2', get((new ReflectionClass('E3'))->getMethod('foo2')));
Assert::same('B2::foo2', get(new ReflectionMethod('E3', 'foo2')));
Assert::same('A::foo', get((new ReflectionClass('E3'))->getMethod('foo')));
Assert::same('A::foo', get(new ReflectionMethod('E3', 'foo')));
// Method in class
Assert::same('E2::alias', get((new ReflectionClass('E2'))->getMethod('alias')));
Assert::same('E2::alias', get(new ReflectionMethod('E2', 'alias')));
Assert::same('E2::foo2', get((new ReflectionClass('E2'))->getMethod('foo2')));
Assert::same('E2::foo2', get(new ReflectionMethod('E2', 'foo2')));
// Method in trait
Assert::same('A::foo', get((new ReflectionClass('E1'))->getMethod('alias')));
Assert::same('A::foo', get(new ReflectionMethod('E1', 'alias')));
// Method in trait
Assert::same('B2::foo2', get((new ReflectionClass('B2'))->getMethod('foo2')));
Assert::same('B2::foo2', get(new ReflectionMethod('B2', 'foo2')));
Assert::same('A::foo', get((new ReflectionClass('B'))->getMethod('foo2')));
Assert::same('A::foo', get(new ReflectionMethod('B', 'foo2')));
Assert::same('A::foo', get((new ReflectionClass('A'))->getMethod('foo')));
Assert::same('A::foo', get(new ReflectionMethod('A', 'foo')));