Skip to content

Commit

Permalink
Fix timezone unit test issue and add format test (#1043)
Browse files Browse the repository at this point in the history
* Fix timestamp timezone in tests

* Set timezone for snippets
  • Loading branch information
jdpedrie committed May 8, 2018
1 parent a5b5886 commit 261fa81
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Core/snippet-bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
use Google\Cloud\Core\Testing\TestHelpers;

TestHelpers::snippetBootstrap();

date_default_timezone_set('UTC');
24 changes: 24 additions & 0 deletions Core/tests/Unit/TimestampTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,28 @@ public function timestampArrays()
]
];
}

/**
* @dataProvider timezones
*/
public function testTimezones($tz)
{
$time = new \DateTimeImmutable('now', new \DateTimeZone($tz));
$timestamp = new Timestamp($time);

$utc = $time->setTimeZone(new \DateTimeZone('UTC'));
$utcTs = new Timestamp($utc);

$this->assertEquals($utcTs->formatAsString(), $timestamp->formatAsString());
}

public function timezones()
{
return [
['America/Detroit'],
['Australia/Sydney'],
['Pacific/Guam'],
['Africa/Johannesburg'],
];
}
}
3 changes: 3 additions & 0 deletions Core/unit-bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

date_default_timezone_set('UTC');
4 changes: 3 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true">
<phpunit
bootstrap="./Core/unit-bootstrap.php"
colors="true">
<testsuites>
<testsuite>
<directory>*/tests/Unit</directory>
Expand Down

0 comments on commit 261fa81

Please sign in to comment.