-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
use GuzzleHttp\Message\Response; | ||
use GuzzleHttp\Message\ResponseInterface; | ||
use GuzzleHttp\Stream\Stream; | ||
use GW2Treasures\GW2Api\V2\ApiHandler; | ||
use GW2Treasures\GW2Api\V2\IEndpoint; | ||
use Stubs\EndpointStub; | ||
|
||
class ApiExceptionTest extends TestCase { | ||
protected function getEndpoint() { | ||
return new EndpointStub( $this->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' )); | ||
} | ||
} | ||
} |