diff --git a/src/Helper/ProcessHelper.php b/src/Helper/ProcessHelper.php index b7a8a5c..440d42f 100644 --- a/src/Helper/ProcessHelper.php +++ b/src/Helper/ProcessHelper.php @@ -92,7 +92,10 @@ public function console(array $args): void public function runAndTail(string $code): void { - $start = $this->printPreStart([$code]); + $originalCode = $code; + $code = $this->replaceVariables($code); + + $start = $this->printPreStart([$originalCode]); $process = new Process(['sh', '-c', $code], $this->projectDir); $process->setTimeout($this->timeout); @@ -110,10 +113,10 @@ public function runAndTail(string $code): void }); if (!$process->isSuccessful()) { - throw new \RuntimeException('Execution of ' . $code . ' failed'); + throw new \RuntimeException('Execution of ' . $originalCode . ' failed'); } - $this->printPostStart([$code], $start); + $this->printPostStart([$originalCode], $start); } public function getPluginList(): string @@ -194,4 +197,15 @@ private function validateTimeout(?float $timeout): ?float return $timeout; } + + /** + * Replaces placeholders in hook/script commands with actual values. + * + * Supported placeholders: + * - %php.bin%: The path to the PHP binary that started the current process + */ + private function replaceVariables(string $code): string + { + return str_replace('%php.bin%', escapeshellarg(\PHP_BINARY), $code); + } } diff --git a/tests/Helper/ProcessHelperTest.php b/tests/Helper/ProcessHelperTest.php new file mode 100644 index 0000000..0e923e0 --- /dev/null +++ b/tests/Helper/ProcessHelperTest.php @@ -0,0 +1,28 @@ +runAndTail('echo %php.bin% > ' . $tempFile); + + static::assertFileExists($tempFile); + static::assertStringContainsString(\PHP_BINARY, (string) file_get_contents($tempFile)); + } finally { + @unlink($tempFile); + } + } +}