Skip to content

Commit 5dce9e9

Browse files
authored
Merge pull request #109 from laravel/fix-phpstorm-on-windows-v1
Fix PHPStorm using absolute paths
2 parents 81165c0 + e9c56dc commit 5dce9e9

File tree

4 files changed

+75
-4
lines changed

4 files changed

+75
-4
lines changed

src/Console/InstallCommand.php

Lines changed: 5 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 = $mcpClient->getPhpPath();
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 = $mcpClient->getArtisanPath();
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: $php,
495496
args: [$this->herd->mcpPath()],
496497
env: ['SITE_PATH' => base_path()]
497498
);

src/Contracts/McpClient.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ 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+
24+
/**
25+
* Get the PHP executable path for this MCP client.
26+
*/
27+
public function getPhpPath(): string;
28+
29+
/**
30+
* Get the artisan path for this MCP client.
31+
*/
32+
public function getArtisanPath(): string;
33+
1934
/**
2035
* Install an MCP server configuration in this IDE.
2136
*

src/Install/CodeEnvironment/CodeEnvironment.php

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

38+
public function useAbsolutePathForMcp(): bool
39+
{
40+
return $this->useAbsolutePathForMcp;
41+
}
42+
43+
public function getPhpPath(): string
44+
{
45+
return $this->useAbsolutePathForMcp() ? PHP_BINARY : 'php';
46+
}
47+
48+
public function getArtisanPath(): string
49+
{
50+
return $this->useAbsolutePathForMcp() ? base_path('artisan') : './artisan';
51+
52+
}
53+
3854
/**
3955
* Get the detection configuration for system-wide installation detection.
4056
*
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Laravel\Boost\Install\CodeEnvironment\Cursor;
6+
use Laravel\Boost\Install\CodeEnvironment\PhpStorm;
7+
use Laravel\Boost\Install\Detection\DetectionStrategyFactory;
8+
9+
test('PhpStorm returns absolute PHP_BINARY path', function () {
10+
$strategyFactory = Mockery::mock(DetectionStrategyFactory::class);
11+
$phpStorm = new PhpStorm($strategyFactory);
12+
13+
expect($phpStorm->getPhpPath())->toBe(PHP_BINARY);
14+
});
15+
16+
test('PhpStorm returns absolute artisan path', function () {
17+
$strategyFactory = Mockery::mock(DetectionStrategyFactory::class);
18+
$phpStorm = new PhpStorm($strategyFactory);
19+
20+
$artisanPath = $phpStorm->getArtisanPath();
21+
22+
// Should be an absolute path ending with 'artisan'
23+
expect($artisanPath)->toEndWith('artisan')
24+
->and($artisanPath)->not()->toBe('./artisan');
25+
});
26+
27+
test('Cursor returns relative php string', function () {
28+
$strategyFactory = Mockery::mock(DetectionStrategyFactory::class);
29+
$cursor = new Cursor($strategyFactory);
30+
31+
expect($cursor->getPhpPath())->toBe('php');
32+
});
33+
34+
test('Cursor returns relative artisan path', function () {
35+
$strategyFactory = Mockery::mock(DetectionStrategyFactory::class);
36+
$cursor = new Cursor($strategyFactory);
37+
38+
expect($cursor->getArtisanPath())->toBe('./artisan');
39+
});

0 commit comments

Comments
 (0)