Skip to content

Commit

Permalink
fix: Handle the case where SERVER['PWD'] is not set (#219)
Browse files Browse the repository at this point in the history
Closes #204.
  • Loading branch information
theofidry committed Apr 1, 2024
1 parent 7f71f7a commit eb38e5b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ParallelExecutorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ private static function getNoopClosure(): Closure

private static function getScriptPath(): string
{
$pwd = $_SERVER['PWD'];
$pwd = $_SERVER['PWD'] ?? getcwd();
$scriptName = $_SERVER['SCRIPT_NAME'];

return (str_starts_with($scriptName, $pwd)
Expand Down
2 changes: 1 addition & 1 deletion tests/EnvironmentVariables.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function setVariables(array $environmentVariables): callable
/**
* @return callable():void
*/
private static function setVariable(string $name, string $value): callable
private static function setVariable(string $name, ?string $value): callable
{
if (array_key_exists($name, $_SERVER)) {
$previousValue = $_SERVER[$name];
Expand Down
15 changes: 15 additions & 0 deletions tests/ParallelExecutorFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,21 @@ public static function defaultValuesProvider(): iterable
$expectedScriptPath,
$workingDirectory,
];

// This can happen e.g. when executed with Docker.
// See https://github.com/webmozarts/console-parallelization/issues/204.
yield 'PWD is not set' => [
[
'PHP_BINARY' => $phpExecutable,
'PWD' => null,
'SCRIPT_NAME' => __DIR__.'/../bin/console',
],
$workingDirectory,
$progressSymbol,
$phpExecutable,
$expectedScriptPath,
$workingDirectory,
];
}

// See https://github.com/webmozarts/console-parallelization/issues/223
Expand Down

0 comments on commit eb38e5b

Please sign in to comment.