77use Binaryk \LaravelRestify \Tests \Fixtures \Post \PostRepository ;
88use Binaryk \LaravelRestify \Tests \IntegrationTestCase ;
99use Illuminate \Contracts \Validation \ValidationRule ;
10- use Illuminate \JsonSchema \JsonSchemaTypeFactory ;
11- use Illuminate \JsonSchema \Types \ArrayType ;
12- use Illuminate \JsonSchema \Types \BooleanType ;
13- use Illuminate \JsonSchema \Types \IntegerType ;
14- use Illuminate \JsonSchema \Types \NumberType ;
15- use Illuminate \JsonSchema \Types \StringType ;
1610
11+ /**
12+ * @requires Laravel 12+
13+ */
1714class FieldSchemaValidationTest extends IntegrationTestCase
1815{
16+ protected function setUp (): void
17+ {
18+ parent ::setUp ();
19+
20+ if (! interface_exists (\Illuminate \Contracts \JsonSchema \JsonSchema::class)) {
21+ $ this ->markTestSkipped ('JsonSchema classes are only available in Laravel 12+ ' );
22+ }
23+ }
24+
1925 public function test_field_rules_convert_to_correct_schema_types (): void
2026 {
2127 // Test string field type detection
2228 $ titleField = Field::make ('title ' )->rules (['required ' , 'string ' , 'max:255 ' ]);
23- $ this ->assertInstanceOf (StringType::class, $ titleField ->guessFieldType (new McpStoreRequest ));
29+ $ this ->assertInstanceOf (\ Illuminate \ JsonSchema \ Types \ StringType::class, $ titleField ->guessFieldType (new McpStoreRequest ));
2430
2531 // Test integer field type detection
2632 $ priorityField = Field::make ('priority ' )->rules (['required ' , 'integer ' , 'min:1 ' ]);
27- $ this ->assertInstanceOf (IntegerType::class, $ priorityField ->guessFieldType (new McpStoreRequest ));
33+ $ this ->assertInstanceOf (\ Illuminate \ JsonSchema \ Types \ IntegerType::class, $ priorityField ->guessFieldType (new McpStoreRequest ));
2834
2935 // Test boolean field type detection
3036 $ publishedField = Field::make ('is_published ' )->rules (['boolean ' ]);
31- $ this ->assertInstanceOf (BooleanType::class, $ publishedField ->guessFieldType (new McpStoreRequest ));
37+ $ this ->assertInstanceOf (\ Illuminate \ JsonSchema \ Types \ BooleanType::class, $ publishedField ->guessFieldType (new McpStoreRequest ));
3238
3339 // Test numeric field type detection
3440 $ ratingField = Field::make ('rating ' )->rules (['numeric ' , 'between:0,5 ' ]);
35- $ this ->assertInstanceOf (NumberType::class, $ ratingField ->guessFieldType (new McpStoreRequest ));
41+ $ this ->assertInstanceOf (\ Illuminate \ JsonSchema \ Types \ NumberType::class, $ ratingField ->guessFieldType (new McpStoreRequest ));
3642
3743 // Test email field (should be string type)
3844 $ emailField = Field::make ('author_email ' )->rules (['required ' , 'email ' ]);
39- $ this ->assertInstanceOf (StringType::class, $ emailField ->guessFieldType (new McpStoreRequest ));
45+ $ this ->assertInstanceOf (\ Illuminate \ JsonSchema \ Types \ StringType::class, $ emailField ->guessFieldType (new McpStoreRequest ));
4046
4147 // Test array field type detection
4248 $ tagsField = Field::make ('tags ' )->rules (['array ' ]);
43- $ this ->assertInstanceOf (ArrayType::class, $ tagsField ->guessFieldType (new McpStoreRequest ));
49+ $ this ->assertInstanceOf (\ Illuminate \ JsonSchema \ Types \ ArrayType::class, $ tagsField ->guessFieldType (new McpStoreRequest ));
4450
4551 // Test default type for custom validation
4652 $ slugField = Field::make ('slug ' )->rules (['required ' , 'unique:posts,slug ' ]);
47- $ this ->assertInstanceOf (StringType::class, $ slugField ->guessFieldType (new McpStoreRequest ));
53+ $ this ->assertInstanceOf (\ Illuminate \ JsonSchema \ Types \ StringType::class, $ slugField ->guessFieldType (new McpStoreRequest ));
4854 }
4955
5056 public function test_field_validation_rules_format (): void
5157 {
5258 // Test field with 'in' validation
5359 $ statusField = Field::make ('status ' )->rules (['required ' , 'string ' , 'in:draft,published,archived ' ]);
54- $ this ->assertInstanceOf (StringType::class, $ statusField ->guessFieldType (new McpStoreRequest ));
60+ $ this ->assertInstanceOf (\ Illuminate \ JsonSchema \ Types \ StringType::class, $ statusField ->guessFieldType (new McpStoreRequest ));
5561
5662 // Test field with min/max rules
5763 $ wordCountField = Field::make ('word_count ' )->rules (['integer ' , 'min:100 ' , 'max:5000 ' ]);
58- $ this ->assertInstanceOf (IntegerType::class, $ wordCountField ->guessFieldType (new McpStoreRequest ));
64+ $ this ->assertInstanceOf (\ Illuminate \ JsonSchema \ Types \ IntegerType::class, $ wordCountField ->guessFieldType (new McpStoreRequest ));
5965
6066 // Test numeric field with between rule
6167 $ ratingField = Field::make ('rating ' )->rules (['numeric ' , 'between:1,10 ' ]);
62- $ this ->assertInstanceOf (NumberType::class, $ ratingField ->guessFieldType (new McpStoreRequest ));
68+ $ this ->assertInstanceOf (\ Illuminate \ JsonSchema \ Types \ NumberType::class, $ ratingField ->guessFieldType (new McpStoreRequest ));
6369
6470 // Test required field detection
6571 $ requiredField = Field::make ('name ' )->rules (['required ' , 'string ' ]);
@@ -75,7 +81,7 @@ public function test_field_validation_rules_format(): void
7581 public function test_field_json_schema_has_description (): void
7682 {
7783 $ request = new McpStoreRequest ;
78- $ schemaFactory = new JsonSchemaTypeFactory ;
84+ $ schemaFactory = new \ Illuminate \ JsonSchema \ JsonSchemaTypeFactory ;
7985 $ repository = PostRepository::partialMock ();
8086 $ field = field ('published_at ' )->rules (['nullable ' , 'date ' , 'after:2020-01-01 ' ])->resolveJsonSchema (
8187 $ schemaFactory ,
@@ -90,7 +96,7 @@ public function test_field_json_schema_has_description(): void
9096 public function test_field_json_schema_prioritize_user_description (): void
9197 {
9298 $ request = new McpStoreRequest ;
93- $ schemaFactory = new JsonSchemaTypeFactory ;
99+ $ schemaFactory = new \ Illuminate \ JsonSchema \ JsonSchemaTypeFactory ;
94100 $ repository = PostRepository::partialMock ();
95101 $ field = field ('published_at ' )->rules (['nullable ' , 'date ' , 'after:2020-01-01 ' ])
96102 ->description ('This is a custom description. ' )
@@ -109,7 +115,7 @@ public function test_can_validate_custom_rule(): void
109115 $ field = field ('published_at ' )->rules ([new UniqueClientCompanyNameRule ]);
110116
111117 $ type = $ field ->guessFieldType (new McpStoreRequest );
112- $ this ->assertInstanceOf (StringType::class, $ type );
118+ $ this ->assertInstanceOf (\ Illuminate \ JsonSchema \ Types \ StringType::class, $ type );
113119 }
114120}
115121class UniqueClientCompanyNameRule implements ValidationRule
0 commit comments