|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Spiral, Core Components |
|
5
|
|
|
* |
|
6
|
|
|
* @author Wolfy-J |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Spiral\Tests\Tokenizer; |
|
10
|
|
|
|
|
11
|
|
|
use PHPUnit\Framework\TestCase; |
|
12
|
|
|
use Spiral\Tokenizer\Reflection\ReflectionArgument; |
|
13
|
|
|
use Spiral\Tokenizer\Reflection\ReflectionFile; |
|
14
|
|
|
|
|
15
|
|
|
class ReflectionFileTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
public function testReflection() |
|
18
|
|
|
{ |
|
19
|
|
|
$reflection = new ReflectionFile(__FILE__); |
|
20
|
|
|
|
|
21
|
|
|
$this->assertContains(self::class, $reflection->getClasses()); |
|
22
|
|
|
$this->assertContains(TestTrait::class, $reflection->getTraits()); |
|
23
|
|
|
$this->assertContains(TestInterface::class, $reflection->getInterfaces()); |
|
24
|
|
|
|
|
25
|
|
|
$this->assertSame([__NAMESPACE__ . '\hello'], $reflection->getFunctions()); |
|
26
|
|
|
|
|
27
|
|
|
$functionA = null; |
|
28
|
|
|
$functionB = null; |
|
29
|
|
|
|
|
30
|
|
|
foreach ($reflection->getInvocations() as $invocation) { |
|
31
|
|
|
if ($invocation->getName() == 'test_function_a') { |
|
32
|
|
|
$functionA = $invocation; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
if ($invocation->getName() == 'test_function_b') { |
|
36
|
|
|
$functionB = $invocation; |
|
37
|
|
|
} |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
$this->assertNotEmpty($functionA); |
|
41
|
|
|
$this->assertNotEmpty($functionB); |
|
42
|
|
|
|
|
43
|
|
|
$this->assertSame(2, count($functionA->getArguments())); |
|
44
|
|
|
$this->assertSame(ReflectionArgument::VARIABLE, $functionA->getArgument(0)->getType()); |
|
45
|
|
|
$this->assertSame('$this', $functionA->getArgument(0)->getValue()); |
|
46
|
|
|
|
|
47
|
|
|
$this->assertSame(ReflectionArgument::EXPRESSION, $functionA->getArgument(1)->getType()); |
|
48
|
|
|
$this->assertSame('$a+$b', $functionA->getArgument(1)->getValue()); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertSame(2, $functionB->countArguments()); |
|
51
|
|
|
|
|
52
|
|
|
$this->assertSame(ReflectionArgument::STRING, $functionB->getArgument(0)->getType()); |
|
53
|
|
|
$this->assertSame('"string"', $functionB->getArgument(0)->getValue()); |
|
54
|
|
|
$this->assertSame('string', $functionB->getArgument(0)->stringValue()); |
|
55
|
|
|
|
|
56
|
|
|
$this->assertSame(ReflectionArgument::CONSTANT, $functionB->getArgument(1)->getType()); |
|
57
|
|
|
$this->assertSame('123', $functionB->getArgument(1)->getValue()); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
private function deadend() |
|
61
|
|
|
{ |
|
62
|
|
|
$a = $b = null; |
|
63
|
|
|
test_function_a($this, $a + $b); |
|
64
|
|
|
test_function_b("string", 123); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
function hello() |
|
69
|
|
|
{ |
|
70
|
|
|
} |
|
71
|
|
|
// phpcs:disable |
|
72
|
|
|
trait TestTrait |
|
73
|
|
|
{ |
|
74
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
interface TestInterface |
|
78
|
|
|
{ |
|
79
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|