8000 Merge branch '2.8' into 3.2 · symfony/symfony@a280e81 · GitHub
[go: up one dir, main page]

Skip to content

Commit a280e81

Browse files
Merge branch '2.8' into 3.2
* 2.8: [DI] use assertStringEqualsFile when possible [VarDumper] Adapt to php 7.2 changes [Form][TwigBridge] Don't render _method in form_rest() for a child form [DoctrineBridge][PropertyInfo] Added support for Doctrine Embeddables [Validator] Fix IbanValidator for ukrainian IBANs
2 parents a3f8fb0 + 17670e4 commit a280e81

File tree

11 files changed

+163
-19
lines changed

11 files changed

+163
-19
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,17 @@ public function getProperties($class, array $context = array())
5050
return;
5151
}
5252

53-
return array_merge($metadata->getFieldNames(), $metadata->getAssociationNames());
53+
$properties = array_merge($metadata->getFieldNames(), $metadata->getAssociationNames());
54+
55+
if ($metadata instanceof ClassMetadataInfo && class_exists('Doctrine\ORM\Mapping\Embedded') && $metadata->embeddedClasses) {
56+
$properties = array_filter($properties, function ($property) {
57+
return false === strpos($property, '.');
58+
});
59+
60+
$properties = array_merge($properties, array_keys($metadata->embeddedClasses));
61+
}
62+
63+
return $properties;
5464
}
5565

5666
/**
@@ -105,6 +115,10 @@ public function getTypes($class, $property, array $context = array())
105115
));
106116
}
107117

118+
if ($metadata instanceof ClassMetadataInfo && class_exists('Doctrine\ORM\Mapping\Embedded') && isset($metadata->embeddedClasses[$property])) {
119+
return array(new Type(Type::BUILTIN_TYPE_OBJECT, false, $metadata->embeddedClasses[$property]['class']));
120+
}
121+
108122
if ($metadata->hasField($property)) {
109123
$typeOfField = $metadata->getTypeOfField($property);
110124
$nullable = $metadata instanceof ClassMetadataInfo && $metadata->isNullable($property);

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,21 @@ public function testGetProperties()
6464
);
6565
}
6666

67+
public function testGetPropertiesWithEmbedded()
68+
{
69+
if (!class_exists('Doctrine\ORM\Mapping\Embedded')) {
70+
$this->markTestSkipped('@Embedded is not available in Doctrine ORM lower than 2.5.');
71+
}
72+
73+
$this->assertEquals(
74+
array(
75+
'id',
76+
'embedded',
77+
),
78+
$this->extractor->getProperties('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineWithEmbedded')
79+
);
80+
}
81+
6782
/**
6883
* @dataProvider typesProvider
6984
*/
@@ -72,6 +87,27 @@ public function testExtract($property, array $type = null)
7287
$this->assertEquals($type, $this->extractor->getTypes('Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineDummy', $property, array()));
7388
}
7489

