[!!!][TASK] Extract testing framework for TYPO3
[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\Extbase\Reflection\ReflectionService;
18
19 /**
20 * Test case
21 * @firsttest test for reflection
22 * @anothertest second test for reflection
23 * @anothertest second test for reflection with second value
24 */
25 class ReflectionServiceTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitTestCase
26 {
27 /**
28 * @param array $foo The foo parameter
29 * @return void
30 */
31 public function fixtureMethodForMethodTagsValues(array $foo)
32 {
33 }
34
35 /**
36 * @param bool $dummy
37 * @param int $foo
38 * @return void
39 */
40 public function fixtureMethodForMethodTagsValuesWithShortTypes($dummy, $foo)
41 {
42 }
43
44 /**
45 * @test
46 */
47 public function getClassTagsValues()
48 {
49 $service = new ReflectionService();
50 $classValues = $service->getClassTagsValues(get_class($this));
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 = new ReflectionService();
63 $classValues = $service->getClassTagValues(get_class($this), 'firsttest');
64 $this->assertEquals([
65 'test for reflection',
66 ], $classValues);
67 }
68
69 /**
70 * @test
71 */
72 public function hasMethod()
73 {
74 $service = new ReflectionService();
75 $this->assertTrue($service->hasMethod(get_class($this), 'fixtureMethodForMethodTagsValues'));
76 $this->assertFalse($service->hasMethod(get_class($this), 'notExistentMethod'));
77 }
78
79 /**
80 * @test
81 */
82 public function getMethodTagsValues()
83 {
84 $service = new ReflectionService();
85 $tagsValues = $service->getMethodTagsValues(get_class($this), 'fixtureMethodForMethodTagsValues');
86 $this->assertEquals([
87 'param' => ['array $foo The foo parameter'],
88 'return' => ['void']
89 ], $tagsValues);
90 }
91
92 /**
93 * @test
94 */
95 public function getMethodParameters()
96 {
97 $service = new ReflectionService();
98 $parameters = $service->getMethodParameters(get_class($this), '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 ]
109 ], $parameters);
110 }
111
112 /**
113 * @test
114 */
115 public function getMethodParametersWithShortTypeNames()
116 {
117 $service = new ReflectionService();
118 $parameters = $service->getMethodParameters(get_class($this), 'fixtureMethodForMethodTagsValuesWithShortTypes');
119 $this->assertSame([
120 'dummy' => [
121 'position' => 0,
122 'byReference' => false,
123 'array' => false,
124 'optional' => false,
125 'allowsNull' => true,
126 'class' => null,
127 'type' => 'boolean'
128 ],
129 'foo' => [
130 'position' => 1,
131 'byReference' => false,
132 'array' => false,
133 'optional' => false,
134 'allowsNull' => true,
135 'class' => null,
136 'type' => 'integer'
137 ]
138 ], $parameters);
139 }
140 }