Skip to content

Fix PHPStorm using absolute paths #109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Aug 14, 2025
Merged
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
9 changes: 5 additions & 4 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,17 +462,18 @@ private function installMcpServerConfig(): void
)->toArray()
);

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

$php = $mcpClient->getPhpPath();
if ($this->shouldInstallMcp()) {
try {
$artisan = $mcpClient->useAbsolutePathForMcp ? base_path('artisan') : './artisan';
$result = $mcpClient->installMcp('laravel-boost', 'php', [$artisan, 'boost:mcp']);
$artisan = $mcpClient->getArtisanPath();
$result = $mcpClient->installMcp('laravel-boost', $php, [$artisan, 'boost:mcp']);

if ($result) {
$results[] = $this->greenTick.' Boost';
Expand All @@ -491,7 +492,7 @@ private function installMcpServerConfig(): void
try {
$result = $mcpClient->installMcp(
key: 'herd',
command: 'php',
command: $php,
args: [$this->herd->mcpPath()],
env: ['SITE_PATH' => base_path()]
);
Expand Down
15 changes: 15 additions & 0 deletions src/Contracts/McpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ interface McpClient
*/
public function mcpClientName(): ?string;

/**
* Whether to use absolute paths for MCP commands.
*/
public function useAbsolutePathForMcp(): bool;

/**
* Get the PHP executable path for this MCP client.
*/
public function getPhpPath(): string;

/**
* Get the artisan path for this MCP client.
*/
public function getArtisanPath(): string;

/**
* Install an MCP server configuration in this IDE.
*
Expand Down
16 changes: 16 additions & 0 deletions src/Install/CodeEnvironment/CodeEnvironment.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,22 @@ public function mcpClientName(): ?string
return $this->displayName();
}

public function useAbsolutePathForMcp(): bool
{
return $this->useAbsolutePathForMcp;
}

public function getPhpPath(): string
{
return $this->useAbsolutePathForMcp() ? PHP_BINARY : 'php';
}

public function getArtisanPath(): string
{
return $this->useAbsolutePathForMcp() ? base_path('artisan') : './artisan';

}

/**
* Get the detection configuration for system-wide installation detection.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

use Laravel\Boost\Install\CodeEnvironment\Cursor;
use Laravel\Boost\Install\CodeEnvironment\PhpStorm;
use Laravel\Boost\Install\Detection\DetectionStrategyFactory;

test('PhpStorm returns absolute PHP_BINARY path', function () {
$strategyFactory = Mockery::mock(DetectionStrategyFactory::class);
$phpStorm = new PhpStorm($strategyFactory);

expect($phpStorm->getPhpPath())->toBe(PHP_BINARY);
});

test('PhpStorm returns absolute artisan path', function () {
$strategyFactory = Mockery::mock(DetectionStrategyFactory::class);
$phpStorm = new PhpStorm($strategyFactory);

$artisanPath = $phpStorm->getArtisanPath();

// Should be an absolute path ending with 'artisan'
expect($artisanPath)->toEndWith('artisan')
->and($artisanPath)->not()->toBe('./artisan');
});

test('Cursor returns relative php string', function () {
$strategyFactory = Mockery::mock(DetectionStrategyFactory::class);
$cursor = new Cursor($strategyFactory);

expect($cursor->getPhpPath())->toBe('php');
});

test('Cursor returns relative artisan path', function () {
$strategyFactory = Mockery::mock(DetectionStrategyFactory::class);
$cursor = new Cursor($strategyFactory);

expect($cursor->getArtisanPath())->toBe('./artisan');
});