From 4a041e9a759538058c09263fb46b4100144e1a48 Mon Sep 17 00:00:00 2001 From: Teoh Han Hui Date: Mon, 5 Sep 2016 15:19:46 +0800 Subject: [PATCH 1/4] Make ReflectionExtractor compatible with ReflectionType changes in PHP 7.1 --- .../Extractor/ReflectionExtractor.php | 2 +- .../Extractors/ReflectionExtractorTest.php | 19 ++++++++++++ .../Tests/Fixtures/Php71Dummy.php | 30 +++++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php71Dummy.php diff --git a/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php b/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php index 63454a5b45..1d3d3a2083 100644 --- a/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php +++ b/src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php @@ -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()) { diff --git a/src/Symfony/Component/PropertyInfo/Tests/Extractors/ReflectionExtractorTest.php b/src/Symfony/Component/PropertyInfo/Tests/Extractors/ReflectionExtractorTest.php index dfc13c025e..10b056220d 100644 --- a/src/Symfony/Component/PropertyInfo/Tests/Extractors/ReflectionExtractorTest.php +++ b/src/Symfony/Component/PropertyInfo/Tests/Extractors/ReflectionExtractorTest.php @@ -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())); diff --git a/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php71Dummy.php b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php71Dummy.php new file mode 100644 index 0000000000..d93c67a3d3 --- /dev/null +++ b/src/Symfony/Component/PropertyInfo/Tests/Fixtures/Php71Dummy.php @@ -0,0 +1,30 @@ + + * + * 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 + */ +class Php71Dummy +{ + public function getFoo(): ?array + { + } + + public function setBar(?int $bar) + { + } + + public function addBaz(string $baz) + { + } +} From 62d28f9204870a4c258637686bb50fd9f372e3b3 Mon Sep 17 00:00:00 2001 From: Teoh Han Hui Date: Tue, 13 Sep 2016 15:40:53 +0800 Subject: [PATCH 2/4] [DoctrineBridge][PropertyInfo] Treat Doctrine decimal type as string --- .../Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php | 2 +- .../Tests/PropertyInfo/DoctrineExtractorTest.php | 4 ++++ .../Tests/PropertyInfo/Fixtures/DoctrineDummy.php | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php index 6e8c29e16b..5446887abf 100644 --- a/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php +++ b/src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php @@ -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: diff --git a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php index 1bc57b1140..2224517db6 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php @@ -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))), diff --git a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineDummy.php b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineDummy.php index 317d14257b..e6d9155704 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineDummy.php +++ b/src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineDummy.php @@ -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") */ From d30374d7eb55bd60609e3d4d05cf25906e327e3b Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Tue, 13 Sep 2016 22:12:03 +0100 Subject: [PATCH 3/4] Fixed bad merge --- src/Symfony/Component/Console/composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/composer.json b/src/Symfony/Component/Console/composer.json index 6078c4b363..bfa01d06db 100644 --- a/src/Symfony/Component/Console/composer.json +++ b/src/Symfony/Component/Console/composer.json @@ -18,7 +18,7 @@ "require": { "php": ">=5.3.9", "symfony/polyfill-mbstring": "~1.0", - "symfony/debug": "~2.7,>=2.7.2" + "symfony/debug": "~2.7,>=2.7.2|~3.0" }, "require-dev": { "symfony/event-dispatcher": "~2.1|~3.0.0", From c555d643909866d3b5ced75bba6c3c5df78ddf34 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 14 Sep 2016 08:12:49 +0200 Subject: [PATCH 4/4] Fix version constraint --- src/Symfony/Component/Console/composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Console/composer.json b/src/Symfony/Component/Console/composer.json index bfa01d06db..f0af3f214b 100644 --- a/src/Symfony/Component/Console/composer.json +++ b/src/Symfony/Component/Console/composer.json @@ -18,7 +18,7 @@ "require": { "php": ">=5.3.9", "symfony/polyfill-mbstring": "~1.0", - "symfony/debug": "~2.7,>=2.7.2|~3.0" + "symfony/debug": "~2.7,>=2.7.2|~3.0.0" }, "require-dev": { "symfony/event-dispatcher": "~2.1|~3.0.0",