|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Symfony\AI\AiBundle\Command\PlatformInvokeCommand;
|
16 | 16 | 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; |
17 | 22 | use Symfony\Component\Console\Tester\CommandTester;
|
18 | 23 | use Symfony\Component\DependencyInjection\ServiceLocator;
|
19 | 24 |
|
20 | 25 | final class PlatformInvokeCommandTest extends TestCase
|
21 | 26 | {
|
| 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 | + |
22 | 57 | public function testExecuteWithNonExistentPlatform()
|
23 | 58 | {
|
24 | 59 | $platforms = $this->createMock(ServiceLocator::class);
|
|
0 commit comments