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