Skip to content
This repository was archived by the owner on Mar 15, 2026. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public function execute(
InputInterface $input,
OutputInterface $output,
): int {
$output->writeln('<comment>Summoning the Teamleader agent... it was in the break room again.</comment>');

$configs = $this->productConfigFacade->getAllProductConfigs();

if (count($configs) === 0) {
Expand Down
116 changes: 116 additions & 0 deletions tests/Unit/Workflow/TeamleaderAgentRunnerCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

declare(strict_types=1);

use App\ProductConfig\Facade\Dto\ProductConfigDto;
use App\ProductConfig\Facade\ProductConfigFacadeInterface;
use App\TeamleaderAgent\Facade\Message\ProcessProductConfigMessage;
use App\Workflow\Infrastructure\Command\TeamleaderAgentRunnerCommand;
use Doctrine\ORM\EntityManagerInterface;
use EnterpriseToolingForSymfony\SharedBundle\Locking\Service\LockService;
use EnterpriseToolingForSymfony\SharedBundle\Rollout\Service\RolloutService;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\MessageBusInterface;

describe('TeamleaderAgentRunnerCommand', function (): void {
it('shows funny message and succeeds when no configs exist', 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([]),
$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<ProductConfigDto> $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<object> */
public array $dispatchedMessages = [];

/**
* @param list<Symfony\Component\Messenger\Stamp\StampInterface> $stamps
*/
public function dispatch(object $message, array $stamps = []): Envelope
{
$this->dispatchedMessages[] = $message;

return new Envelope($message, $stamps);
}
}
Loading