Skip to content
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

Runtime::getRawBinary() #72

Closed
wants to merge 3 commits into from
Closed
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
16 changes: 12 additions & 4 deletions src/Runtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@
}

/**
* Returns the path to the binary of the current runtime.
* Returns the raw path to the binary of the current runtime.
*/
public function getBinary(): string
public function getRawBinary(): string
{
if (self::$initialized) {
return self::$binary;
}

if (PHP_BINARY !== '') {
self::$binary = escapeshellarg(PHP_BINARY);
self::$binary = PHP_BINARY;
self::$initialized = true;

return self::$binary;
Expand All @@ -115,7 +115,7 @@

foreach ($possibleBinaryLocations as $binary) {
if (is_readable($binary)) {
self::$binary = escapeshellarg($binary);
self::$binary = $binary;

Check warning on line 118 in src/Runtime.php

View check run for this annotation

Codecov / codecov/patch

src/Runtime.php#L118

Added line #L118 was not covered by tests
self::$initialized = true;

return self::$binary;
Expand All @@ -130,6 +130,14 @@
return self::$binary;
}

/**
* Returns the escaped path to the binary of the current runtime.
*/
public function getBinary(): string
{
return escapeshellarg($this->getRawBinary());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after this change even the hardcoded 'php' (line 126) is passed thru escapeshellarg, which wasn't the case before.

tested locally on my macos, that this still works as expected

}

public function getNameWithVersion(): string
{
return $this->getName() . ' ' . $this->getVersion();
Expand Down
5 changes: 5 additions & 0 deletions tests/RuntimeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public function testBinaryCanBeRetrieved(): void
$this->assertNotEmpty((new Runtime)->getBinary());
}

public function testRawBinaryCanBeRetrieved(): void
{
$this->assertNotEmpty((new Runtime)->getRawBinary());
}

public function testIsPhpReturnsTrueWhenRunningOnPhp(): void
{
$this->markTestSkippedWhenRunningOnPhpdbg();
Expand Down