Skip to content

Commit 15bb452

Browse files
minor #18098 [Yaml] Fix tests (nicolas-grekas)
This PR was merged into the 3.1-dev branch. Discussion ---------- [Yaml] Fix tests | Q | A | ------------- | --- | Branch | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | no | Fixed tickets | #18093 | License | MIT | Doc PR | - `now` contains a TZ info (the current default TZ), so that the following ignores the injected TZ: `new \DateTime('now', new \DateTimeZone('UTC'))` An other fix is that since PHP 5.5.14, timestamps contains sub-seconds numbers that where previously ignore. This fixes both issues. Commits ------- 25677fe [Yaml] Fix tests
2 parents fe012e8 + 25677fe commit 15bb452

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/Symfony/Component/Yaml/Inline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ private static function evaluateScalar($scalar, $flags, $references = array())
588588
return (float) str_replace(',', '', $scalar);
589589
case preg_match(self::getTimestampRegex(), $scalar):
590590
if (Yaml::PARSE_DATETIME & $flags) {
591-
return new \DateTime($scalar,new \DateTimeZone('UTC'));
591+
return new \DateTime($scalar, new \DateTimeZone('UTC'));
592592
}
593593

594594
$timeZone = date_default_timezone_get();

src/Symfony/Component/Yaml/Tests/InlineTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,8 @@ public function testParseTimestampAsUnixTimestampByDefault($yaml, $year, $month,
495495
*/
496496
public function testParseTimestampAsDateTimeObject($yaml, $year, $month, $day, $hour, $minute, $second)
497497
{
498-
$expected = new \DateTime('now', new \DateTimeZone('UTC'));
498+
$expected = new \DateTime($yaml);
499+
$expected->setTimeZone(new \DateTimeZone('UTC'));
499500
$expected->setDate($year, $month, $day);
500501
$expected->setTime($hour, $minute, $second);
501502

0 commit comments

Comments
 (0)