Skip to content

Commit 16b8181

Browse files
author
klapaudius
committed
Add comprehensive test cases for ToolParamsValidator
This commit introduces detailed unit tests for various validation scenarios in ToolParamsValidator. These include cases for valid arguments, missing required arguments, empty optional and required arguments, invalid arguments not in the schema, and incorrect argument types. It ensures improved test coverage and robustness of the validation logic.
1 parent 56305d5 commit 16b8181

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tests/Services/ToolService/ToolParamsValidatorTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
#[Small]
1111
class ToolParamsValidatorTest extends TestCase
1212
{
13+
/**
14+
* Tests the `validate` method of `ToolParamsValidator` with valid arguments.
15+
*
16+
* Ensures that the provided valid arguments pass the validation process defined
17+
* by the tool schema without throwing any exceptions or errors.
18+
*/
1319
public function test_validate_with_valid_arguments(): void
1420
{
1521
$toolSchema = [
@@ -30,6 +36,14 @@ public function test_validate_with_valid_arguments(): void
3036
ToolParamsValidator::validate($toolSchema, $arguments);
3137
}
3238

39+
/**
40+
* Tests the `validate` method of `ToolParamsValidator` with missing required arguments.
41+
*
42+
* Verifies that the validation process throws a `ToolParamsValidatorException` when
43+
* the provided arguments are missing one or more keys that are marked as required
44+
* in the tool schema. Confirms the exception contains specific error details about
45+
* the missing argument(s).
46+
*/
3347
public function test_validate_with_missing_required_argument(): void
3448
{
3549
$toolSchema = [
@@ -55,6 +69,9 @@ public function test_validate_with_missing_required_argument(): void
5569
}
5670
}
5771

72+
/**
73+
* Tests the validation process when an optional argument is provided with an empty string value.
74+
*/
5875
public function test_validate_with_empty_optional_argument(): void
5976
{
6077
$toolSchema = [
@@ -70,6 +87,9 @@ public function test_validate_with_empty_optional_argument(): void
7087
ToolParamsValidator::validate($toolSchema, $arguments);
7188
}
7289

90+
/**
91+
* Tests the validation process when an invalid argument that is not defined in the schema is provided.
92+
*/
7393
public function test_validate_with_invalid_argument_not_in_schema(): void
7494
{
7595
$toolSchema = [
@@ -95,6 +115,9 @@ public function test_validate_with_invalid_argument_not_in_schema(): void
95115
}
96116
}
97117

118+
/**
119+
* Tests the validation process when a required argument is provided with an invalid type.
120+
*/
98121
public function test_validate_with_invalid_argument_type(): void
99122
{
100123
$toolSchema = [
@@ -121,6 +144,9 @@ public function test_validate_with_invalid_argument_type(): void
121144
}
122145
}
123146

147+
/**
148+
* Tests the validation process when a required argument is provided with an empty string value.
149+
*/
124150
public function test_validate_with_empty_required_argument(): void
125151
{
126152
$toolSchema = [

0 commit comments

Comments
 (0)