-
Notifications
You must be signed in to change notification settings - Fork 150
Expand file tree
/
Copy pathNumberSchemaDefinitionTest.php
More file actions
191 lines (160 loc) · 5.72 KB
/
Copy pathNumberSchemaDefinitionTest.php
File metadata and controls
191 lines (160 loc) · 5.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?php
/*
* This file is part of the official PHP MCP SDK.
*
* A collaboration between Symfony and the PHP Foundation.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mcp\Tests\Unit\Schema\Elicitation;
use Mcp\Exception\InvalidArgumentException;
use Mcp\Schema\Elicitation\NumberSchemaDefinition;
use PHPUnit\Framework\TestCase;
final class NumberSchemaDefinitionTest extends TestCase
{
public function testConstructorWithMinimalParams(): void
{
$schema = new NumberSchemaDefinition('Age');
$this->assertSame('Age', $schema->title);
$this->assertFalse($schema->integerOnly);
$this->assertNull($schema->description);
$this->assertNull($schema->default);
$this->assertNull($schema->minimum);
$this->assertNull($schema->maximum);
}
public function testConstructorWithAllParams(): void
{
$schema = new NumberSchemaDefinition(
title: 'Party Size',
integerOnly: true,
description: 'Number of guests',
default: 2,
minimum: 1,
maximum: 10,
);
$this->assertSame('Party Size', $schema->title);
$this->assertTrue($schema->integerOnly);
$this->assertSame('Number of guests', $schema->description);
$this->assertSame(2, $schema->default);
$this->assertSame(1, $schema->minimum);
$this->assertSame(10, $schema->maximum);
}
public function testConstructorWithFloatValues(): void
{
$schema = new NumberSchemaDefinition(
title: 'Temperature',
default: 36.5,
minimum: 35.0,
maximum: 42.0,
);
$this->assertSame(36.5, $schema->default);
$this->assertSame(35.0, $schema->minimum);
$this->assertSame(42.0, $schema->maximum);
}
public function testConstructorWithMinimumGreaterThanMaximum(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('minimum cannot be greater than maximum');
new NumberSchemaDefinition('Test', minimum: 10, maximum: 5);
}
public function testConstructorWithDefaultBelowMinimum(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('default value cannot be less than minimum');
new NumberSchemaDefinition('Test', default: 5, minimum: 10);
}
public function testConstructorWithDefaultAboveMaximum(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('default value cannot be greater than maximum');
new NumberSchemaDefinition('Test', default: 15, maximum: 10);
}
public function testConstructorWithNonIntegerDefaultWhenIntegerOnly(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('default value must be an integer when integerOnly is true');
new NumberSchemaDefinition('Test', integerOnly: true, default: 5.5);
}
public function testFromArrayWithIntegerType(): void
{
$schema = NumberSchemaDefinition::fromArray([
'type' => 'integer',
'title' => 'Count',
]);
$this->assertTrue($schema->integerOnly);
}
public function testFromArrayWithNumberType(): void
{
$schema = NumberSchemaDefinition::fromArray([
'type' => 'number',
'title' => 'Price',
]);
$this->assertFalse($schema->integerOnly);
}
public function testFromArrayWithAllParams(): void
{
$schema = NumberSchemaDefinition::fromArray([
'type' => 'integer',
'title' => 'Party Size',
'description' => 'Number of guests',
'default' => 2,
'minimum' => 1,
'maximum' => 10,
]);
$this->assertSame('Party Size', $schema->title);
$this->assertTrue($schema->integerOnly);
$this->assertSame('Number of guests', $schema->description);
$this->assertSame(2, $schema->default);
$this->assertSame(1, $schema->minimum);
$this->assertSame(10, $schema->maximum);
}
public function testFromArrayWithMissingTitle(): void
{
$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage('Missing or invalid "title"');
/* @phpstan-ignore argument.type */
NumberSchemaDefinition::fromArray(['type' => 'integer']);
}
public function testJsonSerializeAsInteger(): void
{
$schema = new NumberSchemaDefinition(
title: 'Count',
integerOnly: true,
);
$this->assertSame([
'type' => 'integer',
'title' => 'Count',
], $schema->jsonSerialize());
}
public function testJsonSerializeAsNumber(): void
{
$schema = new NumberSchemaDefinition(
title: 'Price',
integerOnly: false,
);
$this->assertSame([
'type' => 'number',
'title' => 'Price',
], $schema->jsonSerialize());
}
public function testJsonSerializeWithAllParams(): void
{
$schema = new NumberSchemaDefinition(
title: 'Party Size',
integerOnly: true,
description: 'Number of guests',
default: 2,
minimum: 1,
maximum: 10,
);
$this->assertSame([
'type' => 'integer',
'title' => 'Party Size',
'description' => 'Number of guests',
'default' => 2,
'minimum' => 1,
'maximum' => 10,
], $schema->jsonSerialize());
}
}