|
2 | 2 |
|
3 | 3 | namespace Swaggest\JsonSchema\Tests\PHPUnit\Suite;
|
4 | 4 |
|
| 5 | +use Swaggest\JsonSchema\Context; |
| 6 | +use Swaggest\JsonSchema\RemoteRef\Preloaded; |
5 | 7 | use Swaggest\JsonSchema\Schema;
|
6 | 8 |
|
7 | 9 | class Issue66Test extends \PHPUnit_Framework_TestCase
|
8 | 10 | {
|
9 | 11 | public function testIssue()
|
10 | 12 | {
|
11 |
| - $schemaData = json_decode(<<<'JSON' |
12 |
| -{ |
13 |
| - "$schema": "http://json-schema.org/draft-07/schema#", |
14 |
| - "$id": "urn:example:api:response-example", |
15 |
| - "type": "object", |
16 |
| - "additionalProperties": false, |
17 |
| - "required": ["confirmed", "to_pay"], |
18 |
| - "definitions": { |
19 |
| - "example_item": { |
20 |
| - "type": "object", |
21 |
| - "additionalProperties": false, |
22 |
| - "required": [ |
23 |
| - "_type", |
24 |
| - "count" |
25 |
| - ], |
26 |
| - "properties": { |
27 |
| - "_type": { |
28 |
| - "$id": "#/definitions/example_item/properties/confirmed/properties/_type", |
29 |
| - "type": "string", |
30 |
| - "enum": ["example_item"] |
31 |
| - }, |
32 |
| - "count": { |
33 |
| - "$id": "#/definitions/example_item/properties/confirmed/properties/count", |
34 |
| - "type": "integer" |
35 |
| - } |
36 |
| - } |
37 |
| - } |
38 |
| - }, |
39 |
| - "properties": { |
40 |
| - "confirmed": { |
41 |
| - "$ref": "#/definitions/example_item" |
42 |
| - }, |
43 |
| - "to_pay": { |
44 |
| - "$ref": "#/definitions/example_item" |
45 |
| - } |
| 13 | + $schemaPath = realpath(__DIR__ . '/../../../resources/suite/issue66.json'); |
| 14 | + $schemaData = json_decode(file_get_contents($schemaPath)); |
| 15 | + $resolver = new Preloaded(); |
| 16 | + $resolver->setSchemaData($schemaPath, $schemaData); |
| 17 | + |
| 18 | + $options = new Context($resolver); |
| 19 | + |
| 20 | + $schema = Schema::import((object)['$ref' => $schemaPath], $options); |
| 21 | + $res = $schema->in(json_decode('{"confirmed":{"count":123, "_type": "example_item"}, "to_pay":{"count":123, "_type": "example_item"}}')); |
| 22 | + $this->assertSame(123, $res->confirmed->count); |
46 | 23 | }
|
47 |
| -} |
48 |
| -JSON |
49 |
| -); |
50 |
| - $schema = Schema::import($schemaData); |
| 24 | + |
| 25 | + public function testDirectImport() |
| 26 | + { |
| 27 | + $schemaPath = realpath(__DIR__ . '/../../../resources/suite/issue66.json'); |
| 28 | + $schema = Schema::import($schemaPath); |
51 | 29 | $res = $schema->in(json_decode('{"confirmed":{"count":123, "_type": "example_item"}, "to_pay":{"count":123, "_type": "example_item"}}'));
|
52 | 30 | $this->assertSame(123, $res->confirmed->count);
|
53 | 31 | }
|
|
0 commit comments