Skip to content

Commit 7cb86b8

Browse files
committed
Fix NullResponseException tests.
1 parent 7c10917 commit 7cb86b8

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

lib/Tmdb/HttpClient/Adapter/GuzzleAdapter.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,8 @@ protected function handleRequestException(Request $request, RequestException $pr
139139
{
140140
if (null !== $previousException) {
141141
$response = $previousException->getResponse();
142-
if(null == $response) {
143-
throw new NullResponseException($this->request, $previousException);
144-
}
145-
if($response->getStatusCode() >= 500 && $response->getStatusCode() <= 599) {
142+
143+
if (null == $response || ($response->getStatusCode() >= 500 && $response->getStatusCode() <= 599)) {
146144
throw new NullResponseException($this->request, $previousException);
147145
}
148146
}

test/Tmdb/Tests/HttpClient/Adapter/GuzzleAdapterTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use GuzzleHttp\Exception\RequestException;
1717
use GuzzleHttp\HandlerStack;
1818
use GuzzleHttp\Psr7\Response;
19+
use GuzzleHttp\Psr7\Stream;
1920
use Tmdb\ApiToken;
2021
use Tmdb\Exception\NullResponseException;
2122
use Tmdb\HttpClient\Adapter\GuzzleAdapter;
@@ -305,21 +306,21 @@ public function shouldThrowNullResponseException()
305306
*/
306307
public function shouldThrowExceptionForServerError()
307308
{
308-
$client = $this->getMock('GuzzleHttp\ClientInterface');
309+
$client = $this->createMock('GuzzleHttp\ClientInterface');
309310

310311
$client->expects($this->once())
311-
->method('get')
312+
->method('request')
312313
->will($this->throwException(
313314
new RequestException(
314315
'500',
315-
new \GuzzleHttp\Message\Request('get', '/'),
316-
new \GuzzleHttp\Message\Response(500, [], Stream::factory('<html><body>Internal Server Error</body></html>'))
316+
new \GuzzleHttp\Psr7\Request('GET', '/'),
317+
new Response(500, [], '<html><body>Internal Server Error</body></html>')
317318
)
318319
))
319320
;
320321

321322
$adapter = new GuzzleAdapter($client);
322-
$adapter->get(new Request());
323+
$adapter->get(new Request('/'));
323324
}
324325

325326
/**

0 commit comments

Comments
 (0)