Make ReflectionExtractor compatible with ReflectionType changes in PHP 7.1
This commit is contained in:
parent
356a0ac7e4
commit
4a041e9a75
@ -231,7 +231,7 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
|
|||||||
*/
|
*/
|
||||||
private function extractFromReflectionType(\ReflectionType $reflectionType)
|
private function extractFromReflectionType(\ReflectionType $reflectionType)
|
||||||
{
|
{
|
||||||
$phpTypeOrClass = (string) $reflectionType;
|
$phpTypeOrClass = method_exists($reflectionType, 'getName') ? $reflectionType->getName() : (string) $reflectionType;
|
||||||
$nullable = $reflectionType->allowsNull();
|
$nullable = $reflectionType->allowsNull();
|
||||||
|
|
||||||
if ($reflectionType->isBuiltin()) {
|
if ($reflectionType->isBuiltin()) {
|
||||||
|
@ -94,6 +94,25 @@ class ReflectionExtractorTest extends \PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider php71TypesProvider
|
||||||
|
* @requires PHP 7.1
|
||||||
|
*/
|
||||||
|
public function testExtractPhp71Type($property, array $type = null)
|
||||||
|
{
|
||||||
|
$this->assertEquals($type, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Php71Dummy', $property, array()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function php71TypesProvider()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array('foo', array(new Type(Type::BUILTIN_TYPE_ARRAY, true, null, true))),
|
||||||
|
array('bar', array(new Type(Type::BUILTIN_TYPE_INT, true))),
|
||||||
|
array('baz', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING)))),
|
||||||
|
array('donotexist', null),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function testIsReadable()
|
public function testIsReadable()
|
||||||
{
|
{
|
||||||
$this->assertFalse($this->extractor->isReadable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'bar', array()));
|
$this->assertFalse($this->extractor->isReadable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'bar', array()));
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the Symfony package.
|
||||||
|
*
|
||||||
|
* (c) Fabien Potencier <fabien@symfony.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Symfony\Component\PropertyInfo\Tests\Fixtures;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Teoh Han Hui <teohhanhui@gmail.com>
|
||||||
|
*/
|
||||||
|
class Php71Dummy
|
||||||
|
{
|
||||||
|
public function getFoo(): ?array
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBar(?int $bar)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addBaz(string $baz)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user