|
9 | 9 | $result = $tool->handle(['code' => 'return 2 + 2;']); |
10 | 10 |
|
11 | 11 | expect($result)->isToolResult() |
12 | | - ->toolJsonContent(function ($data) { |
13 | | - expect($data['result'])->toBe(4) |
14 | | - ->and($data['type'])->toBe('integer'); |
15 | | - }); |
| 12 | + ->toolJsonContentToMatchArray([ |
| 13 | + 'result' => 4, |
| 14 | + 'type' => 'integer', |
| 15 | + ]); |
16 | 16 | }); |
17 | 17 |
|
18 | 18 | test('executes code with output', function () { |
19 | 19 | $tool = new Tinker; |
20 | 20 | $result = $tool->handle(['code' => 'echo "Hello World"; return "test";']); |
21 | 21 |
|
22 | 22 | expect($result)->isToolResult() |
23 | | - ->toolJsonContent(function ($data) { |
24 | | - expect($data['result'])->toBe('test') |
25 | | - ->and($data['output'])->toBe('Hello World') |
26 | | - ->and($data['type'])->toBe('string'); |
27 | | - }); |
| 23 | + ->toolJsonContentToMatchArray([ |
| 24 | + 'result' => 'test', |
| 25 | + 'output' => 'Hello World', |
| 26 | + 'type' => 'string', |
| 27 | + ]); |
28 | 28 | }); |
29 | 29 |
|
30 | 30 | test('accesses laravel facades', function () { |
31 | 31 | $tool = new Tinker; |
32 | 32 | $result = $tool->handle(['code' => 'return config("app.name");']); |
33 | 33 |
|
34 | 34 | expect($result)->isToolResult() |
35 | | - ->toolJsonContent(function ($data) { |
36 | | - expect($data['result'])->toBeString() |
37 | | - ->and($data['result'])->toBe(config('app.name')) |
38 | | - ->and($data['type'])->toBe('string'); |
39 | | - }); |
| 35 | + ->toolJsonContentToMatchArray([ |
| 36 | + 'result' => config('app.name'), |
| 37 | + 'type' => 'string', |
| 38 | + ]); |
40 | 39 | }); |
41 | 40 |
|
42 | 41 | test('creates objects', function () { |
43 | 42 | $tool = new Tinker; |
44 | 43 | $result = $tool->handle(['code' => 'return new stdClass();']); |
45 | 44 |
|
46 | 45 | expect($result)->isToolResult() |
47 | | - ->toolJsonContent(function ($data) { |
48 | | - expect($data['type'])->toBe('object') |
49 | | - ->and($data['class'])->toBe('stdClass'); |
50 | | - }); |
| 46 | + ->toolJsonContentToMatchArray([ |
| 47 | + 'type' => 'object', |
| 48 | + 'class' => 'stdClass', |
| 49 | + ]); |
51 | 50 | }); |
52 | 51 |
|
53 | 52 | test('handles syntax errors', function () { |
|
56 | 55 |
|
57 | 56 | expect($result)->isToolResult() |
58 | 57 | ->toolHasNoError() |
| 58 | + ->toolJsonContentToMatchArray([ |
| 59 | + 'type' => 'ParseError', |
| 60 | + ]) |
59 | 61 | ->toolJsonContent(function ($data) { |
60 | | - expect($data)->toHaveKey('error') |
61 | | - ->and($data)->toHaveKey('type') |
62 | | - ->and($data['type'])->toBe('ParseError'); |
| 62 | + expect($data)->toHaveKey('error'); |
63 | 63 | }); |
64 | 64 | }); |
65 | 65 |
|
|
69 | 69 |
|
70 | 70 | expect($result)->isToolResult() |
71 | 71 | ->toolHasNoError() |
| 72 | + ->toolJsonContentToMatchArray([ |
| 73 | + 'type' => 'Exception', |
| 74 | + 'error' => 'Test error', |
| 75 | + ]) |
72 | 76 | ->toolJsonContent(function ($data) { |
73 | | - expect($data)->toHaveKey('error') |
74 | | - ->and($data['type'])->toBe('Exception') |
75 | | - ->and($data['error'])->toBe('Test error'); |
| 77 | + expect($data)->toHaveKey('error'); |
76 | 78 | }); |
77 | 79 | }); |
78 | 80 |
|
|
81 | 83 | $result = $tool->handle(['code' => 'echo "First"; echo "Second"; return "done";']); |
82 | 84 |
|
83 | 85 | expect($result)->isToolResult() |
84 | | - ->toolJsonContent(function ($data) { |
85 | | - expect($data['result'])->toBe('done') |
86 | | - ->and($data['output'])->toBe('FirstSecond'); |
87 | | - }); |
| 86 | + ->toolJsonContentToMatchArray([ |
| 87 | + 'result' => 'done', |
| 88 | + 'output' => 'FirstSecond', |
| 89 | + ]); |
88 | 90 | }); |
89 | 91 |
|
90 | 92 | test('executes code with different return types', function (string $code, mixed $expectedResult, string $expectedType) { |
91 | 93 | $tool = new Tinker; |
92 | 94 | $result = $tool->handle(['code' => $code]); |
93 | 95 |
|
94 | 96 | expect($result)->isToolResult() |
95 | | - ->toolJsonContent(function ($data) use ($expectedResult, $expectedType) { |
96 | | - expect($data['result'])->toBe($expectedResult) |
97 | | - ->and($data['type'])->toBe($expectedType); |
98 | | - }); |
| 97 | + ->toolJsonContentToMatchArray([ |
| 98 | + 'result' => $expectedResult, |
| 99 | + 'type' => $expectedType, |
| 100 | + ]); |
99 | 101 | })->with([ |
100 | 102 | 'integer' => ['return 42;', 42, 'integer'], |
101 | 103 | 'string' => ['return "hello";', 'hello', 'string'], |
|
111 | 113 | $result = $tool->handle(['code' => '']); |
112 | 114 |
|
113 | 115 | expect($result)->isToolResult() |
114 | | - ->toolJsonContent(function ($data) { |
115 | | - expect($data['result'])->toBeFalse() |
116 | | - ->and($data['type'])->toBe('boolean'); |
117 | | - }); |
| 116 | + ->toolJsonContentToMatchArray([ |
| 117 | + 'result' => false, |
| 118 | + 'type' => 'boolean', |
| 119 | + ]); |
118 | 120 | }); |
119 | 121 |
|
120 | 122 | test('handles code with no return statement', function () { |
121 | 123 | $tool = new Tinker; |
122 | 124 | $result = $tool->handle(['code' => '$x = 5;']); |
123 | 125 |
|
124 | 126 | expect($result)->isToolResult() |
125 | | - ->toolJsonContent(function ($data) { |
126 | | - expect($data['result'])->toBeNull() |
127 | | - ->and($data['type'])->toBe('NULL'); |
128 | | - }); |
| 127 | + ->toolJsonContentToMatchArray([ |
| 128 | + 'result' => null, |
| 129 | + 'type' => 'NULL', |
| 130 | + ]); |
129 | 131 | }); |
130 | 132 |
|
131 | 133 | test('should register only in local environment', function () { |
|
144 | 146 | $result = $tool->handle(['code' => 'return 2 + 2;', 'timeout' => 10]); |
145 | 147 |
|
146 | 148 | expect($result)->isToolResult() |
147 | | - ->toolJsonContent(function ($data) { |
148 | | - expect($data['result'])->toBe(4) |
149 | | - ->and($data['type'])->toBe('integer'); |
150 | | - }); |
| 149 | + ->toolJsonContentToMatchArray([ |
| 150 | + 'result' => 4, |
| 151 | + 'type' => 'integer', |
| 152 | + ]); |
151 | 153 | }); |
152 | 154 |
|
153 | 155 | test('uses default timeout when not specified', function () { |
154 | 156 | $tool = new Tinker; |
155 | 157 | $result = $tool->handle(['code' => 'return 2 + 2;']); |
156 | 158 |
|
157 | 159 | expect($result)->isToolResult() |
158 | | - ->toolJsonContent(function ($data) { |
159 | | - expect($data['result'])->toBe(4) |
160 | | - ->and($data['type'])->toBe('integer'); |
161 | | - }); |
| 160 | + ->toolJsonContentToMatchArray([ |
| 161 | + 'result' => 4, |
| 162 | + 'type' => 'integer', |
| 163 | + ]); |
162 | 164 | }); |
163 | 165 |
|
164 | 166 | test('times out when code takes too long', function () { |
|
0 commit comments