Skip to content

Commit efbb08f

Browse files
committed
fix: wip
1 parent 708fed0 commit efbb08f

File tree

2 files changed

+41
-26
lines changed

2 files changed

+41
-26
lines changed

tests/MCP/FieldSchemaValidationTest.php

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,65 @@
77
use Binaryk\LaravelRestify\Tests\Fixtures\Post\PostRepository;
88
use Binaryk\LaravelRestify\Tests\IntegrationTestCase;
99
use 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+
*/
1714
class 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
}
115121
class UniqueClientCompanyNameRule implements ValidationRule

tests/MCP/JsonSchemaFromRulesActionTest.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,25 @@
44

55
use Binaryk\LaravelRestify\MCP\Actions\JsonSchemaFromRulesAction;
66
use Binaryk\LaravelRestify\Tests\IntegrationTestCase;
7-
use Illuminate\JsonSchema\JsonSchemaTypeFactory;
8-
use Illuminate\JsonSchema\Types\IntegerType;
9-
use Illuminate\JsonSchema\Types\StringType;
107

8+
/**
9+
* @requires Laravel 12+
10+
*/
1111
class JsonSchemaFromRulesActionTest extends IntegrationTestCase
1212
{
13+
protected function setUp(): void
14+
{
15+
parent::setUp();
16+
17+
if (! interface_exists(\Illuminate\Contracts\JsonSchema\JsonSchema::class)) {
18+
$this->markTestSkipped('JsonSchema classes are only available in Laravel 12+');
19+
}
20+
}
21+
1322
public function test_before_date_rule_generates_correct_schema(): void
1423
{
1524
$action = new JsonSchemaFromRulesAction;
16-
$schema = new JsonSchemaTypeFactory;
25+
$schema = new \Illuminate\JsonSchema\JsonSchemaTypeFactory;
1726

1827
$rules = [
1928
'event_date' => ['required', 'date', 'before:2025-12-31'],
@@ -22,7 +31,7 @@ public function test_before_date_rule_generates_correct_schema(): void
2231
$result = $action($schema, $rules);
2332

2433
$this->assertArrayHasKey('event_date', $result);
25-
$this->assertInstanceOf(StringType::class, $result['event_date']);
34+
$this->assertInstanceOf(\Illuminate\JsonSchema\Types\StringType::class, $result['event_date']);
2635

2736
$serialized = $result['event_date']->toArray();
2837

@@ -34,7 +43,7 @@ public function test_before_date_rule_generates_correct_schema(): void
3443
public function test_integer_rule_generates_correct_schema(): void
3544
{
3645
$action = new JsonSchemaFromRulesAction;
37-
$schema = new JsonSchemaTypeFactory;
46+
$schema = new \Illuminate\JsonSchema\JsonSchemaTypeFactory;
3847

3948
$rules = [
4049
'age' => ['required', 'integer', 'min:18'],
@@ -43,7 +52,7 @@ public function test_integer_rule_generates_correct_schema(): void
4352
$result = $action($schema, $rules);
4453

4554
$this->assertArrayHasKey('age', $result);
46-
$this->assertInstanceOf(IntegerType::class, $result['age']);
55+
$this->assertInstanceOf(\Illuminate\JsonSchema\Types\IntegerType::class, $result['age']);
4756

4857
$serialized = $result['age']->toArray();
4958

0 commit comments

Comments
 (0)