Skip to content

Commit f913ce0

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

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
@@ -35,8 +35,9 @@ public function testInvalidCases(string $input, string $schema, ?int $checkMode
3535
$checkMode |= Constraint::CHECK_MODE_VALIDATE_SCHEMA;
3636
}
3737

38-
$schemaStorage = new SchemaStorage($this->getUriRetrieverMock(json_decode($schema, false)));
39-
$schema = $schemaStorage->getSchema('http://www.my-domain.com/schema.json');
38+
$schema = json_decode($schema, false);
39+
$schemaStorage = new SchemaStorage($this->getUriRetrieverMock($schema));
40+
$schema = $schemaStorage->getSchema($schema->id ?? 'http://www.my-domain.com/schema.json');
4041
if (is_object($schema) && !isset($schema->{'$schema'})) {
4142
$schema->{'$schema'} = $this->schemaSpec;
4243
}
@@ -67,8 +68,9 @@ public function testInvalidCasesUsingAssoc($input, $schema, $checkMode = Constra
6768
$this->markTestSkipped('Test indicates that it is not for "CHECK_MODE_TYPE_CAST"');
6869
}
6970

70-
$schemaStorage = new SchemaStorage($this->getUriRetrieverMock(json_decode($schema)));
71-
$schema = $schemaStorage->getSchema('http://www.my-domain.com/schema.json');
71+
$schema = json_decode($schema, false);
72+
$schemaStorage = new SchemaStorage($this->getUriRetrieverMock($schema));
73+
$schema = $schemaStorage->getSchema($schema->id ?? 'http://www.my-domain.com/schema.json');
7274
if (is_object($schema) && !isset($schema->{'$schema'})) {
7375
$schema->{'$schema'} = $this->schemaSpec;
7476
}
@@ -94,8 +96,10 @@ public function testValidCases($input, $schema, $checkMode = Constraint::CHECK_M
9496
if ($this->validateSchema) {
9597
$checkMode |= Constraint::CHECK_MODE_VALIDATE_SCHEMA;
9698
}
97-
$schemaStorage = new SchemaStorage($this->getUriRetrieverMock(json_decode($schema)));
98-
$schema = $schemaStorage->getSchema('http://www.my-domain.com/schema.json');
99+
100+
$schema = json_decode($schema, false);
101+
$schemaStorage = new SchemaStorage($this->getUriRetrieverMock($schema));
102+
$schema = $schemaStorage->getSchema($schema->id ?? 'http://www.my-domain.com/schema.json');
99103
if (is_object($schema) && !isset($schema->{'$schema'})) {
100104
$schema->{'$schema'} = $this->schemaSpec;
101105
}
@@ -120,9 +124,9 @@ public function testValidCasesUsingAssoc($input, $schema, $checkMode = Constrain
120124
$this->markTestSkipped('Test indicates that it is not for "CHECK_MODE_TYPE_CAST"');
121125
}
122126

123-
$schema = json_decode($schema);
127+
$schema = json_decode($schema, false);
124128
$schemaStorage = new SchemaStorage($this->getUriRetrieverMock($schema), new UriResolver());
125-
$schema = $schemaStorage->getSchema('http://www.my-domain.com/schema.json');
129+
$schema = $schemaStorage->getSchema($schema->id ?? +'http://www.my-domain.com/schema.json');
126130
if (is_object($schema) && !isset($schema->{'$schema'})) {
127131
$schema->{'$schema'} = $this->schemaSpec;
128132
}

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)