|
20 | 20 | use PhpLlm\LlmChain\Tests\Fixture\Tool\ToolReturningJsonSerializable;
|
21 | 21 | use PhpLlm\LlmChain\Tests\Fixture\Tool\ToolReturningStringable;
|
22 | 22 | use PHPUnit\Framework\Attributes\CoversClass;
|
| 23 | +use PHPUnit\Framework\Attributes\DataProvider; |
23 | 24 | use PHPUnit\Framework\Attributes\Test;
|
24 | 25 | use PHPUnit\Framework\Attributes\UsesClass;
|
25 | 26 | use PHPUnit\Framework\TestCase;
|
@@ -157,58 +158,49 @@ public function executeWithUnknownTool(): void
|
157 | 158 | }
|
158 | 159 |
|
159 | 160 | #[Test]
|
160 |
| - public function executeWithToolReturningString(): void |
| 161 | + #[DataProvider('executeProvider')] |
| 162 | + public function execute(string $expected, string $toolName, array $toolPayload = []): void |
161 | 163 | {
|
162 | 164 | self::assertSame(
|
163 |
| - 'Hello says "3".', |
164 |
| - $this->toolBox->execute( |
165 |
| - new ToolCall('call_1234', 'tool_required_params', ['text' => 'Hello', 'number' => 3]) |
166 |
| - ) |
| 165 | + $expected, |
| 166 | + $this->toolBox->execute(new ToolCall('call_1234', $toolName, $toolPayload)), |
167 | 167 | );
|
168 | 168 | }
|
169 | 169 |
|
170 |
| - #[Test] |
171 |
| - public function executeWithToolReturningArray(): void |
| 170 | + /** |
| 171 | + * @return iterable<array{0: non-empty-string, 1: non-empty-string, 2?: array}> |
| 172 | + */ |
| 173 | + public static function executeProvider(): iterable |
172 | 174 | {
|
173 |
| - self::assertSame( |
| 175 | + yield 'tool_required_params' => [ |
| 176 | + 'Hello says "3".', |
| 177 | + 'tool_required_params', |
| 178 | + ['text' => 'Hello', 'number' => 3], |
| 179 | + ]; |
| 180 | + |
| 181 | + yield 'tool_returning_array' => [ |
174 | 182 | '{"foo":"bar"}',
|
175 |
| - $this->toolBox->execute(new ToolCall('call_1234', 'tool_returning_array')) |
176 |
| - ); |
177 |
| - } |
| 183 | + 'tool_returning_array', |
| 184 | + ]; |
178 | 185 |
|
179 |
| - #[Test] |
180 |
| - public function executeWithToolReturningJsonSerializable(): void |
181 |
| - { |
182 |
| - self::assertSame( |
| 186 | + yield 'tool_returning_json_serializable' => [ |
183 | 187 | '{"foo":"bar"}',
|
184 |
| - $this->toolBox->execute(new ToolCall('call_1234', 'tool_returning_json_serializable')) |
185 |
| - ); |
186 |
| - } |
| 188 | + 'tool_returning_json_serializable', |
| 189 | + ]; |
187 | 190 |
|
188 |
| - #[Test] |
189 |
| - public function executeWithToolReturningInteger(): void |
190 |
| - { |
191 |
| - self::assertSame( |
| 191 | + yield 'tool_returning_integer' => [ |
192 | 192 | '42',
|
193 |
| - $this->toolBox->execute(new ToolCall('call_1234', 'tool_returning_integer')) |
194 |
| - ); |
195 |
| - } |
| 193 | + 'tool_returning_integer', |
| 194 | + ]; |
196 | 195 |
|
197 |
| - #[Test] |
198 |
| - public function executeWithToolReturningFloat(): void |
199 |
| - { |
200 |
| - self::assertSame( |
| 196 | + yield 'tool_returning_float' => [ |
201 | 197 | '42.42',
|
202 |
| - $this->toolBox->execute(new ToolCall('call_1234', 'tool_returning_float')) |
203 |
| - ); |
204 |
| - } |
| 198 | + 'tool_returning_float', |
| 199 | + ]; |
205 | 200 |
|
206 |
| - #[Test] |
207 |
| - public function executeWithToolReturningStringable(): void |
208 |
| - { |
209 |
| - self::assertSame( |
| 201 | + yield 'tool_returning_stringable' => [ |
210 | 202 | 'Hi!',
|
211 |
| - $this->toolBox->execute(new ToolCall('call_1234', 'tool_returning_stringable')) |
212 |
| - ); |
| 203 | + 'tool_returning_stringable', |
| 204 | + ]; |
213 | 205 | }
|
214 | 206 | }
|
0 commit comments