Skip to content

Commit 156269d

Browse files
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
2 parents da565de + c555d64 commit 156269d

File tree

7 files changed

+66
-3
lines changed

7 files changed

+66
-3
lines changed

src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,12 @@ private function getPhpType($doctrineType)
178178
return Type::BUILTIN_TYPE_INT;
179179

180180
case DBALType::FLOAT:
181-
case DBALType::DECIMAL:
182181
return Type::BUILTIN_TYPE_FLOAT;
183182

184183
case DBALType::STRING:
185184
case DBALType::TEXT:
186185
case DBALType::GUID:
186+
case DBALType::DECIMAL:
187187
return Type::BUILTIN_TYPE_STRING;
188188

189189
case DBALType::BOOLEAN:

src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/DoctrineExtractorTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public function testGetProperties()
4949
'time',
5050
'json',
5151
'simpleArray',
52+
'float',
53+
'decimal',
5254
'bool',
5355
'binary',
5456
'customFoo',
@@ -73,6 +75,8 @@ public function typesProvider()
7375
return array(
7476
array('id', array(new Type(Type::BUILTIN_TYPE_INT))),
7577
array('guid', array(new Type(Type::BUILTIN_TYPE_STRING))),
78+
array('float', array(new Type(Type::BUILTIN_TYPE_FLOAT))),
79+
array('decimal', array(new Type(Type::BUILTIN_TYPE_STRING))),
7680
array('bool', array(new Type(Type::BUILTIN_TYPE_BOOL))),
7781
array('binary', array(new Type(Type::BUILTIN_TYPE_RESOURCE))),
7882
array('json', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true))),

src/Symfony/Bridge/Doctrine/Tests/PropertyInfo/Fixtures/DoctrineDummy.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ class DoctrineDummy
6565
*/
6666
private $simpleArray;
6767

68+
/**
69+
* @Column(type="float")
70+
*/
71+
private $float;
72+
73+
/**
74+
* @Column(type="decimal", precision=10, scale=2)
75+
*/
76+
private $decimal;
77+
6878
/**
6979
* @Column(type="boolean")
7080
*/

src/Symfony/Component/Console/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": ">=5.5.9",
2020
"symfony/polyfill-mbstring": "~1.0",
21-
"symfony/debug": "~2.7,>=2.7.2"
21+
"symfony/debug": "~2.8|~3.0"
2222
},
2323
"require-dev": {
2424
"symfony/event-dispatcher": "~2.8|~3.0",

src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ private function extractFromAccessor($class, $property)
231231
*/
232232
private function extractFromReflectionType(\ReflectionType $reflectionType)
233233
{
234-
$phpTypeOrClass = (string) $reflectionType;
234+
$phpTypeOrClass = method_exists($reflectionType, 'getName') ? $reflectionType->getName() : (string) $reflectionType;
235235
$nullable = $reflectionType->allowsNull();
236236

237237
if ($reflectionType->isBuiltin()) {

src/Symfony/Component/PropertyInfo/Tests/Extractors/ReflectionExtractorTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,25 @@ public function php7TypesProvider()
9494
);
9595
}
9696

97+
/**
98+
* @dataProvider php71TypesProvider
99+
* @requires PHP 7.1
100+
*/
101+
public function testExtractPhp71Type($property, array $type = null)
102+
{
103+
$this->assertEquals($type, $this->extractor->getTypes('Symfony\Component\PropertyInfo\Tests\Fixtures\Php71Dummy', $property, array()));
104+
}
105+
106+
public function php71TypesProvider()
107+
{
108+
return array(
109+
array('foo', array(new Type(Type::BUILTIN_TYPE_ARRAY, true, null, true))),
110+
array('bar', array(new Type(Type::BUILTIN_TYPE_INT, true))),
111+
array('baz', array(new Type(Type::BUILTIN_TYPE_ARRAY, false, null, true, new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING)))),
112+
array('donotexist', null),
113+
);
114+
}
115+
97116
public function testIsReadable()
98117
{
99118
$this->assertFalse($this->extractor->isReadable('Symfony\Component\PropertyInfo\Tests\Fixtures\Dummy', 'bar', array()));
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\PropertyInfo\Tests\Fixtures;
13+
14+
/**
15+
* @author Teoh Han Hui <[email protected]>
16+
*/
17+
class Php71Dummy
18+
{
19+
public function getFoo(): ?array
20+
{
21+
}
22+
23+
public function setBar(?int $bar)
24+
{
25+
}
26+
27+
public function addBaz(string $baz)
28+
{
29+
}
30+
}

0 commit comments

Comments
 (0)