Skip to content

Commit 2572839

Browse files
committed
Merge branch '3.4' into 4.4
* 3.4: [ExpressionLanguage] Fixed collisions of character operators with object properties [Validator] Remove specific check for Valid targets [PhpUnitBridge] Use trait instead of extending deprecated class fix remember me Use strict assertion in asset tests [DoctrineBridge][DoctrineExtractor] Fix indexBy with custom and some core types Do not rely on the current locale when dumping a Graphviz object fix typo [Ldap] force default network timeout [Config] don't throw on missing excluded paths Docs: Typo, grammar [Validator] Add the missing translations for the Polish ("pl") locale [Console] Inline exact-match handling with 4.4 Set previous exception when rethrown from controller resolver [VarDumper] fixed DateCaster not displaying additional fields [HttpKernel] fix registering DebugHandlersListener regardless of the PHP_SAPI
2 parents dff1cf9 + 07801f3 commit 2572839

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

Caster/DateCaster.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ public static function castDateTime(\DateTimeInterface $d, array $a, Stub $stub,
3535
.($location ? ($d->format('I') ? "\nDST On" : "\nDST Off") : '')
3636
;
3737

38-
$a = [];
38+
unset(
39+
$a[Caster::PREFIX_DYNAMIC.'date'],
40+
$a[Caster::PREFIX_DYNAMIC.'timezone'],
41+
$a[Caster::PREFIX_DYNAMIC.'timezone_type']
42+
);
3943
$a[$prefix.'date'] = new ConstStub(self::formatDateTime($d, $location ? ' e (P)' : ' P'), $title);
4044

4145
$stub->class .= $d->format(' @U');

Tests/Caster/DateCasterTest.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\VarDumper\Caster\DateCaster;
1717
use Symfony\Component\VarDumper\Cloner\Stub;
1818
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
19+
use Symfony\Component\VarDumper\Tests\Fixtures\DateTimeChild;
1920

2021
/**
2122
* @author Dany Maillard <[email protected]>
@@ -47,7 +48,7 @@ public function testCastDateTime($time, $timezone, $xDate, $xTimestamp, $xInfos)
4748
{
4849
$stub = new Stub();
4950
$date = new \DateTime($time, new \DateTimeZone($timezone));
50-
$cast = DateCaster::castDateTime($date, ['foo' => 'bar'], $stub, false, 0);
51+
$cast = DateCaster::castDateTime($date, Caster::castObject($date, \DateTime::class), $stub, false, 0);
5152

5253
$xDump = <<<EODUMP
5354
array:1 [
@@ -89,6 +90,40 @@ public function provideDateTimes()
8990
];
9091
}
9192

93+
public function testCastDateTimeWithAdditionalChildProperty()
94+
{
95+
$stub = new Stub();
96+
$date = new DateTimeChild('2020-02-13 00:00:00.123456', new \DateTimeZone('Europe/Paris'));
97+
$objectCast = Caster::castObject($date, DateTimeChild::class);
98+
$dateCast = DateCaster::castDateTime($date, $objectCast, $stub, false, 0);
99+
100+
$xDate = '2020-02-13 00:00:00.123456 Europe/Paris (+01:00)';
101+
$xInfo = 'Thursday, February 13, 2020%Afrom now';
102+
$xDump = <<<EODUMP
103+
array:2 [
104+
"\\x00Symfony\Component\VarDumper\Tests\Fixtures\DateTimeChild\\x00addedProperty" => "foo"
105+
"\\x00~\\x00date" => $xDate
106+
]
107+
EODUMP;
108+
109+
$this->assertDumpEquals($xDump, $dateCast);
110+
111+
$xDump = <<<EODUMP
112+
Symfony\Component\VarDumper\Caster\ConstStub {
113+
+type: 1
114+
+class: "$xDate"
115+
+value: "%A$xInfo%A"
116+
+cut: 0
117+
+handle: 0
118+
+refCount: 0
119+
+position: 0
120+
+attr: []
121+
}
122+
EODUMP;
123+
124+
$this->assertDumpMatchesFormat($xDump, $dateCast["\0~\0date"]);
125+
}
126+
92127
/**
93128
* @dataProvider provideIntervals
94129
*/

Tests/Fixtures/DateTimeChild.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace Symfony\Component\VarDumper\Tests\Fixtures;
4+
5+
class DateTimeChild extends \DateTime
6+
{
7+
private $addedProperty = 'foo';
8+
}

0 commit comments

Comments
 (0)