Skip to content

Commit aaf038d

Browse files
committed
feat: use absolute path for phpstorm with test
1 parent 5f0a446 commit aaf038d

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed

src/Console/InstallCommand.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -462,17 +462,18 @@ private function installMcpServerConfig(): void
462462
)->toArray()
463463
);
464464

465-
/** @var CodeEnvironment $mcpClient */
465+
/** @var McpClient $mcpClient */
466466
foreach ($this->selectedTargetMcpClient as $mcpClient) {
467467
$ideName = $mcpClient->mcpClientName();
468468
$ideDisplay = str_pad($ideName, $longestIdeName);
469469
$this->output->write(" {$ideDisplay}... ");
470470
$results = [];
471471

472+
$php = $this->getPhpPathForMcpClient($mcpClient);
472473
if ($this->shouldInstallMcp()) {
473474
try {
474-
$artisan = $mcpClient->useAbsolutePathForMcp ? base_path('artisan') : './artisan';
475-
$result = $mcpClient->installMcp('laravel-boost', 'php', [$artisan, 'boost:mcp']);
475+
$artisan = $this->getArtisanPathForMcpClient($mcpClient);
476+
$result = $mcpClient->installMcp('laravel-boost', $php, [$artisan, 'boost:mcp']);
476477

477478
if ($result) {
478479
$results[] = $this->greenTick.' Boost';
@@ -491,7 +492,7 @@ private function installMcpServerConfig(): void
491492
try {
492493
$result = $mcpClient->installMcp(
493494
key: 'herd',
494-
command: 'php',
495+
command: $this->getPhpPathForMcpClient($mcpClient),
495496
args: [$this->herd->mcpPath()],
496497
env: ['SITE_PATH' => base_path()]
497498
);
@@ -523,6 +524,16 @@ private function installMcpServerConfig(): void
523524
}
524525
}
525526

527+
private function getPhpPathForMcpClient(McpClient $mcpClient): string
528+
{
529+
return $mcpClient->useAbsolutePathForMcp() ? PHP_BINARY : 'php';
530+
}
531+
532+
private function getArtisanPathForMcpClient(McpClient $mcpClient): string
533+
{
534+
return $mcpClient->useAbsolutePathForMcp() ? base_path('artisan') : './artisan';
535+
}
536+
526537
/**
527538
* Is the project actually using localization for their new features?
528539
*/

src/Contracts/McpClient.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ interface McpClient
1616
*/
1717
public function mcpClientName(): ?string;
1818

19+
/**
20+
* Whether to use absolute paths for MCP commands.
21+
*/
22+
public function useAbsolutePathForMcp(): bool;
23+
1924
/**
2025
* Install an MCP server configuration in this IDE.
2126
*

src/Install/CodeEnvironment/CodeEnvironment.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ public function mcpClientName(): ?string
3535
return $this->displayName();
3636
}
3737

38+
public function useAbsolutePathForMcp(): bool
39+
{
40+
return $this->useAbsolutePathForMcp;
41+
}
42+
3843
/**
3944
* Get the detection configuration for system-wide installation detection.
4045
*
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Laravel\Boost\Console\InstallCommand;
6+
use Laravel\Boost\Install\CodeEnvironment\Cursor;
7+
use Laravel\Boost\Install\CodeEnvironment\PhpStorm;
8+
use Laravel\Boost\Install\Detection\DetectionStrategyFactory;
9+
10+
test('getPhpPathForMcpClient returns absolute PHP_BINARY for PhpStorm', function () {
11+
$installCommand = new InstallCommand;
12+
$strategyFactory = Mockery::mock(DetectionStrategyFactory::class);
13+
$phpStorm = new PhpStorm($strategyFactory);
14+
15+
$phpPath = invokePrivateMethod($installCommand, 'getPhpPathForMcpClient', [$phpStorm]);
16+
17+
expect($phpPath)->toBe(PHP_BINARY);
18+
});
19+
20+
test('getPhpPathForMcpClient returns php string for Cursor', function () {
21+
$installCommand = new InstallCommand;
22+
$strategyFactory = Mockery::mock(DetectionStrategyFactory::class);
23+
$cursor = new Cursor($strategyFactory);
24+
25+
$phpPath = invokePrivateMethod($installCommand, 'getPhpPathForMcpClient', [$cursor]);
26+
27+
expect($phpPath)->toBe('php');
28+
});
29+
30+
function invokePrivateMethod(object $object, string $methodName, array $parameters = []): mixed
31+
{
32+
$reflection = new ReflectionClass($object);
33+
$method = $reflection->getMethod($methodName);
34+
$method->setAccessible(true);
35+
36+
return $method->invokeArgs($object, $parameters);
37+
}

0 commit comments

Comments
 (0)