diff --git a/tests/ApiExceptionTest.php b/tests/ApiExceptionTest.php new file mode 100644 index 0000000..bf32f3e --- /dev/null +++ b/tests/ApiExceptionTest.php @@ -0,0 +1,47 @@ +api() ); + } + + + /** + * @expectedException \GW2Treasures\GW2Api\Exception\ApiException + * @expectedExceptionMessage this is the error message. + */ + public function testMessage() { + $this->mockResponse( new Response( + 400, [ 'Content-Type' => 'application/json; charset=utf-8' ], + Stream::factory( '{"text":"this is the error message."}' ) + )); + + $this->getEndpoint()->test(); + } + + public function testResponse() { + $this->mockResponse( new Response( + 400, [ 'Content-Type' => 'application/json; charset=utf-8', 'foo' => 'bar' ], + Stream::factory( '{"text":"this is the error message."}' ) + )); + + try { + $this->getEndpoint()->test(); + } catch( \GW2Treasures\GW2Api\Exception\ApiException $exception ) { + $this->assertNotNull( $exception->getResponse() ); + $this->assertEquals( 'bar', $exception->getResponse()->getHeader('foo') ); + $this->assertEquals( 400, $exception->getCode() ); + $this->assertEquals( 400, $exception->getResponse()->getStatusCode() ); + + $this->assertStringStartsWith( $exception->getMessage(), $exception->__toString() ); + $this->assertNotFalse( strstr( $exception->__toString(), 'status: 400' )); + } + } +}