This repository was archived by the owner on Mar 15, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTeamleaderAgentRunnerCommandTest.php
More file actions
116 lines (100 loc) · 4.56 KB
/
Copy pathTeamleaderAgentRunnerCommandTest.php
File metadata and controls
116 lines (100 loc) · 4.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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);
}
}