Skip to content

Commit 3a11784

Browse files
committed
add test for server exceptions
1 parent 0ad5a47 commit 3a11784

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

tests/Intercom/Exception/IntercomExceptionTest.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,19 @@ public function test404Exception()
1818
$this->assertEquals('No such user with id[123456]', $errors[0]['message'] );
1919
}
2020
}
21-
}
21+
22+
public function test503Exception()
23+
{
24+
try {
25+
$this->setMockResponse($this->client, 'Error/Error503.txt');
26+
$response = $this->client->getUser(['id' => '123456']);
27+
$this->fail('An Exception\ClientErrorResponseException for a 503 response should have been raised');
28+
}
29+
catch (Exception\ServerErrorResponseException $expected) {
30+
$errors = $expected->getErrors();
31+
$this->assertEquals(1, count($errors));
32+
$this->assertEquals('service_unavailable', $errors[0]['code'] );
33+
$this->assertEquals('Sorry, the API service is temporarily unavailable', $errors[0]['message'] );
34+
}
35+
}
36+
}

tests/Mock/Error/Error503.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
HTTP/1.1 503 Service Unavailable
2+
Content-Type: application/json; charset=utf-8
3+
Date: Mon, 25 Aug 2014 23:57:54 GMT
4+
5+
{
6+
"type": "error.list",
7+
"errors": [
8+
{
9+
"code": "service_unavailable",
10+
"message": "Sorry, the API service is temporarily unavailable"
11+
}
12+
]
13+
}

0 commit comments

Comments
 (0)