90+
public function testExtractWithEmbedded()
91+
{
92+
if (!class_exists('Doctrine\ORM\Mapping\Embedded')) {
93+
$this->markTestSkipped('@Embedded is not available in Doctrine ORM lower than 2.5.');
94+
}
95+
96+
$expectedTypes = array(new Type(
97+
Type::BUILTIN_TYPE_OBJECT,
98+
false,
99+
'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineEmbeddable'
100+
));
101+
102+
$actualTypes = $this->extractor->getTypes(
103+
'Symfony\Bridge\Doctrine\Tests\PropertyInfo\Fixtures\DoctrineWithEmbedded',
104+
'embedded',
105+
array()
106+
);
107+
108+
$this->assertEquals($expectedTypes, $actualTypes);
109+
}
110+
75111
public function typesProvider()
76112
{
77113
return array(
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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\Bridge\Doctrine\Tests\PropertyInfo\Fixtures;
13+
14+
use Doctrine\ORM\Mapping\Column;
15+
use Doctrine\ORM\Mapping\Embeddable;
16+
17+
/**
18+
* @Embeddable
19+
*
20+
* @author Udaltsov Valentin <udaltsov.valentin@gmail.com>
21+
*/
22+
class DoctrineEmbeddable
23+
{
24+
/**
25+
* @Column(type="string")
26+
*/
27+
protected $field;
28+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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\Bridge\Doctrine\Tests\PropertyInfo\Fixtures;
13+
14+
use Doctrine\ORM\Mapping\Column;
15+
use Doctrine\ORM\Mapping\Entity;
16+
use Doctrine\ORM\Mapping\Id;
17+
use Doctrine\ORM\Mapping\Embedded;
18+
19+
/**
20+
* @Entity
21+
*
22+
* @author Udaltsov Valentin <udaltsov.valentin@gmail.com>
23+
*/
24+
class DoctrineWithEmbedded
25+
{
26+
/**
27+
* @Id
28+
* @Column(type="smallint")
29+
*/
30+
public $id;
31+
32+
/**
33+
* @Embedded(class="DoctrineEmbeddable")
34+
*/
35+
protected $embedded;
36+
}

src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@
322322
{% endif %}
323323
{%- endfor %}
324324

325-
{% if not form.methodRendered %}
325+
{% if not form.methodRendered and form.parent is null %}
326326
{%- do form.setMethodRendered() -%}
327327
{% set method = method|upper %}
328328
{%- if method in ["GET", "POST"] -%}

src/Symfony/Component/DependencyInjection/Tests/Dumper/PhpDumperTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ public function testAddService()
122122
// without compilation
123123
$container = include self::$fixturesPath.'/containers/container9.php';
124124
$dumper = new PhpDumper($container);
125-
$this->assertEquals(str_replace('%path%', str_replace('\\', '\\\\', self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR), file_get_contents(self::$fixturesPath.'/php/services9.php')), $dumper->dump(), '->dump() dumps services');
125+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services9.php', str_replace(str_replace('\\', '\\\\', self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR), '%path%', $dumper->dump()), '->dump() dumps services');
126126

127127
// with compilation
128128
$container = include self::$fixturesPath.'/containers/container9.php';
129129
$container->compile();
130130
$dumper = new PhpDumper($container);
131-
$this->assertEquals(str_replace('%path%', str_replace('\\', '\\\\', self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR), file_get_contents(self::$fixturesPath.'/php/services9_compiled.php')), $dumper->dump(), '->dump() dumps services');
131+
$this->assertStringEqualsFile(self::$fixturesPath.'/php/services9_compiled.php', str_replace(str_replace('\\', '\\\\', self::$fixturesPath.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR), '%path%', $dumper->dump()), '->dump() dumps services');
132132

133133
$dumper = new PhpDumper($container = new ContainerBuilder());
134134
$container->register('foo', 'FooClass')->addArgument(new \stdClass());

src/Symfony/Component/Validator/Constraints/IbanValidator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class IbanValidator extends ConstraintValidator
3333
* a BBAN (Basic Bank Account Number) which has a fixed length per country and,
3434
* included within it, a bank identifier with a fixed position and a fixed length per country
3535
*
36-
* @see http://www.swift.com/dsp/resources/documents/IBAN_Registry.pdf
36+
* @see https://www.swift.com/sites/default/files/resources/iban_registry.pdf
3737
*
3838
* @var array
3939
*/
@@ -129,7 +129,7 @@ class IbanValidator extends ConstraintValidator
129129
'TL' => 'TL\d{2}\d{3}\d{14}\d{2}', // Timor-Leste
130130
'TN' => 'TN59\d{2}\d{3}\d{13}\d{2}', // Tunisia
131131
'TR' => 'TR\d{2}\d{5}[\dA-Z]{1}[\dA-Z]{16}', // Turkey
132-
'UA' => 'UA\d{2}[A-Z]{6}[\dA-Z]{19}', // Ukraine
132+
'UA' => 'UA\d{2}\d{6}[\dA-Z]{19}', // Ukraine
133133
'VG' => 'VG\d{2}[A-Z]{4}\d{16}', // Virgin Islands, British
134134
'WF' => 'FR\d{2}\d{5}\d{5}[\dA-Z]{11}\d{2}', // Wallis and Futuna Islands
135135
'XK' => 'XK\d{2}\d{4}\d{10}\d{2}', // Republic of Kosovo

src/Symfony/Component/Validator/Tests/Constraints/IbanValidatorTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function getValidIbans()
113113

114114
//Extended country list
115115
//http://www.nordea.com/Our+services/International+products+and+services/Cash+Management/IBAN+countries/908462.html
116-
// http://www.swift.com/dsp/resources/documents/IBAN_Registry.pdf
116+
// https://www.swift.com/sites/default/files/resources/iban_registry.pdf
117117
array('AO06000600000100037131174'), //Angola
118118
array('AZ21NABZ00000000137010001944'), //Azerbaijan
119119
array('BH29BMAG1299123456BH00'), //Bahrain
@@ -151,6 +151,7 @@ public function getValidIbans()
151151
array('TL380080012345678910157'), //Timor-Leste
152152
array('TN5914207207100707129648'), //Tunisia
153153
array('TR330006100519786457841326'), //Turkey
154+
array('UA213223130000026007233566001'), //Ukraine
154155
array('AE260211000000230064016'), //United Arab Emirates
155156
);
156157
}
@@ -263,6 +264,7 @@ public function getIbansWithInvalidFormat()
263264
array('TL3800800123456789101571'), //Timor-Leste
264265
array('TN59142072071007071296481'), //Tunisia
265266
array('TR3300061005197864578413261'), //Turkey
267+
array('UA21AAAA1300000260072335660012'), //Ukraine
266268
array('AE2602110000002300640161'), //United Arab Emirates
267269
);
268270
}
@@ -372,6 +374,7 @@ public function getIbansWithValidFormatButIncorrectChecksum()
372374
array('TL380080012345678910158'), //Timor-Leste
373375
array('TN5914207207100707129649'), //Tunisia
374376
array('TR330006100519786457841327'), //Turkey
377+
array('UA213223130000026007233566002'), //Ukraine
375378
array('AE260211000000230064017'), //United Arab Emirates
376379
);
377380
}

