[CLEANUP] Remove/Replace non-standard phpdoc annotations
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Reflection / ReflectionServiceTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\Unit\Reflection;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Utility\GeneralUtility;
18 use TYPO3\CMS\Extbase\Reflection\ReflectionService;
19
20 /**
21 * Test case
22 * @see test for reflection
23 * @link second test for reflection
24 * @link second test for reflection with second value
25 */
26 class ReflectionServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
27 {
28 /**
29 * @param array $foo The foo parameter
30 * @return string
31 */
32 public function fixtureMethodForMethodTagsValues(array $foo)
33 {
34 }
35
36 /**
37 * @param bool $dummy
38 * @param int $foo
39 */
40 public function fixtureMethodForMethodTagsValuesWithShortTypes($dummy, $foo)
41 {
42 }
43
44 /**
45 * @test
46 */
47 public function getClassTagsValues()
48 {
49 $service = GeneralUtility::makeInstance(ReflectionService::class);
50 $classValues = $service->getClassTagsValues(static::class);
51 $this->assertEquals([
52 'see' => ['test for reflection'],
53 'link' => ['second test for reflection', 'second test for reflection with second value']
54 ], $classValues);
55
56 $this->assertEquals(
57 [],
58 $service->getClassTagsValues('NonExistantNamespace\\NonExistantClass')
59 );
60 }
61
62 /**
63 * @test
64 */
65 public function getClassTagValues()
66 {
67 $service = GeneralUtility::makeInstance(ReflectionService::class);
68 $classValues = $service->getClassTagValues(static::class, 'see');
69 $this->assertEquals([
70 'test for reflection',
71 ], $classValues);
72
73 $this->assertEquals(
74 [],
75 $service->getClassTagValues(static::class, 'nonExistantTag')
76 );
77
78 $this->assertEquals(
79 [],
80 $service->getClassTagValues('NonExistantNamespace\\NonExistantClass', 'nonExistantTag')
81 );
82 }
83
84 /**
85 * @test
86 */
87 public function hasMethod()
88 {
89 $service = GeneralUtility::makeInstance(ReflectionService::class);
90 $this->assertTrue($service->hasMethod(static::class, 'fixtureMethodForMethodTagsValues'));
91 $this->assertFalse($service->hasMethod(static::class, 'notExistentMethod'));
92 $this->assertFalse($service->hasMethod('NonExistantNamespace\\NonExistantClass', 'notExistentMethod'));
93 }
94
95 /**
96 * @test
97 */
98 public function getMethodTagsValues()
99 {
100 $service = GeneralUtility::makeInstance(ReflectionService::class);
101 $tagsValues = $service->getMethodTagsValues(static::class, 'fixtureMethodForMethodTagsValues');
102 $this->assertEquals([
103 'param' => ['array $foo The foo parameter'],
104 'return' => ['string']
105 ], $tagsValues);
106
107 $this->assertEquals(
108 [],
109 $service->getMethodTagsValues(static::class, 'notExistentMethod')
110 );
111
112 $this->assertEquals(
113 [],
114 $service->getMethodTagsValues('NonExistantNamespace\\NonExistantClass', 'notExistentMethod')
115 );
116 }
117
118 /**
119 * @test
120 */
121 public function getMethodParameters()
122 {
123 $service = GeneralUtility::makeInstance(ReflectionService::class);
124 $parameters = $service->getMethodParameters(static::class, 'fixtureMethodForMethodTagsValues');
125 $this->assertSame([
126 'foo' => [
127 'position' => 0,
128 'byReference' => false,
129 'array' => true,
130 'optional' => false,
131 'allowsNull' => false,
132 'class' => null,
133 'type' => 'array',
134 'nullable' => false,
135 'default' => null,
136 'hasDefaultValue' => false,
137 'defaultValue' => null,
138 'dependency' => null,
139 ]
140 ], $parameters);
141
142 $this->assertSame(
143 [],
144 $service->getMethodParameters(static::class, 'notExistentMethod')
145 );
146
147 $this->assertSame(
148 [],
149 $service->getMethodParameters('NonExistantNamespace\\NonExistantClass', 'notExistentMethod')
150 );
151 }
152
153 /**
154 * @test
155 */
156 public function getMethodParametersWithShortTypeNames()
157 {
158 $service = GeneralUtility::makeInstance(ReflectionService::class);
159 $parameters = $service->getMethodParameters(static::class, 'fixtureMethodForMethodTagsValuesWithShortTypes');
160 $this->assertSame([
161 'dummy' => [
162 'position' => 0,
163 'byReference' => false,
164 'array' => false,
165 'optional' => false,
166 'allowsNull' => true,
167 'class' => null,
168 'type' => 'boolean',
169 'nullable' => true,
170 'default' => null,
171 'hasDefaultValue' => false,
172 'defaultValue' => null,
173 'dependency' => null,
174 ],
175 'foo' => [
176 'position' => 1,
177 'byReference' => false,
178 'array' => false,
179 'optional' => false,
180 'allowsNull' => true,
181 'class' => null,
182 'type' => 'integer',
183 'nullable' => true,
184 'default' => null,
185 'hasDefaultValue' => false,
186 'defaultValue' => null,
187 'dependency' => null,
188 ]
189 ], $parameters);
190 }
191
192 public function testIsClassTaggedWith()
193 {
194 $service = GeneralUtility::makeInstance(ReflectionService::class);
195 $this->assertTrue($service->isClassTaggedWith(
196 Fixture\DummyClassWithTags::class,
197 'see'
198 ));
199
200 $this->assertFalse($service->isClassTaggedWith(
201 Fixture\DummyClassWithAllTypesOfProperties::class,
202 'bar'
203 ));
204
205 $this->assertFalse($service->isClassTaggedWith(
206 'NonExistantNamespace\\NonExistantClass',
207 'foo'
208 ));
209 }
210
211 public function testIsPropertyTaggedWith()
212 {
213 $service = GeneralUtility::makeInstance(ReflectionService::class);
214 $this->assertTrue($service->isPropertyTaggedWith(
215 Fixture\DummyClassWithAllTypesOfProperties::class,
216 'propertyWithInjectAnnotation',
217 'inject'
218 ));
219
220 $this->assertFalse($service->isPropertyTaggedWith(
221 Fixture\DummyClassWithAllTypesOfProperties::class,
222 'propertyWithInjectAnnotation',
223 'foo'
224 ));
225
226 $this->assertFalse($service->isPropertyTaggedWith(
227 Fixture\DummyClassWithAllTypesOfProperties::class,
228 'nonExistantProperty',
229 'foo'
230 ));
231
232 $this->assertFalse($service->isPropertyTaggedWith(
233 'NonExistantNamespace\\NonExistantClass',
234 'propertyWithInjectAnnotation',
235 'inject'
236 ));
237 }
238
239 public function testgetPropertyTagValues()
240 {
241 $service = GeneralUtility::makeInstance(ReflectionService::class);
242
243 $this->assertSame(
244 [],
245 $service->getPropertyTagValues(
246 Fixture\DummyClassWithAllTypesOfProperties::class,
247 'propertyWithInjectAnnotation',
248 'foo'
249 )
250 );
251
252 $this->assertSame(
253 [],
254 $service->getPropertyTagValues(
255 Fixture\DummyClassWithAllTypesOfProperties::class,
256 'propertyWithInjectAnnotation',
257 'inject'
258 )
259 );
260 }
261
262 public function testGetPropertyTagsValues()
263 {
264 $service = GeneralUtility::makeInstance(ReflectionService::class);
265
266 $this->assertSame(
267 [
268 'inject' => [],
269 'var' => [
270 'DummyClassWithAllTypesOfProperties'
271 ]
272 ],
273 $service->getPropertyTagsValues(
274 Fixture\DummyClassWithAllTypesOfProperties::class,
275 'propertyWithInjectAnnotation'
276 )
277 );
278
279 $this->assertSame(
280 [],
281 $service->getPropertyTagsValues(
282 Fixture\DummyClassWithAllTypesOfProperties::class,
283 'nonExistantProperty'
284 )
285 );
286
287 $this->assertSame(
288 [],
289 $service->getPropertyTagsValues(
290 'NonExistantNamespace\\NonExistantClass',
291 'nonExistantProperty'
292 )
293 );
294 }
295
296 public function testGetClassPropertyNames()
297 {
298 $service = GeneralUtility::makeInstance(ReflectionService::class);
299
300 $this->assertSame(
301 [
302 'publicProperty',
303 'protectedProperty',
304 'privateProperty',
305 'publicStaticProperty',
306 'protectedStaticProperty',
307 'privateStaticProperty',
308 'propertyWithIgnoredTags',
309 'propertyWithInjectAnnotation',
310 'propertyWithTransientAnnotation',
311 'propertyWithCascadeAnnotation',
312 'propertyWithCascadeAnnotationWithoutVarAnnotation',
313 'propertyWithObjectStorageAnnotation'
314 ],
315 $service->getClassPropertyNames(Fixture\DummyClassWithAllTypesOfProperties::class)
316 );
317
318 $this->assertSame(
319 [],
320 $service->getClassPropertyNames('NonExistantNamespace\\NonExistantClass')
321 );
322 }
323 }