|
| 1 | +<?php |
| 2 | + |
| 3 | +use GW2Treasures\GW2Api\GW2Api; |
| 4 | +use Stubs\EndpointStub; |
| 5 | + |
| 6 | +const EXPECTED_DEFAULT_SCHEMA = GW2Api::DEFAULT_SCHEMA; |
| 7 | +const EXPECTED_CUSTOM_SCHEMA = '2077-01-01T00:00:00Z'; |
| 8 | + |
| 9 | +class SchemaTest extends TestCase { |
| 10 | + protected function getEndpoint() { |
| 11 | + return new EndpointStub( $this->api() ); |
| 12 | + } |
| 13 | + |
| 14 | + public function testDefaultSchema() { |
| 15 | + $this->mockResponse('[]'); |
| 16 | + |
| 17 | + $endpoint = $this->getEndpoint(); |
| 18 | + |
| 19 | + $this->assertEquals(EXPECTED_DEFAULT_SCHEMA, $endpoint->getSchema()); |
| 20 | + |
| 21 | + $endpoint->test(); |
| 22 | + |
| 23 | + $request = $this->getLastRequest(); |
| 24 | + $this->assertHasHeader($request, 'X-Schema-Version', EXPECTED_DEFAULT_SCHEMA); |
| 25 | + } |
| 26 | + |
| 27 | + public function testCustomSchema() { |
| 28 | + $this->mockResponse('[]'); |
| 29 | + |
| 30 | + $endpoint = $this->getEndpoint()->schema(EXPECTED_CUSTOM_SCHEMA); |
| 31 | + |
| 32 | + $this->assertEquals(EXPECTED_CUSTOM_SCHEMA, $endpoint->getSchema()); |
| 33 | + |
| 34 | + $endpoint->test(); |
| 35 | + |
| 36 | + $request = $this->getLastRequest(); |
| 37 | + $this->assertHasHeader($request, 'X-Schema-Version', EXPECTED_CUSTOM_SCHEMA); |
| 38 | + } |
| 39 | + |
| 40 | + public function testGlobalSchema() { |
| 41 | + $this->mockResponse('[]'); |
| 42 | + |
| 43 | + $endpoint = $this->getEndpoint(); |
| 44 | + $this->assertEquals(EXPECTED_DEFAULT_SCHEMA, $endpoint->getSchema()); |
| 45 | + |
| 46 | + $this->api()->schema(EXPECTED_CUSTOM_SCHEMA); |
| 47 | + |
| 48 | + $this->assertEquals(EXPECTED_CUSTOM_SCHEMA, $endpoint->getSchema()); |
| 49 | + |
| 50 | + $endpoint->test(); |
| 51 | + |
| 52 | + $request = $this->getLastRequest(); |
| 53 | + $this->assertHasHeader($request, 'X-Schema-Version', EXPECTED_CUSTOM_SCHEMA); |
| 54 | + |
| 55 | + // clean up schema for other tests |
| 56 | + $this->resetApi(); |
| 57 | + } |
| 58 | +} |
0 commit comments