‪TYPO3CMS  9.5
ReflectionServiceTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
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 
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21 
28 class ‪ReflectionServiceTest extends UnitTestCase
29 {
34  public function ‪fixtureMethodForMethodTagsValues(array $foo): string
35  {
36  return '';
37  }
38 
43  public function ‪fixtureMethodForMethodTagsValuesWithShortTypes($dummy, $foo): void
44  {
45  }
46 
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 
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 
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 
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 
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 
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  'propertyWithTransientAnnotation',
314  'propertyWithCascadeAnnotation',
315  'propertyWithCascadeAnnotationWithoutVarAnnotation',
316  'propertyWithObjectStorageAnnotation'
317  ],
318  $service->getClassPropertyNames(Fixture\DummyClassWithAllTypesOfProperties::class)
319  );
320 
321  $this->assertSame(
322  [],
323  $service->getClassPropertyNames('NonExistantNamespace\\NonExistantClass')
324  );
325  }
326 }
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ReflectionServiceTest\getMethodParameters
‪getMethodParameters()
Definition: ReflectionServiceTest.php:124
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ReflectionServiceTest\hasMethod
‪hasMethod()
Definition: ReflectionServiceTest.php:90
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ReflectionServiceTest\testIsPropertyTaggedWith
‪testIsPropertyTaggedWith()
Definition: ReflectionServiceTest.php:217
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ReflectionServiceTest\testIsClassTaggedWith
‪testIsClassTaggedWith()
Definition: ReflectionServiceTest.php:198
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ReflectionServiceTest\getClassTagValues
‪getClassTagValues()
Definition: ReflectionServiceTest.php:68
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ReflectionServiceTest\testGetPropertyTagsValues
‪testGetPropertyTagsValues()
Definition: ReflectionServiceTest.php:267
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ReflectionServiceTest\getClassTagsValues
‪getClassTagsValues()
Definition: ReflectionServiceTest.php:50
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ReflectionServiceTest
Definition: ReflectionServiceTest.php:29
‪TYPO3\CMS\Extbase\Reflection\ReflectionService
Definition: ReflectionService.php:27
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ReflectionServiceTest\testGetClassPropertyNames
‪testGetClassPropertyNames()
Definition: ReflectionServiceTest.php:300
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ReflectionServiceTest\getMethodTagsValues
‪getMethodTagsValues()
Definition: ReflectionServiceTest.php:101
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ReflectionServiceTest\fixtureMethodForMethodTagsValues
‪string fixtureMethodForMethodTagsValues(array $foo)
Definition: ReflectionServiceTest.php:34
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ReflectionServiceTest\fixtureMethodForMethodTagsValuesWithShortTypes
‪fixtureMethodForMethodTagsValuesWithShortTypes($dummy, $foo)
Definition: ReflectionServiceTest.php:43
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ReflectionServiceTest\testgetPropertyTagValues
‪testgetPropertyTagValues()
Definition: ReflectionServiceTest.php:245
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection
Definition: ClassSchemaTest.php:2
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Reflection\ReflectionServiceTest\getMethodParametersWithShortTypeNames
‪getMethodParametersWithShortTypeNames()
Definition: ReflectionServiceTest.php:160