10000 Merge branch '2.7' into 2.8 · symfony/symfony@68415ab · GitHub
[go: up one dir, main page]

Skip to content

Commit 68415ab

Browse files
Merge branch '2.7' into 2.8
* 2.7: [PropertyAccess] ->getValue() should be read-only [VarDumper] Fix dumping type hints for non-existing parent classes [Config] Fix XmlUtilsTest namespace [Console] [TableHelper] make it work with SymfonyStyle. Remove dead code [Routing] add query param if value is different from default Conflicts: src/Symfony/Component/VarDumper/Tests/Caster/ReflectionCasterTest.php
2 parents d1038c3 + 1ff12d9 commit 68415ab

File tree

12 files changed

+95
-27
lines changed

12 files changed

+95
-27
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/Console/Style/SymfonyStyle.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Symfony\Component\Console\Helper\ProgressBar;
1919
use Symfony\Component\Console\Helper\SymfonyQuestionHelper;
2020
use Symfony\Component\Console\Helper\Table;
21+
use Symfony\Component\Console\Helper\TableCell;
2122
use Symfony\Component\Console\Input\InputInterface;
2223
use Symfony\Component\Console\Output\BufferedOutput;
2324
use Symfony\Component\Console\Output\OutputInterface;
@@ -213,7 +214,16 @@ public function caution($message)
213214
*/
214215
public function table(array $headers, array $rows)
215216
{
216-
$headers = array_map(function ($value) { return sprintf('<info>%s</>', $value); }, $headers);
217+
array_walk_recursive($headers, function (&$value) {
218+
if ($value instanceof TableCell) {
219+
$value = new TableCell(sprintf('<info>%s</>', $value), array(
220+
'colspan' => $value->getColspan(),
221+
'rowspan' => $value->getRowspan(),
222+
));
223+
} else {
224+
$value = sprintf('<info>%s</>', $value);
225+
}
226+
});
217227

218228
$table = new Table($this);
219229
$table->setHeaders($headers);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
use Symfony\Component\Console\Input\InputInterface;
4+
use Symfony\Component\Console\Output\OutputInterface;
5+
use Symfony\Component\Console\Tests\Style\SymfonyStyleWithForcedLineLength;
6+
use Symfony\Component\Console\Helper\TableCell;
7+
8+
//Ensure formatting tables when using multiple headers with TableCell
9+
return function (InputInterface $input, OutputInterface $output) {
10+
$headers = array(
11+
array(new TableCell('Main table title', array('colspan' => 3))),
12+
array('ISBN', 'Title', 'Author'),
13+
);
14+
15+
$rows = array(
16+
array(
17+
'978-0521567817',
18+
'De Monarchia',
19+
new TableCell("Dante Alighieri\nspans multiple rows", array('rowspan' => 2)),
20+
),
21+
array('978-0804169127', 'Divine Comedy'),
22+
);
23+
24+
$output = new SymfonyStyleWithForcedLineLength($input, $output);
25+
$output->table($headers, $rows);
26+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---------------- --------------- ---------------------
2+
Main table title
3+
---------------- --------------- ---------------------
4+
ISBN Title Author
5+
---------------- --------------- ---------------------
6+
978-0521567817 De Monarchia Dante Alighieri
7+
978-0804169127 Divine Comedy spans multiple rows
8+
---------------- --------------- ---------------------
9+

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
@@ -285,7 +285,10 @@ protected function doGenerate($variables, $defaults, $requirements, $tokens, $pa
285285
}
286286

287287
// add a query string if needed
288-
$extra = array_diff_key($parameters, $variables, $defaults);
288+
$extra = array_udiff_assoc(array_diff_key($parameters, $variables), $defaults, function ($a, $b) {
289+
return $a == $b ? 0 : 1;
290+
});
291+
289292
if ($extra && $query = http_build_query($extra, '', '&')) {
290293
// "/" and "?" can be left decoded for better user experience, see
291294
// 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

src/Symfony/Component/Serializer/Serializer.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,15 +250,6 @@ private function denormalizeObject($data, $class, $format, array $context = arra
250250
return $normalizer->denormalize($data, $class, $format, $context);
251251
}
252252

253-
foreach ($this->normalizers as $normalizer) {
254-
if (
255-
$normalizer instanceof DenormalizerInterface &&
256-
$normalizer->supportsDenormalization($data, $class, $format)
257-
) {
258-
return $normalizer->denormalize($data, $class, $format, $context);
259-
}
260-
}
261-
262253
throw new UnexpectedValueException(sprintf('Could not denormalize object of type %s, no supporting normalizer found.', $class));
263254
}
264255

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

Lines changed: 5 additions & 6 deletions
< F438 col width="44"/>
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,11 @@ public static function castParameter(\ReflectionParameter $c, array $a, Stub $st
231231
if ($c->hasType()) {
232232
$a[$prefix.'typeHint'] = $c->getType()->__toString();
233233
}
234-
} elseif ($c->isArray()) {
235-
$a[$prefix.'typeHint'] = 'array';
236-
} elseif (method_exists($c, 'isCallable') && $c->isCallable()) {
237-
$a[$prefix.'typeHint'] = 'callable';
238-
} elseif ($v = $c->getClass()) {
239-
$a[$prefix.'typeHint'] = $v->name;
234+
} else {
235+
$v = explode(' ', $c->__toString(), 6);
236+
if (isset($v[5]) && 0 === strspn($v[4], '.&$')) {
237+
$a[$prefix.'typeHint'] = $v[4];
238+
}
240239
}
241240
} catch (\ReflectionException $e) {
242241
if (preg_match('/^Class ([^ ]++) does not exist$/', $e->getMessage(), $m)) {

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\VarDumper\Test\VarDumperTestCase;
1515
use Symfony\Component\VarDumper\Tests\Fixtures\GeneratorDemo;
16+
use Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass;
1617

1718
/**
1819
* @author Nicolas Grekas <p@tchwork.com>
@@ -47,7 +48,7 @@ public function testReflectionCaster()
4748
"export" => ReflectionMethod {
4849
+name: "export"
4950
+class: "ReflectionClass"
50-
parameters: {
51+
%A parameters: {
5152
$%s: ReflectionParameter {
5253
%A position: 0
5354
%A
@@ -73,7 +74,7 @@ public function testClosureCaster()
7374
\$b: & 123
7475
}
7576
file: "%sReflectionCasterTest.php"
76-
line: "63 to 63"
77+
line: "64 to 64"
7778
}
7879
EOTXT
7980
, $var
@@ -89,7 +90,7 @@ public function testReflectionParameter()
8990
ReflectionParameter {
9091
+name: "arg1"
9192
position: 0
92-
typeHint: "Symfony\Component\VarDumper\Tests\Caster\NotExistingClass"
93+
typeHint: "Symfony\Component\VarDumper\Tests\Fixtures\NotLoadableClass"
9394
default: null
9495
}
9596
EOTXT
@@ -221,6 +222,6 @@ public function testGenerator()
221222
}
222223
}
223224

224-
function reflectionParameterFixture(NotExistingClass $arg1 = null, $arg2)
225+
function reflectionParameterFixture(NotLoadableClass $arg1 = null, $arg2)
225226
{
226227
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
namespace Symfony\Component\VarDumper\Tests\Fixtures;
4+
5+
class NotLoadableClass extends NotLoadableClass
6+
{
7+
}

0 commit comments

Comments
 (0)
0