File tree Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,10 @@ public function __construct(
25
25
public function arguments (): array
26
26
{
27
27
if (is_string ($ this ->arguments )) {
28
+ if ($ this ->arguments === '' || $ this ->arguments === '0 ' ) {
29
+ return [];
30
+ }
31
+
28
32
/** @var string $arguments */
29
33
$ arguments = $ this ->arguments ;
30
34
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ use Prism \Prism \ValueObjects \ToolCall ;
6
+
7
+ it ('handles empty string arguments correctly ' , function (): void {
8
+ $ toolCall = new ToolCall (
9
+ id: 'test-id ' ,
10
+ name: 'test-tool ' ,
11
+ arguments: ''
12
+ );
13
+
14
+ expect ($ toolCall ->arguments ())->toBe ([]);
15
+ });
16
+
17
+ it ('handles null arguments correctly ' , function (): void {
18
+ $ toolCall = new ToolCall (
19
+ id: 'test-id ' ,
20
+ name: 'test-tool ' ,
21
+ arguments: []
22
+ );
23
+
24
+ expect ($ toolCall ->arguments ())->toBe ([]);
25
+ });
26
+
27
+ it ('handles valid JSON string arguments correctly ' , function (): void {
28
+ $ toolCall = new ToolCall (
29
+ id: 'test-id ' ,
30
+ name: 'test-tool ' ,
31
+ arguments: '{"param1": "value1", "param2": 42} '
32
+ );
33
+
34
+ expect ($ toolCall ->arguments ())->toBe ([
35
+ 'param1 ' => 'value1 ' ,
36
+ 'param2 ' => 42 ,
37
+ ]);
38
+ });
39
+
40
+ it ('handles array arguments correctly ' , function (): void {
41
+ $ arguments = ['param1 ' => 'value1 ' , 'param2 ' => 42 ];
42
+
43
+ $ toolCall = new ToolCall (
44
+ id: 'test-id ' ,
45
+ name: 'test-tool ' ,
46
+ arguments: $ arguments
47
+ );
48
+
49
+ expect ($ toolCall ->arguments ())->toBe ($ arguments );
50
+ });
51
+
52
+ it ('throws exception for malformed JSON string arguments ' , function (): void {
53
+ $ toolCall = new ToolCall (
54
+ id: 'test-id ' ,
55
+ name: 'test-tool ' ,
56
+ arguments: '{"invalid json" '
57
+ );
58
+
59
+ expect (fn (): array => $ toolCall ->arguments ())->toThrow (JsonException::class);
60
+ });
You can’t perform that action at this time.
0 commit comments