[FEATURE] Support 'has*' for properties in ObjectAccess
[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\Tests\UnitTestCase;
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 UnitTestCase {
27
28 /**
29 * @param array $foo The foo parameter
30 * @return void
31 */
32 public function fixtureMethodForMethodTagsValues(array $foo) {
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 * @test
45 */
46 public function getClassTagsValues() {
47 $service = new ReflectionService();
48 $classValues = $service->getClassTagsValues(get_class($this));
49 $this->assertEquals(array(
50 'firsttest' => array('test for reflection'),
51 'anothertest' => array('second test for reflection', 'second test for reflection with second value')
52 ), $classValues);
53 }
54
55 /**
56 * @test
57 */
58 public function getClassTagValues() {
59 $service = new ReflectionService();
60 $classValues = $service->getClassTagValues(get_class($this), 'firsttest');
61 $this->assertEquals(array(
62 'test for reflection',
63 ), $classValues);
64 }
65
66 /**
67 * @test
68 */
69 public function hasMethod() {
70 $service = new ReflectionService();
71 $this->assertTrue($service->hasMethod(get_class($this), 'fixtureMethodForMethodTagsValues'));
72 $this->assertFalse($service->hasMethod(get_class($this), 'notExistentMethod'));
73 }
74
75 /**
76 * @test
77 */
78 public function getMethodTagsValues() {
79 $service = new ReflectionService();
80 $tagsValues = $service->getMethodTagsValues(get_class($this), 'fixtureMethodForMethodTagsValues');
81 $this->assertEquals(array(
82 'param' => array('array $foo The foo parameter'),
83 'return' => array('void')
84 ), $tagsValues);
85 }
86
87 /**
88 * @test
89 */
90 public function getMethodParameters() {
91 $service = new ReflectionService();
92 $parameters = $service->getMethodParameters(get_class($this), 'fixtureMethodForMethodTagsValues');
93 $this->assertSame(array(
94 'foo' => array(
95 'position' => 0,
96 'byReference' => FALSE,
97 'array' => TRUE,
98 'optional' => FALSE,
99 'allowsNull' => FALSE,
100 'class' => NULL,
101 'type' => 'array'
102 )
103 ), $parameters);
104 }
105
106 /**
107 * @test
108 */
109 public function getMethodParametersWithShortTypeNames() {
110 $service = new ReflectionService();
111 $parameters = $service->getMethodParameters(get_class($this), 'fixtureMethodForMethodTagsValuesWithShortTypes');
112 $this->assertSame(array(
113 'dummy' => array(
114 'position' => 0,
115 'byReference' => FALSE,
116 'array' => FALSE,
117 'optional' => FALSE,
118 'allowsNull' => TRUE,
119 'class' => NULL,
120 'type' => 'boolean'
121 ),
122 'foo' => array(
123 'position' => 1,
124 'byReference' => FALSE,
125 'array' => FALSE,
126 'optional' => FALSE,
127 'allowsNull' => TRUE,
128 'class' => NULL,
129 'type' => 'integer'
130 )
131 ), $parameters);
132 }
133
134 }