Skip to content

Commit b92168c

Browse files
bug #35702 [VarDumper] fixed DateCaster not displaying additional fields (Makdessi Alex)
This PR was merged into the 3.4 branch. Discussion ---------- [VarDumper] fixed DateCaster not displaying additional fields | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #35699 | License | MIT | Doc PR | ~ ---- Here's the result with [Holiday](https://github.com/azuyalabs/yasumi/blob/develop/src/Yasumi/Holiday.php) class | before | after | ------- | ----- | ![before](https://user-images.githubusercontent.com/4425529/74445818-48f03d00-4e77-11ea-97e1-58d88ac52cba.png) | ![after](https://user-images.githubusercontent.com/4425529/74445825-4c83c400-4e77-11ea-8e8e-1fbbb1040438.png) Commits ------- f965971 [VarDumper] fixed DateCaster not displaying additional fields
2 parents 1a51d34 + f965971 commit b92168c

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

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

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

34-
$a = [];
34+
unset(
35+
$a[Caster::PREFIX_DYNAMIC.'date'],
36+
$a[Caster::PREFIX_DYNAMIC.'timezone'],
37+
$a[Caster::PREFIX_DYNAMIC.'timezone_type']
38+
);
3539
$a[$prefix.'date'] = new ConstStub(self::formatDateTime($d, $location ? ' e (P)' : ' P'), $title);
3640

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

src/Symfony/Component/VarDumper/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 <danymaillard93b@gmail.com>
@@ -55,7 +56,7 @@ public function testCastDateTime($time, $timezone, $xDate, $xTimestamp, $xInfos)
5556

5657
$stub = new Stub();
5758
$date = new \DateTime($time, new \DateTimeZone($timezone));
58-
$cast = DateCaster::castDateTime($date, ['foo' => 'bar'], $stub, false, 0);
59+
$cast = DateCaster::castDateTime($date, Caster::castObject($date, \DateTime::class), $stub, false, 0);
5960

6061
$xDump = <<<EODUMP
6162
array:1 [
@@ -97,6 +98,40 @@ public function provideDateTimes()
9798
];
9899
}
99100

101+
public function testCastDateTimeWithAdditionalChildProperty()
102+
{
103+
$stub = new Stub();
104+
$date = new DateTimeChild('2020-02-13 00:00:00.123456', new \DateTimeZone('Europe/Paris'));
105+
$objectCast = Caster::castObject($date, DateTimeChild::class);
106+
$dateCast = DateCaster::castDateTime($date, $objectCast, $stub, false, 0);
107+
108+
$xDate = '2020-02-13 00:00:00.123456 Europe/Paris (+01:00)';
109+
$xInfo = 'Thursday, February 13, 2020%Afrom now';
110+
$xDump = <<<EODUMP
111+
array:2 [
112+
"\\x00Symfony\Component\VarDumper\Tests\Fixtures\DateTimeChild\\x00addedProperty" => "foo"
113+
"\\x00~\\x00date" => $xDate
114+
]
115+
EODUMP;
116+
117+
$this->assertDumpEquals($xDump, $dateCast);
118+
119+
$xDump = <<<EODUMP
120+
Symfony\Component\VarDumper\Caster\ConstStub {
121+
+type: 1
122+
+class: "$xDate"
123+
+value: "%A$xInfo%A"
124+
+cut: 0
125+
+handle: 0
126+
+refCount: 0
127+
+position: 0
128+
+attr: []
129+
}
130+
EODUMP;
131+
132+
$this->assertDumpMatchesFormat($xDump, $dateCast["\0~\0date"]);
133+
}
134+
100135
/**
101136
* @dataProvider provideIntervals
102137
*/
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy