Skip to content

Commit

Permalink
get timezone from string, but set locally to avoid NOTICEs
Browse files Browse the repository at this point in the history
  • Loading branch information
Harry Bragg committed Oct 5, 2015
1 parent 19a4e2c commit 5d8b309
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 24 deletions.
7 changes: 1 addition & 6 deletions src/Response/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use DateTimeImmutable;
use DateTimeInterface;
use DateTimeZone;
use GuzzleHttp\Message\ResponseInterface as GuzzleResponseInterface;
use Illuminate\Support\Collection;

Expand Down Expand Up @@ -72,11 +71,7 @@ public function __construct(GuzzleResponseInterface $response)
$this->statusCode = (int)$this->popField('statusCode');
$this->statusReason = $this->popField('statusReason');
$this->callId = $this->popField('callId');
$this->time = DateTimeImmutable::createFromFormat(
static::DATE_TIME_FORMAT,
$this->popField('time'),
new DateTimeZone('UTC')
);
$this->time = DateTimeImmutable::createFromFormat(static::DATE_TIME_FORMAT, $this->popField('time'));
}

/**
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/Response/ResponseFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace Graze\Gigya\Test\Unit\Response;

use DateTime;
use DateTimeImmutable;
use DateTimeZone;
use Graze\Gigya\Exceptions\UnknownResponseException;
use Graze\Gigya\Response\Response;
use Graze\Gigya\Response\ResponseCollectionInterface;
Expand All @@ -19,6 +17,7 @@

class ResponseFactoryTest extends TestCase
{

/**
* @var ResponseFactory
*/
Expand All @@ -29,6 +28,11 @@ class ResponseFactoryTest extends TestCase
*/
private $validator;

public static function setUpBeforeClass()
{
date_default_timezone_set('UTC');
}

public function setUp()
{
$this->validator = m::mock('Graze\Gigya\Validation\GigyaResponseValidatorInterface');
Expand Down Expand Up @@ -60,11 +64,7 @@ public function testAccountModel()
static::assertEquals("e6f891ac17f24810bee6eb533524a152", $gigyaResponse->getCallId());
static::assertInstanceOf('DateTimeInterface', $gigyaResponse->getTime());
static::assertEquals(
DateTimeImmutable::createFromFormat(
Response::DATE_TIME_FORMAT,
"2015-03-22T11:42:25.943Z",
new DateTimeZone('UTC')
),
DateTimeImmutable::createFromFormat(Response::DATE_TIME_FORMAT, "2015-03-22T11:42:25.943Z"),
$gigyaResponse->getTime()
);
$data = $gigyaResponse->getData();
Expand Down
18 changes: 7 additions & 11 deletions tests/unit/Response/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
namespace Graze\Gigya\Test\Unit\Response;

use DateTime;
use DateTimeZone;
use Graze\Gigya\Response\Response;
use Graze\Gigya\Test\TestCase;

class ResponseTest extends TestCase
{
public static function setUpBeforeClass()
{
date_default_timezone_set('UTC');
}

public function testDateFormat()
{
$time = DateTime::createFromFormat(
Response::DATE_TIME_FORMAT,
'2015-03-22T11:42:25.943Z',
new DateTimeZone('UTC')
);
$time = DateTime::createFromFormat(Response::DATE_TIME_FORMAT, '2015-03-22T11:42:25.943Z');

static::assertInstanceOf('DateTimeInterface', $time);
static::assertEquals("2015", $time->format('Y'));
Expand All @@ -30,11 +30,7 @@ public function testDateFormat()

public function testOtherTimeZoneFormat()
{
$time = DateTime::createFromFormat(
Response::DATE_TIME_FORMAT,
'2015-03-22T11:42:25.943+02:00',
new DateTimeZone('UTC')
);
$time = DateTime::createFromFormat(Response::DATE_TIME_FORMAT, '2015-03-22T11:42:25.943+02:00');

static::assertInstanceOf('DateTimeInterface', $time);
static::assertEquals("2015", $time->format('Y'));
Expand Down

0 comments on commit 5d8b309

Please sign in to comment.