|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace ApiGen\Tests\Generator\Resolvers\ElementResolver; |
|
4
|
|
|
|
|
5
|
|
|
use ApiGen\Contracts\Parser\Reflection\ClassReflectionInterface; |
|
6
|
|
|
use ApiGen\Contracts\Parser\Reflection\MethodReflectionInterface; |
|
7
|
|
|
|
|
8
|
|
|
final class ResolveTest extends AbstractElementResolverTest |
|
9
|
|
|
{ |
|
10
|
|
|
public function testNonExistingMethod(): void |
|
11
|
|
|
{ |
|
12
|
|
|
$classReflectionMock = $this->createMock(ClassReflectionInterface::class); |
|
13
|
|
|
$classReflectionMock->method('hasMethod') |
|
14
|
|
|
->with('nonExistingMethod') |
|
15
|
|
|
->willReturn(false); |
|
16
|
|
|
|
|
17
|
|
|
$this->assertNull($this->elementResolver->resolveElement('nonExistingMethod', $classReflectionMock)); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
View Code Duplication |
public function testExistingMethod(): void |
|
|
|
|
|
|
21
|
|
|
{ |
|
22
|
|
|
$classReflectionMock = $this->createMock(ClassReflectionInterface::class); |
|
23
|
|
|
$classReflectionMock->method('hasMethod') |
|
24
|
|
|
->with('someMethod') |
|
25
|
|
|
->willReturn(true); |
|
26
|
|
|
|
|
27
|
|
|
$methodReflectionMock = $this->createMock(MethodReflectionInterface::class); |
|
28
|
|
|
|
|
29
|
|
|
$classReflectionMock->method('getMethod') |
|
30
|
|
|
->with('someMethod') |
|
31
|
|
|
->willReturn($methodReflectionMock); |
|
32
|
|
|
|
|
33
|
|
|
$this->assertSame( |
|
34
|
|
|
$methodReflectionMock, |
|
35
|
|
|
$this->elementResolver->resolveElement('someMethod', $classReflectionMock) |
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testNonExistingElement(): void |
|
40
|
|
|
{ |
|
41
|
|
|
$classReflectionMock = $this->createMock(ClassReflectionInterface::class); |
|
42
|
|
|
|
|
43
|
|
|
$this->assertNull($this->elementResolver->resolveElement('string', $classReflectionMock)); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testThis(): void |
|
47
|
|
|
{ |
|
48
|
|
|
$classReflectionMock = $this->createMock(ClassReflectionInterface::class); |
|
49
|
|
|
|
|
50
|
|
|
$this->assertSame($classReflectionMock, $this->elementResolver->resolveElement('$this', $classReflectionMock)); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function testSelf(): void |
|
54
|
|
|
{ |
|
55
|
|
|
$classReflectionMock = $this->createMock(ClassReflectionInterface::class); |
|
56
|
|
|
|
|
57
|
|
|
$this->assertSame($classReflectionMock, $this->elementResolver->resolveElement('self', $classReflectionMock)); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
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.