/
SeeAnnotationSubscriberTest.php
139 lines (114 loc) · 5.48 KB
/
SeeAnnotationSubscriberTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php declare(strict_types=1);
namespace ApiGen\Annotation\Tests\AnnotationSubscriber;
use ApiGen\Annotation\AnnotationDecorator;
use ApiGen\Annotation\AnnotationList;
use ApiGen\Annotation\Tests\AnnotationSubscriber\SeeAnnotationSubscriberSource\InterfaceWithSeeAnnotationsInterface;
use ApiGen\Annotation\Tests\AnnotationSubscriber\SeeAnnotationSubscriberSource\SomeClassWithSeeAnnotations;
use ApiGen\Reflection\Contract\Reflection\Class_\ClassMethodReflectionInterface;
use ApiGen\Reflection\Contract\Reflection\Class_\ClassReflectionInterface;
use ApiGen\Reflection\Contract\Reflection\Function_\FunctionReflectionInterface;
use ApiGen\Reflection\Contract\Reflection\Interface_\InterfaceReflectionInterface;
use ApiGen\Tests\AbstractParserAwareTestCase;
final class SeeAnnotationSubscriberTest extends AbstractParserAwareTestCase
{
/**
* @var AnnotationDecorator
*/
private $annotationDecorator;
/**
* @var ClassReflectionInterface
*/
private $classReflection;
/**
* @var ClassMethodReflectionInterface
*/
private $methodReflection;
/**
* @var FunctionReflectionInterface
*/
private $functionReflection;
/**
* @var InterfaceReflectionInterface
*/
private $interfaceReflection;
protected function setUp(): void
{
$this->parser->parseFilesAndDirectories([__DIR__ . '/SeeAnnotationSubscriberSource']);
$this->annotationDecorator = $this->container->get(AnnotationDecorator::class);
$this->classReflection = $this->reflectionStorage->getClassReflections()[SomeClassWithSeeAnnotations::class];
$this->methodReflection = $this->classReflection->getMethod('returnArray');
$this->functionReflection = $this->reflectionStorage->getFunctionReflections()[
'ApiGen\Annotation\Tests\AnnotationSubscriber\SeeAnnotationSubscriberSource\someFunction'
];
$this->interfaceReflection = $this->reflectionStorage->getInterfaceReflections()[
InterfaceWithSeeAnnotationsInterface::class
];
}
public function testPropertyOnMissingClassReflection(): void
{
$seePropertyAnnotation = $this->methodReflection->getAnnotation(AnnotationList::SEE)[0];
$this->assertSame(
'<code>ReturnedClass::$someProperty</code>',
$this->annotationDecorator->decorate($seePropertyAnnotation, $this->methodReflection)
);
}
public function testProperty(): void
{
$seePropertyAnnotation = $this->methodReflection->getAnnotation(AnnotationList::SEE)[2];
$this->assertSame(
'<code><a href="class-ApiGen.Annotation.Tests.AnnotationSubscriber.SeeAnnotationSubscriberSource.'
. 'PresentReturnedClass.html#$someProperty">PresentReturnedClass::$someProperty</a></code>',
$this->annotationDecorator->decorate($seePropertyAnnotation, $this->methodReflection)
);
}
public function testMethodOnMissingClassReflection(): void
{
$seeMethodAnnotation = $this->methodReflection->getAnnotation(AnnotationList::SEE)[1];
$this->assertSame(
'<code>ReturnedClass::someMethod()</code>',
$this->annotationDecorator->decorate($seeMethodAnnotation, $this->methodReflection)
);
}
public function testMethod(): void
{
$seeMethodAnnotation = $this->methodReflection->getAnnotation(AnnotationList::SEE)[3];
$this->assertSame(
'<code><a href="class-ApiGen.Annotation.Tests.AnnotationSubscriber.SeeAnnotationSubscriberSource'
. '.PresentReturnedClass.html#_someMethod">PresentReturnedClass::someMethod()</a></code>',
$this->annotationDecorator->decorate($seeMethodAnnotation, $this->methodReflection)
);
}
public function testMissingFunction(): void
{
$seeFunctionAnnotation = $this->methodReflection->getAnnotation(AnnotationList::SEE)[4];
$this->assertSame(
'<code>someMissingFunction()</code>',
$this->annotationDecorator->decorate($seeFunctionAnnotation, $this->methodReflection)
);
}
public function testFunction(): void
{
$seeFunctionAnnotation = $this->functionReflection->getAnnotation(AnnotationList::SEE)[0];
$this->assertSame(
'<code><a href="function-ApiGen.Annotation.Tests.AnnotationSubscriber.SeeAnnotationSubscriberSource'
. '.anotherFunction.html">anotherFunction()</a></code>',
$this->annotationDecorator->decorate($seeFunctionAnnotation, $this->functionReflection)
);
$seeFunctionAnnotation = $this->methodReflection->getAnnotation(AnnotationList::SEE)[5];
$this->assertSame(
'<code><a href="function-ApiGen.Annotation.Tests.AnnotationSubscriber.SeeAnnotationSubscriberSource'
. '.someExistingFunction.html">someExistingFunction()</a></code>',
$this->annotationDecorator->decorate($seeFunctionAnnotation, $this->methodReflection)
);
}
public function testInterface(): void
{
$seeMethodAnnotation = $this->interfaceReflection->getMethod('someSexyMethod')
->getAnnotation(AnnotationList::SEE)[0];
$this->assertSame(
'<code><a href="class-ApiGen.Annotation.Tests.AnnotationSubscriber.SeeAnnotationSubscriberSource'
. '.SomeClassWithSeeAnnotations.html#_returnArray">SomeClassWithSeeAnnotations::returnArray()</a></code>',
$this->annotationDecorator->decorate($seeMethodAnnotation, $this->interfaceReflection)
);
}
}