9f12e29cc81e08f7fe212a0eeab28c093fe136f4
[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 * @firsttest test for reflection
23 * @anothertest second test for reflection
24 * @anothertest 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 'firsttest' => ['test for reflection'],
53 'anothertest' => ['second test for reflection', 'second test for reflection with second value']
54 ], $classValues);
55 }
56
57 /**
58 * @test
59 */
60 public function getClassTagValues()
61 {
62 $service = GeneralUtility::makeInstance(ReflectionService::class);
63 $classValues = $service->getClassTagValues(static::class, 'firsttest');
64 $this->assertEquals([
65 'test for reflection',
66 ], $classValues);
67 }
68
69 /**
70 * @test
71 */
72 public function hasMethod()
73 {
74 $service = GeneralUtility::makeInstance(ReflectionService::class);
75 $this->assertTrue($service->hasMethod(static::class, 'fixtureMethodForMethodTagsValues'));
76 $this->assertFalse($service->hasMethod(static::class, 'notExistentMethod'));
77 }
78
79 /**
80 * @test
81 */
82 public function getMethodTagsValues()
83 {
84 $service = GeneralUtility::makeInstance(ReflectionService::class);
85 $tagsValues = $service->getMethodTagsValues(static::class, 'fixtureMethodForMethodTagsValues');
86 $this->assertEquals([
87 'param' => ['array $foo The foo parameter'],
88 'return' => ['string']
89 ], $tagsValues);
90 }
91
92 /**
93 * @test
94 */
95 public function getMethodParameters()
96 {
97 $service = GeneralUtility::makeInstance(ReflectionService::class);
98 $parameters = $service->getMethodParameters(static::class, 'fixtureMethodForMethodTagsValues');
99 $this->assertSame([
100 'foo' => [
101 'position' => 0,
102 'byReference' => false,
103 'array' => true,
104 'optional' => false,
105 'allowsNull' => false,
106 'class' => null,
107 'type' => 'array',
108 'nullable' => false,
109 'default' => null,
110 'hasDefaultValue' => false,
111 'defaultValue' => null,
112 'dependency' => null,
113 ]
114 ], $parameters);
115 }
116
117 /**
118 * @test
119 */
120 public function getMethodParametersWithShortTypeNames()
121 {
122 $service = GeneralUtility::makeInstance(ReflectionService::class);
123 $parameters = $service->getMethodParameters(static::class, 'fixtureMethodForMethodTagsValuesWithShortTypes');
124 $this->assertSame([
125 'dummy' => [
126 'position' => 0,
127 'byReference' => false,
128 'array' => false,
129 'optional' => false,
130 'allowsNull' => true,
131 'class' => null,
132 'type' => 'boolean',
133 'nullable' => true,
134 'default' => null,
135 'hasDefaultValue' => false,
136 'defaultValue' => null,
137 'dependency' => null,
138 ],
139 'foo' => [
140 'position' => 1,
141 'byReference' => false,
142 'array' => false,
143 'optional' => false,
144 'allowsNull' => true,
145 'class' => null,
146 'type' => 'integer',
147 'nullable' => true,
148 'default' => null,
149 'hasDefaultValue' => false,
150 'defaultValue' => null,
151 'dependency' => null,
152 ]
153 ], $parameters);
154 }
155 }