src/Symfony/Component/VarDumper/Caster/Caster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static function castObject($obj, \ReflectionClass $reflector)
6060
$combine = false;
6161
$p = array_keys($a);
6262
foreach ($p as $i => $k) {
63-
if (isset($k[0]) && "\0" !== $k[0] && !$reflector->hasProperty($k)) {
63+
if (isset($k[0]) ? "\0" !== $k[0] && !$reflector->hasProperty($k) : \PHP_VERSION_ID >= 70200) {
6464
$combine = true;
6565
$p[$i] = self::PREFIX_DYNAMIC.$k;
6666
} elseif (isset($k[16]) && "\0" === $k[16] && 0 === strpos($k, "\0class@anonymous\0")) {

src/Symfony/Component/VarDumper/Tests/CliDumperTest.php

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,35 +139,62 @@ public function testJsonCast()
139139
$var[] = &$v;
140140
$var[''] = 2;
141141

142-
$this->assertDumpMatchesFormat(
143-
<<<'EOTXT'
142+
if (\PHP_VERSION_ID >= 70200) {
143+
$this->assertDumpMatchesFormat(
144+
<<<'EOTXT'
145+
array:4 [
146+
0 => {}
147+
1 => &1 null
148+
2 => &1 null
149+
"" => 2
150+
]
151+
EOTXT
152+
,
153+
$var
154+
);
155+
} else {
156+
$this->assertDumpMatchesFormat(
157+
<<<'EOTXT'
144158
array:4 [
145159
"0" => {}
146160
"1" => &1 null
147161
0 => &1 null
148162
"" => 2
149163
]
150164
EOTXT
151-
,
152-
$var
153-
);
165+
,
166+
$var
167+
);
168+
}
154169
}
155170

156171
public function testObjectCast()
157172
{
158173
$var = (object) array(1 => 1);
159174
$var->{1} = 2;
160175

161-
$this->assertDumpMatchesFormat(
162-
<<<'EOTXT'
176+
if (\PHP_VERSION_ID >= 70200) {
177+
$this->assertDumpMatchesFormat(
178+
<<<'EOTXT'
179+
{
180+
+"1": 2
181+
}
182+
EOTXT
183+
,
184+
$var
185+
);
186+
} else {
187+
$this->assertDumpMatchesFormat(
188+
<<<'EOTXT'
163189
{
164190
+1: 1
165191
+"1": 2
166192
}
167193
EOTXT
168-
,
169-
$var
170-
);
194+
,
195+
$var
196+
);
197+
}
171198
}
172199

173200
public function testClosedResource()

src/Symfony/Component/VarDumper/Tests/VarClonerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public function testJsonCast()
233233
EOTXT;
234234
ob_start();
235235
var_dump($clone);
236-
$this->assertStringMatchesFormat($expected, ob_get_clean());
23 5228 6+
$this->assertStringMatchesFormat(\PHP_VERSION_ID >= 70200 ? str_replace('"1"', '1', $expected) : $expected, ob_get_clean());
237237
}
238238

239239
public function testCaster()

0 commit comments

Comments
 (0)
0