Skip to content

Commit 278a478

Browse files
committed
handle http errors with consistent interfax exception creation
1 parent d1b3a62 commit 278a478

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

src/Interfax/Client.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ protected function getBaseRequestParams()
160160
'auth' => [$this->username, $this->password],
161161
'headers' => [
162162
'User-Agent' => $this->getUserAgent()
163-
]
163+
],
164+
'http_errors' => false
164165
];
165166
}
166167

tests/Interfax/ClientTest.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,36 +242,48 @@ public function test_prevents_trailing_slash()
242242
}
243243

244244
/**
245-
* Accept any 2xx status codes, throw an exception otherwise
245+
* Accept any 2xx status codes
246246
*/
247-
public function test_response_status_parsing()
247+
public function test_success_response_status_parsing()
248248
{
249249
for ($i = 0; $i < 10; $i++) {
250250
$container = [];
251251
$client = $this->getClientWithResponses([
252252
new Response(rand(200, 299), [], 'foo')
253253
], $container);
254254

255-
$response = $client->get('test/uri',['query' => ['foo' => true, 'bar' => false]]);
255+
$response = $client->get('test/uri', ['query' => ['foo' => true, 'bar' => false]]);
256256

257257
$this->assertEquals('foo', $response);
258258
}
259-
259+
}
260+
261+
public function errorCodeProvider()
262+
{
263+
$data = [];
260264
for ($i = 0; $i < 10; $i++) {
261265
$status_code = rand(100, 550);
262266
if ($status_code >= 200 && $status_code <=299) {
263267
$status_code += 100;
264268
}
269+
$data[] = [$status_code];
270+
}
271+
return $data;
272+
}
273+
274+
/**
275+
* @dataProvider errorCodeProvider
276+
*/
277+
public function test_error_response_status_parsing($status_code)
278+
{
279+
$container = [];
280+
$client = $this->getClientWithResponses([
281+
new Response($status_code, [], 'foo')
282+
], $container);
265283

266-
$container = [];
267-
$client = $this->getClientWithResponses([
268-
new Response($status_code, [], 'foo')
269-
], $container);
270-
271-
$this->setExpectedException('Interfax\Exception\RequestException', 'Unsuccessful request: foo');
284+
$this->setExpectedException('Interfax\Exception\RequestException', 'Unsuccessful request: foo');
272285

273-
$response = $client->get('test/uri',['query' => ['foo' => true, 'bar' => false]]);
274-
}
286+
$response = $client->get('test/uri', ['query' => ['foo' => true, 'bar' => false]]);
275287
}
276288

277289
}

0 commit comments

Comments
 (0)