|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace ApiGen\Parser\Tests\Reflection\ReflectionClass; |
|
4
|
|
|
|
|
5
|
|
|
use ApiGen\Contracts\Configuration\ConfigurationInterface; |
|
6
|
|
|
use ApiGen\Contracts\Parser\ParserStorageInterface; |
|
7
|
|
|
use ApiGen\Contracts\Parser\Reflection\TokenReflection\ReflectionFactoryInterface; |
|
8
|
|
|
use ApiGen\Parser\Broker\Backend; |
|
9
|
|
|
use ApiGen\Parser\Reflection\ReflectionClass; |
|
10
|
|
|
use ApiGen\Parser\Reflection\TokenReflection\ReflectionFactory; |
|
11
|
|
|
use PHPUnit\Framework\TestCase; |
|
12
|
|
|
use ReflectionProperty; |
|
13
|
|
|
use TokenReflection\Broker; |
|
14
|
|
|
|
|
15
|
|
|
abstract class AbstractReflectionClassTestCase extends TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var ReflectionClass |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $reflectionClass; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @var ReflectionClass |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $reflectionClassOfParent; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var ReflectionClass |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $reflectionClassOfTrait; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var ReflectionClass |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $reflectionClassOfInterface; |
|
36
|
|
|
|
|
37
|
|
|
protected function setUp(): void |
|
38
|
|
|
{ |
|
39
|
|
|
$backend = new Backend($this->getReflectionFactory()); |
|
40
|
|
|
$broker = new Broker($backend); |
|
41
|
|
|
$broker->processDirectory(__DIR__ . '/../ReflectionClassSource'); |
|
42
|
|
|
$this->reflectionClass = $backend->getClasses()['Project\AccessLevels']; |
|
|
|
|
|
|
43
|
|
|
$this->reflectionClassOfParent = $backend->getClasses()['Project\ParentClass']; |
|
|
|
|
|
|
44
|
|
|
$this->reflectionClassOfTrait = $backend->getClasses()['Project\SomeTrait']; |
|
|
|
|
|
|
45
|
|
|
$this->reflectionClassOfInterface = $backend->getClasses()['Project\RichInterface']; |
|
|
|
|
|
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
private function getReflectionFactory(): ReflectionFactoryInterface |
|
49
|
|
|
{ |
|
50
|
|
|
// @todo: use $parserStorage from DI |
|
51
|
|
|
$parserStorageMock = $this->createMock(ParserStorageInterface::class); |
|
52
|
|
|
$parserStorageMock->method('getDirectImplementersOfInterface')->willReturn([1]); |
|
53
|
|
|
$parserStorageMock->method('getIndirectImplementersOfInterface')->willReturn([]); |
|
54
|
|
|
$parserStorageMock->method('getElementsByType')->willReturnCallback(function ($arg) { |
|
55
|
|
|
if ($arg) { |
|
56
|
|
|
return [ |
|
57
|
|
|
'Project\AccessLevels' => $this->reflectionClass, |
|
58
|
|
|
'Project\ParentClass' => $this->reflectionClassOfParent, |
|
59
|
|
|
'Project\SomeTrait' => $this->reflectionClassOfTrait, |
|
60
|
|
|
'Project\RichInterface' => $this->reflectionClassOfInterface |
|
61
|
|
|
]; |
|
62
|
|
|
} |
|
63
|
|
|
}); |
|
64
|
|
|
|
|
65
|
|
|
$configurationMock = $this->createMock(ConfigurationInterface::class); |
|
66
|
|
|
$configurationMock->method('getVisibilityLevel') |
|
67
|
|
|
->willReturn(ReflectionProperty::IS_PUBLIC | ReflectionProperty::IS_PROTECTED); |
|
68
|
|
|
|
|
69
|
|
|
return new ReflectionFactory($configurationMock, $parserStorageMock); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.