Skip to content

Commit be0d5f8

Browse files
committed
Add happy path test for PlatformInvokeCommand
Add test case that verifies successful command execution with proper platform invocation, result handling, and output display.
1 parent 4eac977 commit be0d5f8

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/ai-bundle/tests/Command/PlatformInvokeCommandTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,46 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\AI\AiBundle\Command\PlatformInvokeCommand;
1616
use Symfony\AI\AiBundle\Exception\InvalidArgumentException;
17+
use Symfony\AI\Platform\PlatformInterface;
18+
use Symfony\AI\Platform\Result\InMemoryRawResult;
19+
use Symfony\AI\Platform\Result\ResultPromise;
20+
use Symfony\AI\Platform\Result\TextResult;
21+
use Symfony\Component\Console\Command\Command;
1722
use Symfony\Component\Console\Tester\CommandTester;
1823
use Symfony\Component\DependencyInjection\ServiceLocator;
1924

2025
final class PlatformInvokeCommandTest extends TestCase
2126
{
27+
public function testExecuteSuccessfully()
28+
{
29+
$textResult = new TextResult('Hello! How can I assist you?');
30+
$rawResult = new InMemoryRawResult([]);
31+
$promise = new ResultPromise(fn () => $textResult, $rawResult);
32+
33+
$platform = $this->createMock(PlatformInterface::class);
34+
$platform->method('invoke')
35+
->with('gpt-4o-mini', self::anything())
36+
->willReturn($promise);
37+
38+
$platforms = $this->createMock(ServiceLocator::class);
39+
$platforms->method('getProvidedServices')->willReturn(['openai' => 'service_class']);
40+
$platforms->method('has')->with('openai')->willReturn(true);
41+
$platforms->method('get')->with('openai')->willReturn($platform);
42+
43+
$command = new PlatformInvokeCommand($platforms);
44+
$commandTester = new CommandTester($command);
45+
46+
$exitCode = $commandTester->execute([
47+
'platform' => 'openai',
48+
'model' => 'gpt-4o-mini',
49+
'message' => 'Hello!',
50+
]);
51+
52+
self::assertSame(Command::SUCCESS, $exitCode);
53+
self::assertStringContainsString('Response:', $commandTester->getDisplay());
54+
self::assertStringContainsString('Hello! How can I assist you?', $commandTester->getDisplay());
55+
}
56+
2257
public function testExecuteWithNonExistentPlatform()
2358
{
2459
$platforms = $this->createMock(ServiceLocator::class);

0 commit comments

Comments
 (0)