|
6 | 6 |
|
7 | 7 | use Brick\Reflection\ReflectionTools; |
8 | 8 |
|
| 9 | +use Brick\Reflection\Tests\Classes\ParameterTypesPHP72; |
| 10 | +use Brick\Reflection\Tests\Classes\ParameterTypesPHP80; |
9 | 11 | use Brick\Reflection\Tests\Classes\PropertyTypesPHP72; |
10 | 12 | use Brick\Reflection\Tests\Classes\PropertyTypesPHP74; |
11 | 13 | use Brick\Reflection\Tests\Classes\PropertyTypesPHP80; |
@@ -152,14 +154,55 @@ public function providerExportFunction() : array |
152 | 154 | ]; |
153 | 155 | } |
154 | 156 |
|
| 157 | + /** |
| 158 | + * @dataProvider providerGetParameterTypes |
| 159 | + */ |
| 160 | + public function testGetParameterTypes(string $class, string $method, string $parameter, array $types) : void |
| 161 | + { |
| 162 | + $tools = new ReflectionTools(); |
| 163 | + $reflectionMethod = new \ReflectionMethod($class, $method); |
| 164 | + |
| 165 | + foreach ($reflectionMethod->getParameters() as $reflectionParameter) { |
| 166 | + if ($reflectionParameter->getName() === $parameter) { |
| 167 | + self::assertSame($types, $tools->getParameterTypes($reflectionParameter)); |
| 168 | + return; |
| 169 | + } |
| 170 | + } |
| 171 | + |
| 172 | + self::fail(sprintf('Parameter $%s not found in %s::%s()', $parameter, $class, $method)); |
| 173 | + } |
| 174 | + |
| 175 | + public function providerGetParameterTypes() : array |
| 176 | + { |
| 177 | + $tests = [ |
| 178 | + [ParameterTypesPHP72::class, 'x', 'a', ['int', 'string', 'Namespaced\Foo', 'Brick\Reflection\Tests\Classes\Bar']], |
| 179 | + [ParameterTypesPHP72::class, 'x', 'b', ['PDO', 'null']], |
| 180 | + [ParameterTypesPHP72::class, 'x', 'c', ['stdClass']], |
| 181 | + [ParameterTypesPHP72::class, 'x', 'd', ['stdClass', 'null']], |
| 182 | + ]; |
| 183 | + |
| 184 | + if (version_compare(PHP_VERSION, '8.0') >= 0) { |
| 185 | + $tests = array_merge($tests, [ |
| 186 | + [ParameterTypesPHP80::class, 'x', 'a', ['int', 'string', 'Namespaced\Foo', 'Brick\Reflection\Tests\Classes\Bar']], |
| 187 | + [ParameterTypesPHP80::class, 'x', 'b', ['PDO', 'null']], |
| 188 | + [ParameterTypesPHP80::class, 'x', 'c', ['stdClass']], |
| 189 | + [ParameterTypesPHP80::class, 'x', 'd', ['stdClass', 'null']], |
| 190 | + [ParameterTypesPHP80::class, 'y', 'a', ['stdClass', 'null']], |
| 191 | + [ParameterTypesPHP80::class, 'y', 'b', ['stdClass', 'A\B', 'string', 'int', 'null']], |
| 192 | + ]); |
| 193 | + } |
| 194 | + |
| 195 | + return $tests; |
| 196 | + } |
| 197 | + |
155 | 198 | /** |
156 | 199 | * @dataProvider providerGetPropertyTypes |
157 | 200 | */ |
158 | 201 | public function testGetPropertyTypes(string $class, string $property, array $types) : void |
159 | 202 | { |
160 | 203 | $tools = new ReflectionTools(); |
161 | | - $property = new \ReflectionProperty($class, $property); |
162 | | - self::assertSame($types, $tools->getPropertyTypes($property)); |
| 204 | + $reflectionProperty = new \ReflectionProperty($class, $property); |
| 205 | + self::assertSame($types, $tools->getPropertyTypes($reflectionProperty)); |
163 | 206 | } |
164 | 207 |
|
165 | 208 | public function providerGetPropertyTypes() : array |
|
0 commit comments