1 | <?php |
||
19 | class ReflectionUseStatementsTest extends TestCase { |
||
20 | |||
21 | public function testMain() { |
||
22 | $reflection = new ReflectionUseStatements(Tree::class); |
||
23 | |||
24 | $this->assertEquals( |
||
25 | $reflection->getUseStatements(), |
||
26 | (new UseStatements()) |
||
27 | ->add(new UseStatement('\JsonSerializable')) |
||
28 | ->add(new UseStatement('\Reflection\Tests\Dummy\Branch', 'BranchClass')) |
||
29 | ->add(new UseStatement('\Reflection\Tests\Dummy\Leaf')) |
||
30 | ); |
||
31 | |||
32 | $this->assertFalse($reflection->isNotUserDefined()); |
||
33 | |||
34 | $this->assertTrue($reflection->hasUseStatement('\JsonSerializable')); |
||
35 | $this->assertTrue($reflection->hasUseStatement('JsonSerializable')); |
||
36 | $this->assertTrue($reflection->hasUseStatement('\Reflection\Tests\Dummy\Branch')); |
||
37 | $this->assertTrue($reflection->hasUseStatement('BranchClass')); |
||
38 | $this->assertTrue($reflection->hasUseStatement('\Reflection\Tests\Dummy\Leaf')); |
||
39 | $this->assertTrue($reflection->hasUseStatement('Leaf')); |
||
40 | $this->assertFalse($reflection->hasUseStatement('LeafClass')); |
||
41 | |||
42 | $this->assertNull($reflection->getUseStatements()->findUseStatement('LeafClass')); |
||
43 | $this->assertEquals( |
||
44 | $reflection->getUseStatements()->findUseStatement('BranchClass'), |
||
45 | new UseStatement('\Reflection\Tests\Dummy\Branch', 'BranchClass') |
||
46 | ); |
||
47 | |||
48 | $this->expectException('RuntimeException'); |
||
49 | $this->expectExceptionMessage('Can get use statements from user defined classes only.'); |
||
50 | (new ReflectionUseStatements('\JsonSerializable'))->getUseStatements(); |
||
51 | } |
||
52 | |||
53 | } |