Merge branch '2.8' into 3.1

* 2.8:
  Fix version constraint
  Fixed bad merge
  [DoctrineBridge][PropertyInfo] Treat Doctrine decimal type as string
  Make ReflectionExtractor compatible with ReflectionType changes in PHP 7.1
This commit is contained in:
Nicolas Grekas 2016-09-14 08:12:59 +02:00
commit 156269d1e0
7 changed files with 66 additions and 3 deletions

View File

@ -178,12 +178,12 @@ class DoctrineExtractor implements PropertyListExtractorInterface, PropertyTypeE
return Type::BUILTIN_TYPE_INT;
case DBALType::FLOAT:
case DBALType::DECIMAL:
return Type::BUILTIN_TYPE_FLOAT;
case DBALType::STRING:
case DBALType::TEXT:
case DBALType::GUID:
case DBALType::DECIMAL:
return Type::BUILTIN_TYPE_STRING;
case DBALType::BOOLEAN:

View File

@ -49,6 +49,8 @@ class DoctrineExtractorTest extends \PHPUnit_Framework_TestCase
'time',
'json',
'simpleArray',
'float',
'decimal',
'bool',
'binary',
'customFoo',
@ -73,6 +75,8 @@ class DoctrineExtractorTest extends \PHPUnit_Framework_TestCase
return array(
array('id', array(new Type(Type::BUILTIN_TYPE_INT))),
array('guid', array(new Type(Type::BUILTIN_TYPE_STRING))),
array('float', array(new Type(Type::BUILTIN_TYPE_FLOAT))),
array('decimal', array(new Type(Type::BUILTIN_TYPE_STRING))),
array('bool', array(new Type(Type::BUILTIN_TYPE_BOOL))),
array('binary', array(new Type(Type::BUILTIN_TYPE_RESOURCE))),
array('json', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true))),

View File

@ -65,6 +65,16 @@ class DoctrineDummy
*/
private $simpleArray;
/**
* @Column(type="float")
*/
private $float;
/**
* @Column(type="decimal", precision=10, scale=2)
*/
private $decimal;
/**
* @Column(type="boolean")
*/

View File

@ -18,7 +18,7 @@
"require": {
"php": ">=5.5.9",
"symfony/polyfill-mbstring": "~1.0",
"symfony/debug": "~2.7,>=2.7.2"
"symfony/debug": "~2.8|~3.0"
},
"require-dev": {
"symfony/event-dispatcher": "~2.8|~3.0",

View File

@ -231,7 +231,7 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
*/
private function extractFromReflectionType(\ReflectionType $reflectionType)
{
$phpTypeOrClass = (string) $reflectionType;
$phpTypeOrClass = method_exists($reflectionType, 'getName') ? $reflectionType->getName() : (string) $reflectionType;
$nullable = $reflectionType->allowsNull();
if ($reflectionType->isBuiltin()) {

View File

@ -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()
{
$this->assertFalse($this->extractor->isReadable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'bar', array()));

View File

@ -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)
{
}
}