8000 Merge branch '2.3' into 2.7 · symfony/symfony@1ff12d9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1ff12d9

Browse files
Merge branch '2.3' into 2.7
* 2.3: [PropertyAccess] ->getValue() should be read-only [Config] Fix XmlUtilsTest namespace [Routing] add query param if value is different from default Conflicts: src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php
2 parents 6a0a687 + c1cb357 commit 1ff12d9

File tree

5 files changed

+32
-7
lines changed

5 files changed

+32
-7
lines changed

src/Symfony/Component/Config/Tests/Util/XmlUtilsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\Config\Tests\Loader;
12+
namespace Symfony\Component\Config\Tests\Util;
1313

1414
use Symfony\Component\Config\Util\XmlUtils;
1515

src/Symfony/Component/PropertyAccess/PropertyAccessor.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,11 @@ private function readPropertiesUntil($zval, PropertyPathInterface $propertyPath,
373373
}
374374

375375
if ($i + 1 < $propertyPath->getLength()) {
376-
$zval[self::VALUE][$property] = array();
377-
378376
if (isset($zval[self::REF])) {
377+
$zval[self::VALUE][$property] = array();
379378
$zval[self::REF] = $zval[self::VALUE];
379+
} else {
380+
$zval[self::VALUE] = array($property => array());
380381
}
381382
}
382383
}

src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ public function testGetValueReadsMagicGet()
126126
$this->assertSame('Bernhard', $this->propertyAccessor->getValue(new TestClassMagicGet('Bernhard'), 'magicProperty'));
127127
}
128128

129+
public function testGetValueReadsArrayWithMissingIndexForCustomPropertyPath()
130+
{
131+
$object = new \ArrayObject();
132+
$array = array('child' => array('index' => $object));
133+
134+
$this->assertNull($this->propertyAccessor->getValue($array, '[child][index][foo][bar]'));
135+
$this->assertSame(array(), $object->getArrayCopy());
136+
}
137+
129138
// https://github.com/symfony/symfony/pull/4450
130139
public function testGetValueReadsMagicGetThatReturnsConstant()
131140
{

src/Symfony/Component/Routing/Generator/UrlGenerator.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,10 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
271271
}
272272

273273
// add a query string if needed
274-
$extra = array_diff_key($parameters, $variables, $defaults);
274+
$extra = array_udiff_assoc(array_diff_key($parameters, $variables), $defaults, function ($a, $b) {
275+
return $a == $b ? 0 : 1;
276+
});
277+
275278
if ($extra && $query = http_build_query($extra, '', '&')) {
276279
// "/" and "?" can be left decoded for better user experience, see
277280
// http://tools.ietf.org/html/rfc3986#section-3.4

src/Symfony/Component/Routing/Tests/Generator/UrlGeneratorTest.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,22 @@ public function testNullForOptionalParameterIsIgnored()
297297

298298
public function testQueryParamSameAsDefault()
299299
{
300-
$routes = $this->getRoutes('test', new Route('/test', array('default' => 'value')));
300+
$routes = $this->getRoutes('test', new Route('/test', array('page' => 1)));
301301

302-
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('default' => 'foo')));
303-
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('default' => 'value')));
302+
$this->assertSame('/app.php/test?page=2', $this->getGenerator($routes)->generate('test', array('page' => 2)));
303+
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('page' => 1)));
304+
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('page' => '1')));
305+
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test'));
306+
}
307+
308+
public function testArrayQueryParamSameAsDefault()
309+
{
310+
$routes = $this->getRoutes('test', new Route('/test', array('array' => array('foo', 'bar'))));
311+
312+
$this->assertSame('/app.php/test?array%5B0%5D=bar&array%5B1%5D=foo', $this->getGenerator($routes)->generate('test', array('array' => array('bar', 'foo'))));
313+
$this->assertSame('/app.php/test?array%5Ba%5D=foo&array%5Bb%5D=bar', $this->getGenerator($routes)->generate('test', array('array' => array('a' => 'foo', 'b' => 'bar'))));
314+
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('array' => array('foo', 'bar'))));
315+
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test', array('array' => array(1 => 'bar', 0 => 'foo'))));
304316
$this->assertSame('/app.php/test', $this->getGenerator($routes)->generate('test'));
305317
}
306318

0 commit comments

Comments
 (0)
0