-
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
6 changed files
with
159 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
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
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
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,27 @@ | ||
<?php | ||
|
||
namespace GW2Treasures\GW2Api\V2\Schema; | ||
|
||
use GW2Treasures\GW2Api\V2\ApiHandler; | ||
use GW2Treasures\GW2Api\V2\IEndpoint; | ||
use Psr\Http\Message\MessageInterface; | ||
use Psr\Http\Message\RequestInterface; | ||
|
||
class SchemaHandler extends ApiHandler { | ||
function __construct( IEndpoint $endpoint ) { | ||
parent::__construct( $endpoint ); | ||
} | ||
|
||
/** | ||
* Add the schema version header. | ||
* | ||
* @param RequestInterface $request | ||
* | ||
* @return MessageInterface|RequestInterface | ||
*/ | ||
public function onRequest( RequestInterface $request ) { | ||
$schema = $this->getEndpoint()->getSchema(); | ||
|
||
return $request->withHeader( 'X-Schema-Version', $schema ); | ||
} | ||
} |
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,58 @@ | ||
<?php | ||
|
||
use GW2Treasures\GW2Api\GW2Api; | ||
use Stubs\EndpointStub; | ||
|
||
const EXPECTED_DEFAULT_SCHEMA = GW2Api::DEFAULT_SCHEMA; | ||
const EXPECTED_CUSTOM_SCHEMA = '2077-01-01T00:00:00Z'; | ||
|
||
class SchemaTest extends TestCase { | ||
protected function getEndpoint() { | ||
return new EndpointStub( $this->api() ); | ||
} | ||
|
||
public function testDefaultSchema() { | ||
$this->mockResponse('[]'); | ||
|
||
$endpoint = $this->getEndpoint(); | ||
|
||
$this->assertEquals(EXPECTED_DEFAULT_SCHEMA, $endpoint->getSchema()); | ||
|
||
$endpoint->test(); | ||
|
||
$request = $this->getLastRequest(); | ||
$this->assertHasHeader($request, 'X-Schema-Version', EXPECTED_DEFAULT_SCHEMA); | ||
} | ||
|
||
public function testCustomSchema() { | ||
$this->mockResponse('[]'); | ||
|
||
$endpoint = $this->getEndpoint()->schema(EXPECTED_CUSTOM_SCHEMA); | ||
|
||
$this->assertEquals(EXPECTED_CUSTOM_SCHEMA, $endpoint->getSchema()); | ||
|
||
$endpoint->test(); | ||
|
||
$request = $this->getLastRequest(); | ||
$this->assertHasHeader($request, 'X-Schema-Version', EXPECTED_CUSTOM_SCHEMA); | ||
} | ||
|
||
public function testGlobalSchema() { | ||
$this->mockResponse('[]'); | ||
|
||
$endpoint = $this->getEndpoint(); | ||
$this->assertEquals(EXPECTED_DEFAULT_SCHEMA, $endpoint->getSchema()); | ||
|
||
$this->api()->schema(EXPECTED_CUSTOM_SCHEMA); | ||
|
||
$this->assertEquals(EXPECTED_CUSTOM_SCHEMA, $endpoint->getSchema()); | ||
|
||
$endpoint->test(); | ||
|
||
$request = $this->getLastRequest(); | ||
$this->assertHasHeader($request, 'X-Schema-Version', EXPECTED_CUSTOM_SCHEMA); | ||
|
||
// clean up schema for other tests | ||
$this->resetApi(); | ||
} | ||
} |
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