Skip to content

Commit 8d298df

Browse files
committed
fix: setup default to provided schema id and only fallback when not available
1 parent eb69f3b commit 8d298df

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

tests/Constraints/BaseTestCase.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ public function testInvalidCases(string $input, string $schema, ?int $checkMode
2828
$checkMode |= Constraint::CHECK_MODE_VALIDATE_SCHEMA;
2929
}
3030

31-
$schemaStorage = new SchemaStorage($this->getUriRetrieverMock(json_decode($schema, false)));
32-
$schema = $schemaStorage->getSchema('http://www.my-domain.com/schema.json');
31+
$schema = json_decode($schema, false);
32+
$schemaStorage = new SchemaStorage($this->getUriRetrieverMock($schema));
33+
$schema = $schemaStorage->getSchema($schema->id ?? 'http://www.my-domain.com/schema.json');
3334
if (is_object($schema) && !isset($schema->{'$schema'})) {
3435
$schema->{'$schema'} = $this->schemaSpec;
3536
}
@@ -60,8 +61,9 @@ public function testInvalidCasesUsingAssoc($input, $schema, $checkMode = Constra
6061
$this->markTestSkipped('Test indicates that it is not for "CHECK_MODE_TYPE_CAST"');
6162
}
6263

63-
$schemaStorage = new SchemaStorage($this->getUriRetrieverMock(json_decode($schema)));
64-
$schema = $schemaStorage->getSchema('http://www.my-domain.com/schema.json');
64+
$schema = json_decode($schema, false);
65+
$schemaStorage = new SchemaStorage($this->getUriRetrieverMock($schema));
66+
$schema = $schemaStorage->getSchema($schema->id ?? 'http://www.my-domain.com/schema.json');
6567
if (is_object($schema) && !isset($schema->{'$schema'})) {
6668
$schema->{'$schema'} = $this->schemaSpec;
6769
}
@@ -87,8 +89,10 @@ public function testValidCases($input, $schema, $checkMode = Constraint::CHECK_M
8789
if ($this->validateSchema) {
8890
$checkMode |= Constraint::CHECK_MODE_VALIDATE_SCHEMA;
8991
}
90-
$schemaStorage = new SchemaStorage($this->getUriRetrieverMock(json_decode($schema, false)));
91-
$schema = $schemaStorage->getSchema('http://www.my-domain.com/schema.json');
92+
93+
$schema = json_decode($schema, false);
94+
$schemaStorage = new SchemaStorage($this->getUriRetrieverMock($schema));
95+
$schema = $schemaStorage->getSchema($schema->id ?? 'http://www.my-domain.com/schema.json');
9296
if (is_object($schema) && !isset($schema->{'$schema'})) {
9397
$schema->{'$schema'} = $this->schemaSpec;
9498
}
@@ -113,9 +117,9 @@ public function testValidCasesUsingAssoc($input, $schema, $checkMode = Constrain
113117
$this->markTestSkipped('Test indicates that it is not for "CHECK_MODE_TYPE_CAST"');
114118
}
115119

116-
$schema = json_decode($schema);
120+
$schema = json_decode($schema, false);
117121
$schemaStorage = new SchemaStorage($this->getUriRetrieverMock($schema), new UriResolver());
118-
$schema = $schemaStorage->getSchema('http://www.my-domain.com/schema.json');
122+
$schema = $schemaStorage->getSchema($schema->id ?? 'http://www.my-domain.com/schema.json');
119123
if (is_object($schema) && !isset($schema->{'$schema'})) {
120124
$schema->{'$schema'} = $this->schemaSpec;
121125
}

tests/Constraints/VeryBaseTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ abstract class VeryBaseTestCase extends TestCase
2020
protected function getUriRetrieverMock(?object $schema): object
2121
{
2222
$uriRetriever = $this->prophesize(UriRetrieverInterface::class);
23-
$uriRetriever->retrieve('http://www.my-domain.com/schema.json')
23+
$uriRetriever->retrieve($schema->id ?? 'http://www.my-domain.com/schema.json')
2424
->willReturn($schema)
2525
->shouldBeCalled();
2626

0 commit comments

Comments
 (0)