Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 02d4212

Browse files
committed
[VarDumper] add caster for IntlTimeZone
1 parent a43f307 commit 02d4212

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,23 @@ public static function castNumberFormatter(\NumberFormatter $c, array $a, Stub $
106106
return self::castError($c, $a);
107107
}
108108

109+
public static function castIntlTimeZone(\IntlTimeZone $c, array $a, Stub $stub, $isNested)
110+
{
111+
$a += array(
112+
Caster::PREFIX_VIRTUAL.'display_name' => $c->getDisplayName(),
113+
Caster::PREFIX_VIRTUAL.'id' => $c->getID(),
114+
Caster::PREFIX_VIRTUAL.'raw_offset' => $c->getRawOffset(),
115+
);
116+
117+
if ($c->useDaylightTime()) {
118+
$a += array(
119+
Caster::PREFIX_VIRTUAL.'dst_savings' => $c->getDSTSavings(),
120+
);
121+
}
122+
123+
return self::castError($c, $a);
124+
}
125+
109126
private static function castError($c, array $a): array
110127
{
111128
if ($errorCode = $c->getErrorCode()) {

src/Symfony/Component/VarDumper/Cloner/AbstractCloner.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ abstract class AbstractCloner implements ClonerInterface
119119

120120
'MessageFormatter' => array('Symfony\Component\VarDumper\Caster\IntlCaster', 'castMessageFormatter'),
121121
'NumberFormatter' => array('Symfony\Component\VarDumper\Caster\IntlCaster', 'castNumberFormatter'),
122+
'IntlTimeZone' => array('Symfony\Component\VarDumper\Caster\IntlCaster', 'castIntlTimeZone'),
122123

123124
':curl' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castCurl'),
124125
':dba' => array('Symfony\Component\VarDumper\Caster\ResourceCaster', 'castDba'),

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,44 @@ public function testCastNumberFormatter()
147147
MONETARY_GROUPING_SEPARATOR_SYMBOL: "$expectedSymbol18"
148148
}
149149
}
150+
EOTXT;
151+
$this->assertDumpEquals($expected, $var);
152+
}
153+
154+
public function testCastIntlTimeZoneWithDST()
155+
{
156+
$var = \IntlTimeZone::createTimeZone('Europe/Berlin');
157+
158+
$expectedDisplayName = $var->getDisplayName();
159+
$expectedDSTSavings = $var->getDSTSavings();
160+
$expectedID = $var->getID();
161+
$expectedRawOffset = $var->getRawOffset();
162+
163+
$expected = <<<EOTXT
164+
IntlTimeZone {
165+
display_name: "$expectedDisplayName"
166+
id: "$expectedID"
167+
raw_offset: $expectedRawOffset
168+
dst_savings: $expectedDSTSavings
169+
}
170+
EOTXT;
171+
$this->assertDumpEquals($expected, $var);
172+
}
173+
174+
public function testCastIntlTimeZoneWithoutDST()
175+
{
176+
$var = \IntlTimeZone::createTimeZone('Asia/Bangkok');
177+
178+
$expectedDisplayName = $var->getDisplayName();
179+
$expectedID = $var->getID();
180+
$expectedRawOffset = $var->getRawOffset();
181+
182+
$expected = <<<EOTXT
183+
IntlTimeZone {
184+
display_name: "$expectedDisplayName"
185+
id: "$expectedID"
186+
raw_offset: $expectedRawOffset
187+
}
150188
EOTXT;
151189
$this->assertDumpEquals($expected, $var);
152190
}

0 commit comments

Comments
 (0)