diff --git a/src/Workflow/Infrastructure/Command/TeamleaderAgentRunnerCommand.php b/src/Workflow/Infrastructure/Command/TeamleaderAgentRunnerCommand.php index 28887f8..bb4cf92 100644 --- a/src/Workflow/Infrastructure/Command/TeamleaderAgentRunnerCommand.php +++ b/src/Workflow/Infrastructure/Command/TeamleaderAgentRunnerCommand.php @@ -46,6 +46,8 @@ public function execute( InputInterface $input, OutputInterface $output, ): int { + $output->writeln('Summoning the Teamleader agent... it was in the break room again.'); + $configs = $this->productConfigFacade->getAllProductConfigs(); if (count($configs) === 0) { diff --git a/tests/Unit/Workflow/TeamleaderAgentRunnerCommandTest.php b/tests/Unit/Workflow/TeamleaderAgentRunnerCommandTest.php new file mode 100644 index 0000000..bd6ae58 --- /dev/null +++ b/tests/Unit/Workflow/TeamleaderAgentRunnerCommandTest.php @@ -0,0 +1,116 @@ +createStub(RolloutService::class), + $this->createStub(EntityManagerInterface::class), + $this->createStub(LoggerInterface::class), + $this->createStub(LockService::class), + $this->createStub(ParameterBagInterface::class), + new FakeProductConfigFacadeForTeamleaderRunner([]), + $messageBus, + ); + $tester = new CommandTester($command); + + $exitCode = $tester->execute([]); + + expect($exitCode)->toBe(Command::SUCCESS); + expect($tester->getDisplay())->toContain('Summoning the Teamleader agent... it was in the break room again.'); + expect($tester->getDisplay())->toContain('No product configs found.'); + expect($messageBus->dispatchedMessages)->toBe([]); + }); + + it('shows funny message and dispatches one message per config', function (): void { + $messageBus = new FakeMessageBusForTeamleaderRunner(); + $command = new TeamleaderAgentRunnerCommand( + $this->createStub(RolloutService::class), + $this->createStub(EntityManagerInterface::class), + $this->createStub(LoggerInterface::class), + $this->createStub(LockService::class), + $this->createStub(ParameterBagInterface::class), + new FakeProductConfigFacadeForTeamleaderRunner([ + new ProductConfigDto('cfg-1', 'Config One', 'https://github.com/acme/demo-one', 'cursor-key-1', 'gh-token-1'), + new ProductConfigDto('cfg-2', 'Config Two', 'https://github.com/acme/demo-two', 'cursor-key-2', 'gh-token-2'), + ]), + $messageBus, + ); + $tester = new CommandTester($command); + + $exitCode = $tester->execute([]); + + expect($exitCode)->toBe(Command::SUCCESS); + expect($tester->getDisplay())->toContain('Summoning the Teamleader agent... it was in the break room again.'); + expect($tester->getDisplay())->toContain('Found 2 product config(s), dispatching Teamleader messages...'); + expect($messageBus->dispatchedMessages)->toHaveCount(2); + expect($messageBus->dispatchedMessages[0])->toBeInstanceOf(ProcessProductConfigMessage::class); + expect($messageBus->dispatchedMessages[1])->toBeInstanceOf(ProcessProductConfigMessage::class); + expect($messageBus->dispatchedMessages[0]->productConfigId)->toBe('cfg-1'); + expect($messageBus->dispatchedMessages[1]->productConfigId)->toBe('cfg-2'); + }); +}); + +final class FakeProductConfigFacadeForTeamleaderRunner implements ProductConfigFacadeInterface +{ + /** + * @param list $configs + */ + public function __construct( + private readonly array $configs, + ) { + } + + public function getAllProductConfigs(): array + { + return $this->configs; + } + + public function getProductConfigById(string $id): ?ProductConfigDto + { + foreach ($this->configs as $config) { + if ($config->id === $id) { + return $config; + } + } + + return null; + } + + public function findMatchingProductConfigs(string $githubOwner, string $githubRepo): array + { + return []; + } +} + +final class FakeMessageBusForTeamleaderRunner implements MessageBusInterface +{ + /** @var list */ + public array $dispatchedMessages = []; + + /** + * @param list $stamps + */ + public function dispatch(object $message, array $stamps = []): Envelope + { + $this->dispatchedMessages[] = $message; + + return new Envelope($message, $stamps); + } +}