1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace RoaveTest\BackwardCompatibility\SourceLocator; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Roave\BackwardCompatibility\SourceLocator\StubClassSourceLocator; |
9
|
|
|
use Roave\BetterReflection\BetterReflection; |
10
|
|
|
use Roave\BetterReflection\Identifier\Identifier; |
11
|
|
|
use Roave\BetterReflection\Identifier\IdentifierType; |
12
|
|
|
use Roave\BetterReflection\Reflection\ReflectionClass; |
13
|
|
|
use Roave\BetterReflection\Reflector\Reflector; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @covers \Roave\BackwardCompatibility\SourceLocator\StubClassSourceLocator |
17
|
|
|
*/ |
18
|
|
|
final class StubClassSourceLocatorTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
/** @var StubClassSourceLocator */ |
21
|
|
|
private $stubLocator; |
22
|
|
|
|
23
|
|
|
/** @var Reflector */ |
24
|
|
|
private $reflector; |
25
|
|
|
|
26
|
|
|
protected function setUp() : void |
27
|
|
|
{ |
28
|
|
|
parent::setUp(); |
29
|
|
|
|
30
|
|
|
$betterReflection = new BetterReflection(); |
31
|
|
|
|
32
|
|
|
$this->stubLocator = new StubClassSourceLocator($betterReflection->astLocator()); |
33
|
|
|
$this->reflector = $betterReflection->classReflector(); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function testWillNotRetrieveSymbolsByType() : void |
37
|
|
|
{ |
38
|
|
|
self::assertEmpty($this->stubLocator->locateIdentifiersByType( |
39
|
|
|
$this->reflector, |
40
|
|
|
new IdentifierType(IdentifierType::IDENTIFIER_CLASS) |
41
|
|
|
)); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testWillNotRetrieveFunctionReflections() : void |
45
|
|
|
{ |
46
|
|
|
self::assertNull($this->stubLocator->locateIdentifier( |
47
|
|
|
$this->reflector, |
48
|
|
|
new Identifier('foo', new IdentifierType(IdentifierType::IDENTIFIER_FUNCTION)) |
49
|
|
|
)); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testWillReflectNonNamespacedClass() : void |
53
|
|
|
{ |
54
|
|
|
/** @var ReflectionClass $class */ |
55
|
|
|
$class = $this->stubLocator->locateIdentifier( |
56
|
|
|
$this->reflector, |
57
|
|
|
new Identifier('AClass', new IdentifierType(IdentifierType::IDENTIFIER_CLASS)) |
58
|
|
|
); |
59
|
|
|
|
60
|
|
|
self::assertInstanceOf(ReflectionClass::class, $class); |
61
|
|
|
|
62
|
|
|
self::assertSame('AClass', $class->getName()); |
63
|
|
|
self::assertTrue($class->isInterface()); |
64
|
|
|
self::assertFalse($class->inNamespace()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testWillReflectNamespacedClass() : void |
68
|
|
|
{ |
69
|
|
|
/** @var ReflectionClass $class */ |
70
|
|
|
$class = $this->stubLocator->locateIdentifier( |
71
|
|
|
$this->reflector, |
72
|
|
|
new Identifier('Foo\Bar\AClass', new IdentifierType(IdentifierType::IDENTIFIER_CLASS)) |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
self::assertInstanceOf(ReflectionClass::class, $class); |
76
|
|
|
|
77
|
|
|
self::assertSame('Foo\Bar\AClass', $class->getName()); |
78
|
|
|
self::assertTrue($class->isInterface()); |
79
|
|
|
self::assertTrue($class->inNamespace()); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|