Skip to content

Commit aaeb2e0

Browse files
committed
added PhpInterpreter::withOption()
1 parent d327b8c commit aaeb2e0

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/Runner/Job.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace Tester\Runner;
1111

12-
use Tester\Helpers;
1312
use function count, is_array, is_resource;
1413
use const DIRECTORY_SEPARATOR, PHP_OS_FAMILY;
1514

@@ -92,17 +91,12 @@ public function run(bool $async = false): void
9291
putenv("$name=$value");
9392
}
9493

95-
$args = [];
96-
foreach ($this->test->getArguments() as $value) {
97-
$args[] = is_array($value)
98-
? Helpers::escapeArg("--$value[0]=$value[1]")
99-
: Helpers::escapeArg($value);
100-
}
101-
94+
$args = array_map(fn($arg) => is_array($arg) ? "--$arg[0]=$arg[1]" : $arg, $this->test->getArguments());
10295
$this->duration = -microtime(as_float: true);
10396
$this->proc = proc_open(
104-
$this->interpreter->getCommandLine()
105-
. ' -d register_argc_argv=on ' . Helpers::escapeArg($this->test->getFile()) . ' ' . implode(' ', $args),
97+
$this->interpreter
98+
->withArguments(['-d register_argc_argv=on', $this->test->getFile(), ...$args])
99+
->getCommandLine(),
106100
[
107101
['pipe', 'r'],
108102
['pipe', 'w'],

src/Runner/PhpInterpreter.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,20 @@ public function __construct(string $path, array $args = [])
7777
}
7878

7979

80-
public function withPhpIniOption(string $name, ?string $value = null): static
80+
public function withArguments(array $args): static
8181
{
8282
$me = clone $this;
83-
$me->commandLine .= ' -d ' . Helpers::escapeArg($name . ($value === null ? '' : "=$value"));
83+
$me->commandLine .= ' ' . implode(' ', array_map([Helpers::class, 'escapeArg'], $args));
8484
return $me;
8585
}
8686

8787

88+
public function withPhpIniOption(string $name, ?string $value = null): static
89+
{
90+
return $this->withArguments(['-d ' . $name . ($value === null ? '' : "=$value")]);
91+
}
92+
93+
8894
public function getCommandLine(): string
8995
{
9096
return $this->commandLine;

0 commit comments

Comments
 (0)