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
-------
f965971919
[VarDumper] fixed DateCaster not displaying additional fields
This commit is contained in:
commit
b92168c110
@ -31,7 +31,11 @@ class DateCaster
|
||||
.($location ? ($d->format('I') ? "\nDST On" : "\nDST Off") : '')
|
||||
;
|
||||
|
||||
$a = [];
|
||||
unset(
|
||||
$a[Caster::PREFIX_DYNAMIC.'date'],
|
||||
$a[Caster::PREFIX_DYNAMIC.'timezone'],
|
||||
$a[Caster::PREFIX_DYNAMIC.'timezone_type']
|
||||
);
|
||||
$a[$prefix.'date'] = new ConstStub(self::formatDateTime($d, $location ? ' e (P)' : ' P'), $title);
|
||||
|
||||
$stub->class .= $d->format(' @U');
|
||||
|
@ -16,6 +16,7 @@ use Symfony\Component\VarDumper\Caster\Caster;
|
||||
use Symfony\Component\VarDumper\Caster\DateCaster;
|
||||
use Symfony\Component\VarDumper\Cloner\Stub;
|
||||
use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
|
||||
use Symfony\Component\VarDumper\Tests\Fixtures\DateTimeChild;
|
||||
|
||||
/**
|
||||
* @author Dany Maillard <danymaillard93b@gmail.com>
|
||||
@ -55,7 +56,7 @@ EODUMP;
|
||||
|
||||
$stub = new Stub();
|
||||
$date = new \DateTime($time, new \DateTimeZone($timezone));
|
||||
$cast = DateCaster::castDateTime($date, ['foo' => 'bar'], $stub, false, 0);
|
||||
$cast = DateCaster::castDateTime($date, Caster::castObject($date, \DateTime::class), $stub, false, 0);
|
||||
|
||||
$xDump = <<<EODUMP
|
||||
array:1 [
|
||||
@ -97,6 +98,40 @@ EODUMP;
|
||||
];
|
||||
}
|
||||
|
||||
public function testCastDateTimeWithAdditionalChildProperty()
|
||||
{
|
||||
$stub = new Stub();
|
||||
$date = new DateTimeChild('2020-02-13 00:00:00.123456', new \DateTimeZone('Europe/Paris'));
|
||||
$objectCast = Caster::castObject($date, DateTimeChild::class);
|
||||
$dateCast = DateCaster::castDateTime($date, $objectCast, $stub, false, 0);
|
||||
|
||||
$xDate = '2020-02-13 00:00:00.123456 Europe/Paris (+01:00)';
|
||||
$xInfo = 'Thursday, February 13, 2020%Afrom now';
|
||||
$xDump = <<<EODUMP
|
||||
array:2 [
|
||||
"\\x00Symfony\Component\VarDumper\Tests\Fixtures\DateTimeChild\\x00addedProperty" => "foo"
|
||||
"\\x00~\\x00date" => $xDate
|
||||
]
|
||||
EODUMP;
|
||||
|
||||
$this->assertDumpEquals($xDump, $dateCast);
|
||||
|
||||
$xDump = <<<EODUMP
|
||||
Symfony\Component\VarDumper\Caster\ConstStub {
|
||||
+type: 1
|
||||
+class: "$xDate"
|
||||
+value: "%A$xInfo%A"
|
||||
+cut: 0
|
||||
+handle: 0
|
||||
+refCount: 0
|
||||
+position: 0
|
||||
+attr: []
|
||||
}
|
||||
EODUMP;
|
||||
|
||||
$this->assertDumpMatchesFormat($xDump, $dateCast["\0~\0date"]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideIntervals
|
||||
*/
|
||||
|
@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\VarDumper\Tests\Fixtures;
|
||||
|
||||
class DateTimeChild extends \DateTime
|
||||
{
|
||||
private $addedProperty = 'foo';
|
||||
}
|
Reference in New Issue
Block a user