Skip to content

Commit 9fdb5d4

Browse files
committed
Fix minors in date caster
1 parent fea348c commit 9fdb5d4

File tree

2 files changed

+35
-31
lines changed

2 files changed

+35
-31
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public static function castDateTime(\DateTimeInterface $d, array $a, Stub $stub,
2727
$fromNow = (new \DateTime())->diff($d);
2828

2929
$title = $d->format('l, F j, Y')
30-
."\n".$fromNow->format('%R').self::formatInterval($fromNow).' from now'
30+
."\n".self::formatInterval($fromNow).' from now'
3131
.($location ? ($d->format('I') ? "\nDST On" : "\nDST Off") : '')
3232
;
3333

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

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class DateCasterTest extends TestCase
2727
/**
2828
* @dataProvider provideDateTimes
2929
*/
30-
public function testDumpDateTime($time, $timezone, $expected)
30+
public function testDumpDateTime($time, $timezone, $xDate, $xTimestamp)
3131
{
3232
if ((defined('HHVM_VERSION_ID') || PHP_VERSION_ID <= 50509) && preg_match('/[-+]\d{2}:\d{2}/', $timezone)) {
3333
$this->markTestSkipped('DateTimeZone GMT offsets are supported since 5.5.10. See https://github.com/facebook/hhvm/issues/5875 for HHVM.');
@@ -36,37 +36,40 @@ public function testDumpDateTime($time, $timezone, $expected)
3636
$date = new \DateTime($time, new \DateTimeZone($timezone));
3737

3838
$xDump = <<<EODUMP
39-
DateTime @1493503200 {
40-
date: $expected
39+
DateTime @$xTimestamp {
40+
date: $xDate
4141
}
4242
EODUMP;
4343

44-
$this->assertDumpMatchesFormat($xDump, $date);
44+
$this->assertDumpEquals($xDump, $date);
4545
}
4646

47-
public function testCastDateTime()
47+
/**
48+
* @dataProvider provideDateTimes
49+
*/
50+
public function testCastDateTime($time, $timezone, $xDate, $xTimestamp, $xInfos)
4851
{
52+
if ((defined('HHVM_VERSION_ID') || PHP_VERSION_ID <= 50509) && preg_match('/[-+]\d{2}:\d{2}/', $timezone)) {
53+
$this->markTestSkipped('DateTimeZone GMT offsets are supported since 5.5.10. See https://github.com/facebook/hhvm/issues/5875 for HHVM.');
54+
}
55+
4956
$stub = new Stub();
50-
$date = new \DateTime('2017-08-30 00:00:00.000000', new \DateTimeZone('Europe/Zurich'));
57+
$date = new \DateTime($time, new \DateTimeZone($timezone));
5158
$cast = DateCaster::castDateTime($date, array('foo' => 'bar'), $stub, false, 0);
5259

53-
$xDump = <<<'EODUMP'
60+
$xDump = <<<EODUMP
5461
array:1 [
55-
"\x00~\x00date" => 2017-08-30 00:00:00.0 Europe/Zurich (+02:00)
62+
"\\x00~\\x00date" => $xDate
5663
]
5764
EODUMP;
5865

59-
$this->assertDumpMatchesFormat($xDump, $cast);
66+
$this->assertDumpEquals($xDump, $cast);
6067

61-
$xDump = <<<'EODUMP'
68+
$xDump = <<<EODUMP
6269
Symfony\Component\VarDumper\Caster\ConstStub {
6370
+type: 1
64-
+class: "2017-08-30 00:00:00.0 Europe/Zurich (+02:00)"
65-
+value: """
66-
Wednesday, August 30, 2017\n
67-
+%a from now\n
68-
DST On
69-
"""
71+
+class: "$xDate"
72+
+value: "%A$xInfos%A"
7073
+cut: 0
7174
+handle: 0
7275
+refCount: 0
@@ -81,15 +84,16 @@ public function testCastDateTime()
8184
public function provideDateTimes()
8285
{
8386
return array(
84-
array('2017-04-30 00:00:00.000000', 'Europe/Zurich', '2017-04-30 00:00:00.0 Europe/Zurich (+02:00)'),
85-
array('2017-04-30 00:00:00.000000', '+02:00', '2017-04-30 00:00:00.0 +02:00'),
86-
87-
array('2017-04-30 00:00:00.100000', '+02:00', '2017-04-30 00:00:00.100 +02:00'),
88-
array('2017-04-30 00:00:00.120000', '+02:00', '2017-04-30 00:00:00.120 +02:00'),
89-
array('2017-04-30 00:00:00.123000', '+02:00', '2017-04-30 00:00:00.123 +02:00'),
90-
array('2017-04-30 00:00:00.123400', '+02:00', '2017-04-30 00:00:00.123400 +02:00'),
91-
array('2017-04-30 00:00:00.123450', '+02:00', '2017-04-30 00:00:00.123450 +02:00'),
92-
array('2017-04-30 00:00:00.123456', '+02:00', '2017-04-30 00:00:00.123456 +02:00'),
87+
array('2017-04-30 00:00:00.000000', 'Europe/Zurich', '2017-04-30 00:00:00.0 Europe/Zurich (+02:00)', 1493503200, 'Sunday, April 30, 2017%Afrom now%ADST On'),
88+
array('2017-12-31 00:00:00.000000', 'Europe/Zurich', '2017-12-31 00:00:00.0 Europe/Zurich (+01:00)', 1514674800, 'Sunday, December 31, 2017%Afrom now%ADST Off'),
89+
array('2017-04-30 00:00:00.000000', '+02:00', '2017-04-30 00:00:00.0 +02:00', 1493503200, 'Sunday, April 30, 2017%Afrom now'),
90+
91+
array('2017-04-30 00:00:00.100000', '+00:00', '2017-04-30 00:00:00.100 +00:00', 1493510400, 'Sunday, April 30, 2017%Afrom now'),
92+
array('2017-04-30 00:00:00.120000', '+00:00', '2017-04-30 00:00:00.120 +00:00', 1493510400, 'Sunday, April 30, 2017%Afrom now'),
93+
array('2017-04-30 00:00:00.123000', '+00:00', '2017-04-30 00:00:00.123 +00:00', 1493510400, 'Sunday, April 30, 2017%Afrom now'),
94+
array('2017-04-30 00:00:00.123400', '+00:00', '2017-04-30 00:00:00.123400 +00:00', 1493510400, 'Sunday, April 30, 2017%Afrom now'),
95+
array('2017-04-30 00:00:00.123450', '+00:00', '2017-04-30 00:00:00.123450 +00:00', 1493510400, 'Sunday, April 30, 2017%Afrom now'),
96+
array('2017-04-30 00:00:00.123456', '+00:00', '2017-04-30 00:00:00.123456 +00:00', 1493510400, 'Sunday, April 30, 2017%Afrom now'),
9397
);
9498
}
9599

@@ -124,7 +128,7 @@ public function testDumpIntervalExcludingVerbosity($intervalSpec, $invert, $expe
124128
}
125129
EODUMP;
126130

127-
$this->assertDumpMatchesFormat($xDump, $interval, Caster::EXCLUDE_VERBOSE);
131+
$this->assertDumpEquals($xDump, $interval, Caster::EXCLUDE_VERBOSE);
128132
}
129133

130134
/**
@@ -144,7 +148,7 @@ public function testCastInterval($intervalSpec, $invert, $xInterval, $xSeconds)
144148
]
145149
EODUMP;
146150

147-
$this->assertDumpMatchesFormat($xDump, $cast);
151+
$this->assertDumpEquals($xDump, $cast);
148152

149153
if (null === $xSeconds) {
150154
return;
@@ -163,7 +167,7 @@ public function testCastInterval($intervalSpec, $invert, $xInterval, $xSeconds)
163167
}
164168
EODUMP;
165169

166-
$this->assertDumpMatchesFormat($xDump, $cast["\0~\0interval"]);
170+
$this->assertDumpEquals($xDump, $cast["\0~\0interval"]);
167171
}
168172

169173
public function provideIntervals()
@@ -229,7 +233,7 @@ public function testDumpTimeZoneExcludingVerbosity($timezone, $expected)
229233
}
230234
EODUMP;
231235

232-
$this->assertDumpMatchesFormat($xDump, $timezone, Caster::EXCLUDE_VERBOSE);
236+
$this->assertDumpEquals($xDump, $timezone, Caster::EXCLUDE_VERBOSE);
233237
}
234238

235239
/**
@@ -252,7 +256,7 @@ public function testCastTimeZone($timezone, $xTimezone, $xRegion)
252256
]
253257
EODUMP;
254258

255-
$this->assertDumpMatchesFormat($xDump, $cast);
259+
$this->assertDumpEquals($xDump, $cast);
256260

257261
$xDump = <<<EODUMP
258262
Symfony\Component\VarDumper\Caster\ConstStub {

0 commit comments

Comments
 (0)