Skip to content

Commit

Permalink
Merge pull request #1 from enricodias/dev
Browse files Browse the repository at this point in the history
Fixes unexpected null result in php 5.6
  • Loading branch information
enricodias authored Jan 14, 2020
2 parents 45e41b2 + 9e66d3a commit 53eea85
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 70 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ install:
script:
- php vendor/bin/phpunit

after_success:
- php vendor/bin/ocular code-coverage:upload --format=php-clover tests/_reports/logs/clover.xml

branches:
only:
- master
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
}
},
"require-dev": {
"phpunit/phpunit": ">5.7 <9"
"phpunit/phpunit": ">5.7 <9",
"scrutinizer/ocular": "^1.6"
}
}
5 changes: 5 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,9 @@
<directory suffix=".php">./tests</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="tests/_reports/logs/clover.xml"/>
<log type="coverage-html" target="tests/_reports/coverage" lowUpperBound="35" highLowerBound="70"/>
<log type="testdox-text" target="tests/_reports/testdox/executed.txt"/>
</logging>
</phpunit>
4 changes: 3 additions & 1 deletion src/SmsDev.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ private function makeRequest($request)

$response = json_decode($response->getBody(), true);

if (json_last_error() != JSON_ERROR_NONE) return false;
if (json_last_error() != JSON_ERROR_NONE || is_array($response) === false) return false;

$this->_result = $response;

Expand All @@ -231,6 +231,8 @@ private function makeRequest($request)
* This method is needed to test API calls in unit tests.
*
* @return object GuzzleHttp\Client instance.
*
* @codeCoverageIgnore
*/
protected function getGuzzleClient()
{
Expand Down
23 changes: 23 additions & 0 deletions tests/ApiRequestsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,27 @@ public function testFilterByDate()
$this->assertSame('01/01/2019', $query['date_from']);
$this->assertArrayNotHasKey('date_to', $query);
}

/**
* Test the timezone calculations in the date filters.
*
* Example: 2020-01-02 01:00:00 should be day 2020-01-01 in America/Sao_Paulo
*/
public function testTimezoneDate()
{
$SmsDev = $this->getServiceMock();

date_default_timezone_set('UTC');

$SmsDev->setDateFormat('Y-m-d H:i:s')
->setFilter()
->dateFrom('2020-01-02 01:00:00')
->fetch();

$this->assertSame('/get', $this->_container[0]['request']->getUri()->getPath());

$query = $this->_container[0]['request']->getHeaders()['query'];

$this->assertSame('01/01/2020', $query['date_from']);
}
}
2 changes: 1 addition & 1 deletion tests/ApiResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function testFilterByUnread()

$parsedMessages = current($SmsDev->parsedMessages());

$this->assertSame('2018-01-19 11:35:14', $parsedMessages['date']);
$this->assertSame('2018-01-19 13:35:14', $parsedMessages['date']); // UTC conversion
$this->assertSame('5511988887777', $parsedMessages['number']);
$this->assertSame('Resposta', $parsedMessages['message']);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/SmsDevMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ abstract class SmsDevMock extends TestCase

public function getServiceMock($apiResponse = '')
{
date_default_timezone_set('America/Sao_Paulo');
date_default_timezone_set('UTC');

$this->_container = [];

Expand Down
66 changes: 0 additions & 66 deletions tests/TimezoneTest.php

This file was deleted.

0 comments on commit 53eea85

Please sign in to comment.