1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace ApiGen\Parser\Tests\Elements; |
4
|
|
|
|
5
|
|
|
use ApiGen\Contracts\Parser\Elements\ElementStorageInterface; |
6
|
|
|
use ApiGen\Contracts\Parser\Reflection\ClassReflectionInterface; |
7
|
|
|
use ApiGen\Contracts\Parser\Reflection\ConstantReflectionInterface; |
8
|
|
|
use ApiGen\Contracts\Parser\Reflection\FunctionReflectionInterface; |
9
|
|
|
use ApiGen\Contracts\Parser\Reflection\MethodReflectionInterface; |
10
|
|
|
use ApiGen\Contracts\Parser\Reflection\PropertyReflectionInterface; |
11
|
|
|
use ApiGen\Parser\Elements\AutocompleteElements; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
use PHPUnit_Framework_MockObject_MockObject; |
14
|
|
|
|
15
|
|
|
final class AutocompleteElementsTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var AutocompleteElements |
19
|
|
|
*/ |
20
|
|
|
private $autocompleteElements; |
21
|
|
|
|
22
|
|
|
protected function setUp(): void |
23
|
|
|
{ |
24
|
|
|
$elementsStorageMock = $this->createElementStorageMock(); |
25
|
|
|
$this->autocompleteElements = new AutocompleteElements($elementsStorageMock); |
|
|
|
|
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testGetElementsClasses(): void |
29
|
|
|
{ |
30
|
|
|
$elements = $this->autocompleteElements->getElements(); |
31
|
|
|
$this->assertSame([ |
32
|
|
|
['c', 'ClassPrettyName'], |
33
|
|
|
['p', 'ClassPrettyName::$propertyName'], |
34
|
|
|
['m', 'ClassPrettyName::methodName'], |
35
|
|
|
['co', 'ConstantPrettyName'], |
36
|
|
|
['f', 'FunctionPrettyName'], |
37
|
|
|
], $elements); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @return PHPUnit_Framework_MockObject_MockObject|ElementStorageInterface |
42
|
|
|
*/ |
43
|
|
|
private function createElementStorageMock() |
44
|
|
|
{ |
45
|
|
|
$classReflectionMock = $this->createMock(ClassReflectionInterface::class); |
46
|
|
|
$classReflectionMock->method('getPrettyName') |
47
|
|
|
->willReturn('ClassPrettyName'); |
48
|
|
|
$classReflectionMock->method('getOwnConstants') |
49
|
|
|
->willReturn([]); |
50
|
|
|
|
51
|
|
|
$methodReflection = $this->createMock(MethodReflectionInterface::class); |
52
|
|
|
$methodReflection->method('getPrettyName') |
53
|
|
|
->willReturn('ClassPrettyName::methodName'); |
54
|
|
|
$classReflectionMock->method('getOwnMethods') |
55
|
|
|
->willReturn([$methodReflection]); |
56
|
|
|
|
57
|
|
|
$propertyReflection = $this->createMock(PropertyReflectionInterface::class); |
58
|
|
|
$propertyReflection->method('getPrettyName') |
59
|
|
|
->willReturn('ClassPrettyName::$propertyName'); |
60
|
|
|
$classReflectionMock->method('getOwnProperties') |
61
|
|
|
->willReturn([$propertyReflection]); |
62
|
|
|
|
63
|
|
|
$constantReflectionMock = $this->createMock(ConstantReflectionInterface::class); |
64
|
|
|
$constantReflectionMock->method('getPrettyName') |
65
|
|
|
->willReturn('ConstantPrettyName'); |
66
|
|
|
|
67
|
|
|
$functionReflectionMock = $this->createMock(FunctionReflectionInterface::class); |
68
|
|
|
$functionReflectionMock->method('getPrettyName') |
69
|
|
|
->willReturn('FunctionPrettyName'); |
70
|
|
|
|
71
|
|
|
$elementsStorageMock = $this->createMock(ElementStorageInterface::class); |
72
|
|
|
$elementsStorageMock->method('getElements') |
73
|
|
|
->willReturn([ |
74
|
|
|
'classes' => [$classReflectionMock], |
75
|
|
|
'constants' => [$constantReflectionMock], |
76
|
|
|
'functions' => [$functionReflectionMock] |
77
|
|
|
]); |
78
|
|
|
return $elementsStorageMock; |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.