|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types = 1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Tests; |
|
6
|
|
|
|
|
7
|
|
|
use \PHPUnit\Framework\TestCase; |
|
8
|
|
|
|
|
9
|
|
|
use \Reflection\ReflectionUseStatements; |
|
10
|
|
|
use \Reflection\UseStatements; |
|
11
|
|
|
use \Reflection\UseStatement; |
|
12
|
|
|
|
|
13
|
|
|
use \Tests\Dummy\Tree; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class ClassUseStatementsTest |
|
17
|
|
|
* @package Tests |
|
18
|
|
|
*/ |
|
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('\Tests\Dummy\Branch', 'BranchClass')) |
|
29
|
|
|
->add(new UseStatement('\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('\Tests\Dummy\Branch')); |
|
37
|
|
|
$this->assertTrue($reflection->hasUseStatement('BranchClass')); |
|
38
|
|
|
$this->assertTrue($reflection->hasUseStatement('\Tests\Dummy\Leaf')); |
|
39
|
|
|
$this->assertTrue($reflection->hasUseStatement('Leaf')); |
|
40
|
|
|
$this->assertFalse($reflection->hasUseStatement('LeafClass')); |
|
41
|
|
|
|
|
42
|
|
|
$this->assertNull($reflection->getUseStatements()->getClass('LeafClass')); |
|
43
|
|
|
$this->assertEquals( |
|
44
|
|
|
$reflection->getUseStatements()->getClass('BranchClass'), |
|
45
|
|
|
new UseStatement('\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
|
|
|
} |