Skip to content

Commit c14e28d

Browse files
authored
tests: use dataprovider (#164)
* Use dataprovider * -
1 parent cb2c967 commit c14e28d

File tree

1 file changed

+30
-38
lines changed

1 file changed

+30
-38
lines changed

tests/Chain/ToolBox/ToolBoxTest.php

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use PhpLlm\LlmChain\Tests\Fixture\Tool\ToolReturningJsonSerializable;
2121
use PhpLlm\LlmChain\Tests\Fixture\Tool\ToolReturningStringable;
2222
use PHPUnit\Framework\Attributes\CoversClass;
23+
use PHPUnit\Framework\Attributes\DataProvider;
2324
use PHPUnit\Framework\Attributes\Test;
2425
use PHPUnit\Framework\Attributes\UsesClass;
2526
use PHPUnit\Framework\TestCase;
@@ -157,58 +158,49 @@ public function executeWithUnknownTool(): void
157158
}
158159

159160
#[Test]
160-
public function executeWithToolReturningString(): void
161+
#[DataProvider('executeProvider')]
162+
public function execute(string $expected, string $toolName, array $toolPayload = []): void
161163
{
162164
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)),
167167
);
168168
}
169169

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
172174
{
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' => [
174182
'{"foo":"bar"}',
175-
$this->toolBox->execute(new ToolCall('call_1234', 'tool_returning_array'))
176-
);
177-
}
183+
'tool_returning_array',
184+
];
178185

179-
#[Test]
180-
public function executeWithToolReturningJsonSerializable(): void
181-
{
182-
self::assertSame(
186+
yield 'tool_returning_json_serializable' => [
183187
'{"foo":"bar"}',
184-
$this->toolBox->execute(new ToolCall('call_1234', 'tool_returning_json_serializable'))
185-
);
186-
}
188+
'tool_returning_json_serializable',
189+
];
187190

188-
#[Test]
189-
public function executeWithToolReturningInteger(): void
190-
{
191-
self::assertSame(
191+
yield 'tool_returning_integer' => [
192192
'42',
193-
$this->toolBox->execute(new ToolCall('call_1234', 'tool_returning_integer'))
194-
);
195-
}
193+
'tool_returning_integer',
194+
];
196195

197-
#[Test]
198-
public function executeWithToolReturningFloat(): void
199-
{
200-
self::assertSame(
196+
yield 'tool_returning_float' => [
201197
'42.42',
202-
$this->toolBox->execute(new ToolCall('call_1234', 'tool_returning_float'))
203-
);
204-
}
198+
'tool_returning_float',
199+
];
205200

206-
#[Test]
207-
public function executeWithToolReturningStringable(): void
208-
{
209-
self::assertSame(
201+
yield 'tool_returning_stringable' => [
210202
'Hi!',
211-
$this->toolBox->execute(new ToolCall('call_1234', 'tool_returning_stringable'))
212-
);
203+
'tool_returning_stringable',
204+
];
213205
}
214206
}

0 commit comments

Comments
 (0)