|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace ApiGen\Parser\Tests\Broker; |
|
4
|
|
|
|
|
5
|
|
|
use ApiGen\Contracts\Configuration\ConfigurationInterface; |
|
6
|
|
|
use ApiGen\Contracts\Parser\Broker\BackendInterface; |
|
7
|
|
|
use ApiGen\Contracts\Parser\ParserStorageInterface; |
|
8
|
|
|
use ApiGen\Contracts\Parser\Reflection\ClassReflectionInterface; |
|
9
|
|
|
use ApiGen\Contracts\Parser\Reflection\FunctionReflectionInterface; |
|
10
|
|
|
use ApiGen\Contracts\Parser\Reflection\TokenReflection\ReflectionFactoryInterface; |
|
11
|
|
|
use ApiGen\Parser\Broker\Backend; |
|
12
|
|
|
use ApiGen\Parser\Reflection\TokenReflection\ReflectionFactory; |
|
13
|
|
|
use PHPUnit\Framework\Assert; |
|
14
|
|
|
use PHPUnit\Framework\TestCase; |
|
15
|
|
|
use TokenReflection\Broker; |
|
16
|
|
|
|
|
17
|
|
|
final class BackendTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var BackendInterface |
|
21
|
|
|
*/ |
|
22
|
|
|
private $backend; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var Broker |
|
26
|
|
|
*/ |
|
27
|
|
|
private $broker; |
|
28
|
|
|
|
|
29
|
|
|
protected function setUp(): void |
|
30
|
|
|
{ |
|
31
|
|
|
$this->backend = new Backend($this->getReflectionFactory()); |
|
32
|
|
|
$this->broker = new Broker($this->backend); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
View Code Duplication |
public function testGetClasses(): void |
|
|
|
|
|
|
36
|
|
|
{ |
|
37
|
|
|
$this->broker->processDirectory(__DIR__ . '/BackendSource'); |
|
38
|
|
|
$classes = $this->backend->getClasses(); |
|
39
|
|
|
$this->assertCount(1, $classes); |
|
40
|
|
|
|
|
41
|
|
|
$class = array_pop($classes); |
|
42
|
|
|
$this->assertInstanceOf(ClassReflectionInterface::class, $class); |
|
43
|
|
|
|
|
44
|
|
|
$this->checkLoadedProperties($class); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
View Code Duplication |
public function testGetFunctions(): void |
|
|
|
|
|
|
48
|
|
|
{ |
|
49
|
|
|
$this->broker->processDirectory(__DIR__ . '/BackendSource'); |
|
50
|
|
|
$functions = $this->backend->getFunctions(); |
|
51
|
|
|
$this->assertCount(1, $functions); |
|
52
|
|
|
|
|
53
|
|
|
$function = array_pop($functions); |
|
54
|
|
|
$this->assertInstanceOf(FunctionReflectionInterface::class, $function); |
|
55
|
|
|
|
|
56
|
|
|
$this->checkLoadedProperties($function); |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
View Code Duplication |
public function testGetConstants(): void |
|
|
|
|
|
|
60
|
|
|
{ |
|
61
|
|
|
$this->broker->processDirectory(__DIR__ . '/BackendSource'); |
|
62
|
|
|
$constants = $this->backend->getConstants(); |
|
63
|
|
|
$this->assertCount(1, $constants); |
|
64
|
|
|
|
|
65
|
|
|
$constant = array_pop($constants); |
|
66
|
|
|
$this->assertInstanceOf('ApiGen\Parser\Reflection\ReflectionConstant', $constant); |
|
67
|
|
|
|
|
68
|
|
|
$this->checkLoadedProperties($constant); |
|
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param object $object |
|
73
|
|
|
*/ |
|
74
|
|
View Code Duplication |
private function checkLoadedProperties($object): void |
|
|
|
|
|
|
75
|
|
|
{ |
|
76
|
|
|
$this->assertInstanceOf( |
|
77
|
|
|
ConfigurationInterface::class, |
|
78
|
|
|
Assert::getObjectAttribute($object, 'configuration') |
|
79
|
|
|
); |
|
80
|
|
|
|
|
81
|
|
|
$this->assertInstanceOf( |
|
82
|
|
|
ParserStorageInterface::class, |
|
83
|
|
|
Assert::getObjectAttribute($object, 'parserStorage') |
|
84
|
|
|
); |
|
85
|
|
|
|
|
86
|
|
|
$this->assertInstanceOf( |
|
87
|
|
|
ReflectionFactoryInterface::class, |
|
88
|
|
|
Assert::getObjectAttribute($object, 'reflectionFactory') |
|
89
|
|
|
); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
View Code Duplication |
private function getReflectionFactory(): ReflectionFactory |
|
|
|
|
|
|
93
|
|
|
{ |
|
94
|
|
|
$parserStoragetMock = $this->createMock(ParserStorageInterface::class); |
|
95
|
|
|
$configurationMock = $this->createMock(ConfigurationInterface::class); |
|
96
|
|
|
$configurationMock->method('getVisibilityLevel') |
|
97
|
|
|
->willReturn(1); |
|
98
|
|
|
|
|
99
|
|
|
return new ReflectionFactory($configurationMock, $parserStoragetMock); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.