Skip to content

Commit d6c3651

Browse files
minor symfony#61537 [Validator] Skip tests using unavailable timezone on the local host (nicolas-grekas)
This PR was merged into the 6.4 branch. Discussion ---------- [Validator] Skip tests using unavailable timezone on the local host | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT Commits ------- 6236268 [Validator] Skip tests using unavailable timezone on the local host
2 parents 89c0360 + 6236268 commit d6c3651

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

src/Symfony/Component/Serializer/Tests/Normalizer/DateTimeNormalizerTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ public function testNormalizeUsingFormatPassedInConstructor()
5454

5555
public function testNormalizeUsingTimeZonePassedInConstructor()
5656
{
57-
$normalizer = new DateTimeNormalizer([DateTimeNormalizer::TIMEZONE_KEY => new \DateTimeZone('Japan')]);
57+
$normalizer = new DateTimeNormalizer([DateTimeNormalizer::TIMEZONE_KEY => new \DateTimeZone('Asia/Tokyo')]);
5858

59-
$this->assertSame('2016-12-01T00:00:00+09:00', $normalizer->normalize(new \DateTimeImmutable('2016/12/01', new \DateTimeZone('Japan'))));
59+
$this->assertSame('2016-12-01T00:00:00+09:00', $normalizer->normalize(new \DateTimeImmutable('2016/12/01', new \DateTimeZone('Asia/Tokyo'))));
6060
$this->assertSame('2016-12-01T09:00:00+09:00', $normalizer->normalize(new \DateTimeImmutable('2016/12/01', new \DateTimeZone('UTC'))));
6161
}
6262

@@ -73,9 +73,9 @@ public function testNormalizeUsingTimeZonePassedInContext($expected, $input, $ti
7373
public static function normalizeUsingTimeZonePassedInContextProvider()
7474
{
7575
yield ['2016-12-01T00:00:00+00:00', new \DateTimeImmutable('2016/12/01', new \DateTimeZone('UTC')), null];
76-
yield ['2016-12-01T00:00:00+09:00', new \DateTimeImmutable('2016/12/01', new \DateTimeZone('Japan')), new \DateTimeZone('Japan')];
77-
yield ['2016-12-01T09:00:00+09:00', new \DateTimeImmutable('2016/12/01', new \DateTimeZone('UTC')), new \DateTimeZone('Japan')];
78-
yield ['2016-12-01T09:00:00+09:00', new \DateTime('2016/12/01', new \DateTimeZone('UTC')), new \DateTimeZone('Japan')];
76+
yield ['2016-12-01T00:00:00+09:00', new \DateTimeImmutable('2016/12/01', new \DateTimeZone('Asia/Tokyo')), new \DateTimeZone('Asia/Tokyo')];
77+
yield ['2016-12-01T09:00:00+09:00', new \DateTimeImmutable('2016/12/01', new \DateTimeZone('UTC')), new \DateTimeZone('Asia/Tokyo')];
78+
yield ['2016-12-01T09:00:00+09:00', new \DateTime('2016/12/01', new \DateTimeZone('UTC')), new \DateTimeZone('Asia/Tokyo')];
7979
}
8080

8181
/**
@@ -139,7 +139,7 @@ public static function normalizeUsingTimeZonePassedInContextAndExpectedFormatWit
139139
'2018-12-01T18:03:06.067634',
140140
new \DateTimeZone('UTC')
141141
),
142-
new \DateTimeZone('Europe/Kiev'),
142+
new \DateTimeZone('Europe/Kyiv'),
143143
];
144144

145145
yield [
@@ -181,7 +181,7 @@ public function testDenormalize()
181181

182182
public function testDenormalizeUsingTimezonePassedInConstructor()
183183
{
184-
$timezone = new \DateTimeZone('Japan');
184+
$timezone = new \DateTimeZone('Asia/Tokyo');
185185
$expected = new \DateTimeImmutable('2016/12/01 17:35:00', $timezone);
186186
$normalizer = new DateTimeNormalizer([DateTimeNormalizer::TIMEZONE_KEY => $timezone]);
187187

@@ -214,18 +214,18 @@ public static function denormalizeUsingTimezonePassedInContextProvider()
214214
{
215215
yield 'with timezone' => [
216216
'2016/12/01 17:35:00',
217-
new \DateTimeImmutable('2016/12/01 17:35:00', new \DateTimeZone('Japan')),
218-
new \DateTimeZone('Japan'),
217+
new \DateTimeImmutable('2016/12/01 17:35:00', new \DateTimeZone('Asia/Tokyo')),
218+
new \DateTimeZone('Asia/Tokyo'),
219219
];
220220
yield 'with timezone as string' => [
221221
'2016/12/01 17:35:00',
222-
new \DateTimeImmutable('2016/12/01 17:35:00', new \DateTimeZone('Japan')),
223-
'Japan',
222+
new \DateTimeImmutable('2016/12/01 17:35:00', new \DateTimeZone('Asia/Tokyo')),
223+
'Asia/Tokyo',
224224
];
225225
yield 'with format without timezone information' => [
226226
'2016.12.01 17:35:00',
227-
new \DateTimeImmutable('2016/12/01 17:35:00', new \DateTimeZone('Japan')),
228-
new \DateTimeZone('Japan'),
227+
new \DateTimeImmutable('2016/12/01 17:35:00', new \DateTimeZone('Asia/Tokyo')),
228+
new \DateTimeZone('Asia/Tokyo'),
229229
'Y.m.d H:i:s',
230230
];
231231
yield 'ignored with format with timezone information' => [

src/Symfony/Component/Validator/Tests/Constraints/TimezoneValidatorTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,11 @@ public function testGroupedTimezonesWithInvalidCountry()
274274
*/
275275
public function testDeprecatedTimezonesAreValidWithBC(string $timezone)
276276
{
277+
// Skip test if the timezone is not available in the current timezone database
278+
if (!\in_array($timezone, \DateTimeZone::listIdentifiers(\DateTimeZone::ALL_WITH_BC), true)) {
279+
$this->markTestSkipped(sprintf('Timezone "%s" is not available in the current timezone database', $timezone));
280+
}
281+
277282
$constraint = new Timezone(\DateTimeZone::ALL_WITH_BC);
278283

279284
$this->validator->validate($timezone, $constraint);

0 commit comments

Comments
 (0)