|
6 | 6 |
|
7 | 7 | use PHPModelGenerator\Draft\AutoDetectionDraft; |
8 | 8 | use PHPModelGenerator\Draft\Draft_07; |
| 9 | +use PHPModelGenerator\Draft\Draft_2019_09; |
9 | 10 | use PHPModelGenerator\Draft\Element\Type; |
10 | 11 | use PHPModelGenerator\Exception\SchemaException; |
11 | 12 | use PHPModelGenerator\Exception\String\MinLengthException; |
@@ -170,6 +171,51 @@ public function testAutoDetectionFallsBackToDraft07ForUnrecognisedSchemaKeyword( |
170 | 171 | $this->assertInstanceOf(Draft_07::class, (new AutoDetectionDraft())->getDraftForSchema($jsonSchema)); |
171 | 172 | } |
172 | 173 |
|
| 174 | + /** @return array<string, array{string}> */ |
| 175 | + public static function draft201909SchemaUriProvider(): array |
| 176 | + { |
| 177 | + return [ |
| 178 | + 'https without trailing hash' => ['https://json-schema.org/draft/2019-09/schema'], |
| 179 | + 'https with trailing hash' => ['https://json-schema.org/draft/2019-09/schema#'], |
| 180 | + 'http without trailing hash' => ['http://json-schema.org/draft/2019-09/schema'], |
| 181 | + 'http with trailing hash' => ['http://json-schema.org/draft/2019-09/schema#'], |
| 182 | + ]; |
| 183 | + } |
| 184 | + |
| 185 | + #[DataProvider('draft201909SchemaUriProvider')] |
| 186 | + public function testAutoDetectionReturnsDraft201909ForDraft201909SchemaKeyword(string $schemaUri): void |
| 187 | + { |
| 188 | + $jsonSchema = new JsonSchema('test.json', ['$schema' => $schemaUri]); |
| 189 | + |
| 190 | + $this->assertInstanceOf(Draft_2019_09::class, (new AutoDetectionDraft())->getDraftForSchema($jsonSchema)); |
| 191 | + } |
| 192 | + |
| 193 | + public function testAutoDetectionReusesCachedDraft07Instance(): void |
| 194 | + { |
| 195 | + $autoDetectionDraft = new AutoDetectionDraft(); |
| 196 | + |
| 197 | + $firstSchema = new JsonSchema('first.json', ['$schema' => 'http://json-schema.org/draft-07/schema#']); |
| 198 | + $secondSchema = new JsonSchema('second.json', ['type' => 'object']); |
| 199 | + |
| 200 | + $this->assertSame( |
| 201 | + $autoDetectionDraft->getDraftForSchema($firstSchema), |
| 202 | + $autoDetectionDraft->getDraftForSchema($secondSchema), |
| 203 | + ); |
| 204 | + } |
| 205 | + |
| 206 | + public function testAutoDetectionReusesCachedDraft201909Instance(): void |
| 207 | + { |
| 208 | + $autoDetectionDraft = new AutoDetectionDraft(); |
| 209 | + |
| 210 | + $firstSchema = new JsonSchema('first.json', ['$schema' => 'https://json-schema.org/draft/2019-09/schema']); |
| 211 | + $secondSchema = new JsonSchema('second.json', ['$schema' => 'https://json-schema.org/draft/2019-09/schema#']); |
| 212 | + |
| 213 | + $this->assertSame( |
| 214 | + $autoDetectionDraft->getDraftForSchema($firstSchema), |
| 215 | + $autoDetectionDraft->getDraftForSchema($secondSchema), |
| 216 | + ); |
| 217 | + } |
| 218 | + |
173 | 219 | // --- GeneratorConfiguration --- |
174 | 220 |
|
175 | 221 | public function testGeneratorConfigurationDefaultDraftIsAutoDetection(): void |
|
0 commit comments