|
411 | 411 | expect($emailFormatFeatures)->toBeEmpty(); |
412 | 412 | }); |
413 | 413 |
|
| 414 | +it('validates content encoding and media type features against schema version', function (): void { |
| 415 | + // Draft 06 should reject contentEncoding/contentMediaType |
| 416 | + $stringSchema = Schema::string('test', SchemaVersion::Draft_06); |
| 417 | + |
| 418 | + expect(fn(): StringSchema => $stringSchema->contentEncoding('base64'))->toThrow( |
| 419 | + SchemaException::class, |
| 420 | + 'Feature "Content encoding annotation" is not supported in Draft 6. Minimum version required: Draft 7.', |
| 421 | + ); |
| 422 | + expect(fn(): StringSchema => $stringSchema->contentMediaType('application/json'))->toThrow( |
| 423 | + SchemaException::class, |
| 424 | + 'Feature "Content media type annotation" is not supported in Draft 6. Minimum version required: Draft 7.', |
| 425 | + ); |
| 426 | + |
| 427 | + // Draft 07+ should accept contentEncoding/contentMediaType |
| 428 | + $draft07Schema = Schema::string('test', SchemaVersion::Draft_07); |
| 429 | + $draft201909Schema = Schema::string('test', SchemaVersion::Draft_2019_09); |
| 430 | + $draft202012Schema = Schema::string('test', SchemaVersion::Draft_2020_12); |
| 431 | + |
| 432 | + expect(fn(): StringSchema => $draft07Schema->contentEncoding('base64'))->not->toThrow(SchemaException::class); |
| 433 | + expect(fn(): StringSchema => $draft07Schema->contentMediaType('application/json'))->not->toThrow(SchemaException::class); |
| 434 | + expect(fn(): StringSchema => $draft201909Schema->contentEncoding('base64'))->not->toThrow(SchemaException::class); |
| 435 | + expect(fn(): StringSchema => $draft201909Schema->contentMediaType('application/json'))->not->toThrow(SchemaException::class); |
| 436 | + expect(fn(): StringSchema => $draft202012Schema->contentEncoding('base64'))->not->toThrow(SchemaException::class); |
| 437 | + expect(fn(): StringSchema => $draft202012Schema->contentMediaType('application/json'))->not->toThrow(SchemaException::class); |
| 438 | +}); |
| 439 | + |
414 | 440 | it('allows string formats for custom validation', function (): void { |
415 | 441 | // String formats should not trigger validation (for custom formats) |
416 | 442 | $stringSchema = Schema::string('test', SchemaVersion::Draft_07); |
|
0 commit comments