|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace ApiGen\Tests\Generator\Resolvers\ElementResolver; |
|
4
|
|
|
|
|
5
|
|
|
use ApiGen\Contracts\Parser\Reflection\FunctionReflectionInterface; |
|
6
|
|
|
use ApiGen\Contracts\Parser\Reflection\ParameterReflectionInterface; |
|
7
|
|
|
use ApiGen\Tests\MethodInvoker; |
|
8
|
|
|
use PHPUnit_Framework_MockObject_MockObject; |
|
9
|
|
|
|
|
10
|
|
|
final class CorrectContextForFunctionParameterTest extends AbstractElementResolverTest |
|
11
|
|
|
{ |
|
12
|
|
View Code Duplication |
public function test(): void |
|
|
|
|
|
|
13
|
|
|
{ |
|
14
|
|
|
$functionReflectionMock = $this->createFunctionReflectionMock(); |
|
15
|
|
|
|
|
16
|
|
|
$this->parserStorage->setFunctions([ |
|
|
|
|
|
|
17
|
|
|
'SomeFunction' => $functionReflectionMock |
|
18
|
|
|
]); |
|
19
|
|
|
|
|
20
|
|
|
$reflectionParameterMock = $this->createReflectionParameterInFunctionMock(); |
|
21
|
|
|
|
|
22
|
|
|
$resolvedElement = MethodInvoker::callMethodOnObject( |
|
23
|
|
|
$this->elementResolver, |
|
24
|
|
|
'correctContextForParameterOrClassMember', |
|
25
|
|
|
[$reflectionParameterMock] |
|
26
|
|
|
); |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
$this->assertInstanceOf(FunctionReflectionInterface::class, $resolvedElement); |
|
30
|
|
|
$this->assertSame($functionReflectionMock, $resolvedElement); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @return PHPUnit_Framework_MockObject_MockObject|ParameterReflectionInterface |
|
35
|
|
|
*/ |
|
36
|
|
|
private function createReflectionParameterInFunctionMock() |
|
37
|
|
|
{ |
|
38
|
|
|
$reflectionParameterMock = $this->createMock(ParameterReflectionInterface::class); |
|
39
|
|
|
$reflectionParameterMock->method('getDeclaringClassName') |
|
40
|
|
|
->willReturn(''); |
|
41
|
|
|
|
|
42
|
|
|
$reflectionParameterMock->method('getDeclaringFunctionName') |
|
43
|
|
|
->willReturn('SomeFunction'); |
|
44
|
|
|
|
|
45
|
|
|
return $reflectionParameterMock; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @return PHPUnit_Framework_MockObject_MockObject|FunctionReflectionInterface |
|
50
|
|
|
*/ |
|
51
|
|
View Code Duplication |
private function createFunctionReflectionMock() |
|
|
|
|
|
|
52
|
|
|
{ |
|
53
|
|
|
$functionReflectionMock = $this->createMock(FunctionReflectionInterface::class); |
|
54
|
|
|
$functionReflectionMock->method('getName') |
|
55
|
|
|
->willReturn('SomeFunction'); |
|
56
|
|
|
|
|
57
|
|
|
$functionReflectionMock->method('isDocumented') |
|
58
|
|
|
->willReturn(true); |
|
59
|
|
|
|
|
60
|
|
|
return $functionReflectionMock; |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
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.