File tree Expand file tree Collapse file tree 4 files changed +54
-3
lines changed Expand file tree Collapse file tree 4 files changed +54
-3
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ public function fetchRemoteSchema(string $uri): \stdClass
3737 $ streamContext = stream_context_create (
3838 [
3939 'http ' => [
40- 'user_agent ' => 'ropi- json-schema-evaluator '
40+ 'user_agent ' => 'ropi/ json-schema-evaluator '
4141 ],
4242 'ssl ' => [
4343 'verify_peer ' => false ,
Original file line number Diff line number Diff line change 66use Ropi \JsonSchemaEvaluator \Draft \Draft202012 ;
77use Ropi \JsonSchemaEvaluator \EvaluationConfig \StaticEvaluationConfig ;
88use Ropi \JsonSchemaEvaluator \Tests \Functional \AbstractJsonSchemaTestSuite ;
9+ use Ropi \JsonSchemaEvaluator \Tests \Functional \JsonSchemaTestSuiteSchemaPool ;
910
1011class Draft202012ShortCircuitTest extends AbstractJsonSchemaTestSuite
1112{
@@ -49,7 +50,8 @@ public function test(\stdClass $testCollection): void
4950 defaultDraft: $ this ->draft ,
5051 supportedDrafts: [
5152 $ metaSchemaNoValidation
52- ]
53+ ],
54+ schemaPool: new JsonSchemaTestSuiteSchemaPool ()
5355 ));
5456 }
5557}
Original file line number Diff line number Diff line change 66use Ropi \JsonSchemaEvaluator \Draft \Draft202012 ;
77use Ropi \JsonSchemaEvaluator \EvaluationConfig \StaticEvaluationConfig ;
88use Ropi \JsonSchemaEvaluator \Tests \Functional \AbstractJsonSchemaTestSuite ;
9+ use Ropi \JsonSchemaEvaluator \Tests \Functional \JsonSchemaTestSuiteSchemaPool ;
910
1011class Draft202012Test extends AbstractJsonSchemaTestSuite
1112{
@@ -43,7 +44,8 @@ public function test(\stdClass $testCollection): void
4344 defaultDraft: $ this ->draft ,
4445 supportedDrafts: [
4546 $ metaSchemaNoValidation
46- ]
47+ ],
48+ schemaPool: new JsonSchemaTestSuiteSchemaPool ()
4749 ));
4850 }
4951}
Original file line number Diff line number Diff line change 1+ <?php
2+ declare (strict_types=1 );
3+
4+ namespace Ropi \JsonSchemaEvaluator \Tests \Functional ;
5+
6+ use Ropi \JsonSchemaEvaluator \SchemaPool \Exception \RemoteSchemaParseException ;
7+ use Ropi \JsonSchemaEvaluator \SchemaPool \Exception \RemoteSchemaRequestException ;
8+ use Ropi \JsonSchemaEvaluator \SchemaPool \SchemaPool ;
9+
10+ class JsonSchemaTestSuiteSchemaPool extends SchemaPool
11+ {
12+ /**
13+ * @throws RemoteSchemaParseException
14+ * @throws RemoteSchemaRequestException
15+ */
16+ public function fetchRemoteSchema (string $ uri ): \stdClass
17+ {
18+ if (str_starts_with ($ uri , 'http://localhost:1234 ' )) {
19+ $ relativeFilePath = substr ($ uri , strlen ('http://localhost:1234 ' ));
20+ $ absoluteFilePath = dirname (__DIR__ ) . '/Resources/json-schema-test-suite/remotes ' . $ relativeFilePath ;
21+
22+ $ content = file_get_contents ($ absoluteFilePath );
23+ if (!is_string ($ content )) {
24+ throw new RemoteSchemaRequestException (
25+ 'Failed to open json schema test suite remote schema with URI \''
26+ . $ uri
27+ . '\'' ,
28+ 1703195612
29+ );
30+ }
31+
32+ $ schema = json_decode ($ content );
33+ if (!$ schema instanceof \stdClass) {
34+ throw new RemoteSchemaParseException (
35+ 'The json schema test suite remote schema URI \''
36+ . $ uri
37+ . '\' does not contain a valid JSON Schema object ' ,
38+ 1703195642
39+ );
40+ }
41+
42+ return $ schema ;
43+ }
44+
45+ return parent ::fetchRemoteSchema ($ uri );
46+ }
47+ }
You can’t perform that action at this time.
0 commit comments