Skip to content

Commit a8290fb

Browse files
committed
refactor: add unit tests for CodeEnvironment and update InstallCommand for MCP handling
- Introduced comprehensive tests for `CodeEnvironment`, covering detection, MCP installation, and interface logic. - Renamed variables in `InstallCommand` for clarity (`selectedTargetIdes` -> `selectedTargetMcpClient`). - Replaced `enact` method in `InstallCommand` with `performInstallation`. - Adjusted MCP installation logic for streamlined and consistent implementation.
1 parent 1a80964 commit a8290fb

File tree

2 files changed

+395
-19
lines changed

2 files changed

+395
-19
lines changed

src/Console/InstallCommand.php

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class InstallCommand extends Command
4242
private Collection $selectedTargetAgents;
4343

4444
/** @var Collection<int, CodeEnvironment> */
45-
private Collection $selectedTargetIdes;
45+
private Collection $selectedTargetMcpClient;
4646

4747
/** @var Collection<int, string> */
4848
private Collection $selectedBoostFeatures;
@@ -67,7 +67,7 @@ public function handle(CodeEnvironmentsDetector $codeEnvironmentsDetector, Herd
6767
$this->displayBoostHeader();
6868
$this->discoverEnvironment();
6969
$this->collectInstallationPreferences();
70-
$this->enact();
70+
$this->performInstallation();
7171
$this->outro();
7272
}
7373

@@ -82,7 +82,7 @@ private function bootstrap(CodeEnvironmentsDetector $codeEnvironmentsDetector, H
8282
$this->redCross = $this->red('');
8383

8484
$this->selectedTargetAgents = collect();
85-
$this->selectedTargetIdes = collect();
85+
$this->selectedTargetMcpClient = collect();
8686

8787
$this->projectName = basename(base_path());
8888
}
@@ -117,20 +117,18 @@ private function collectInstallationPreferences(): void
117117
{
118118
$this->selectedBoostFeatures = $this->selectBoostFeatures();
119119
$this->enforceTests = $this->determineTestEnforcement(ask: false);
120-
$this->selectedTargetIdes = $this->selectTargetIdes();
120+
$this->selectedTargetMcpClient = $this->selectTargetIdes();
121121
$this->selectedTargetAgents = $this->selectTargetAgents();
122122
}
123123

124-
private function enact(): void
124+
private function performInstallation(): void
125125
{
126-
if ($this->shouldInstallAiGuidelines() && $this->selectedTargetAgents->isNotEmpty()) {
127-
$this->enactGuidelines();
128-
}
126+
$this->installGuidelines();
129127

130128
usleep(750000);
131129

132-
if (($this->shouldInstallMcp() || $this->shouldInstallHerdMcp()) && $this->selectedTargetIdes->isNotEmpty()) {
133-
$this->enactMcpServers();
130+
if (($this->shouldInstallMcp() || $this->shouldInstallHerdMcp()) && $this->selectedTargetMcpClient->isNotEmpty()) {
131+
$this->installMcpServerConfig();
134132
}
135133
}
136134

@@ -159,7 +157,7 @@ private function outro(): void
159157
{
160158
$label = 'https://boost.laravel.com/installed';
161159

162-
$ideNames = $this->selectedTargetIdes->map(fn ($ide) => 'i:'.$ide->ideName())->toArray();
160+
$ideNames = $this->selectedTargetMcpClient->map(fn ($ide) => 'i:'.$ide->ideName())->toArray();
163161
$agentNames = $this->selectedTargetAgents->map(fn ($agent) => 'a:'.$agent->agentName())->toArray();
164162
$boostFeatures = $this->selectedBoostFeatures->map(fn ($feature) => 'b:'.$feature)->toArray();
165163

@@ -336,7 +334,7 @@ private function selectCodeEnvironments(string $type, string $label): Collection
336334
return $selectedClasses->map(fn ($className) => $availableEnvironments->first(fn ($env) => get_class($env) === $className));
337335
}
338336

339-
protected function enactGuidelines(): void
337+
private function installGuidelines(): void
340338
{
341339
if (! $this->shouldInstallAiGuidelines()) {
342340
return;
@@ -417,27 +415,40 @@ private function shouldInstallHerdMcp(): bool
417415
return $this->selectedBoostFeatures->contains('herd_mcp');
418416
}
419417

420-
private function enactMcpServers(): void
418+
private function installMcpServerConfig(): void
421419
{
420+
if (! $this->shouldInstallMcp() && ! $this->shouldInstallHerdMcp()) {
421+
return;
422+
}
423+
424+
if ($this->selectedTargetMcpClient->isEmpty()) {
425+
$this->info('No agents selected for guideline installation.');
426+
427+
return;
428+
}
422429
$this->newLine();
423430
$this->info(' Installing MCP servers to your selected IDEs');
424431
$this->newLine();
425432

426433
usleep(750000);
427434

428435
$failed = [];
429-
$longestIdeName = max(1, ...$this->selectedTargetIdes->map(fn ($ide) => Str::length($ide->ideName()))->toArray());
436+
$longestIdeName = max(
437+
1,
438+
...$this->selectedTargetMcpClient->map(
439+
fn ($mcpClient) => Str::length($mcpClient->ideName())
440+
)->toArray()
441+
);
430442

431-
foreach ($this->selectedTargetIdes as $ide) {
432-
$ideName = $ide->ideName();
443+
foreach ($this->selectedTargetMcpClient as $mcpClient) {
444+
$ideName = $mcpClient->ideName();
433445
$ideDisplay = str_pad($ideName, $longestIdeName);
434446
$this->output->write(" {$ideDisplay}... ");
435447
$results = [];
436448

437-
// Install Laravel Boost MCP if enabled
438449
if ($this->shouldInstallMcp()) {
439450
try {
440-
$result = $ide->installMcp('laravel-boost', 'php', ['./artisan', 'boost:mcp']);
451+
$result = $mcpClient->installMcp('laravel-boost', 'php', ['./artisan', 'boost:mcp']);
441452

442453
if ($result) {
443454
$results[] = $this->greenTick.' Boost';
@@ -454,7 +465,7 @@ private function enactMcpServers(): void
454465
// Install Herd MCP if enabled
455466
if ($this->shouldInstallHerdMcp()) {
456467
try {
457-
$result = $ide->installMcp(
468+
$result = $mcpClient->installMcp(
458469
key: 'herd',
459470
command: 'php',
460471
args: [$this->herd->mcpPath()],

0 commit comments

Comments
 (0)