Skip to content

Commit

Permalink
Remove windows stdout workarounds
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm authored and sebastianbergmann committed Mar 28, 2024
1 parent 4e96332 commit eeddef5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 56 deletions.
39 changes: 3 additions & 36 deletions src/Util/PHP/DefaultPhpProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@
use function is_array;
use function is_resource;
use function proc_close;
use function proc_get_status;
use function proc_open;
use function rewind;
use function stream_get_contents;
use function sys_get_temp_dir;
use function tempnam;
use function time_nanosleep;
use function unlink;
use PHPUnit\Framework\Exception;

Expand Down Expand Up @@ -57,14 +54,6 @@ public function runJob(string $job, array $settings = []): array
return $this->runProcess($job, $settings);
}

/**
* Returns an array of file handles to be used in place of pipes.
*/
protected function getHandles(): array
{
return [];
}

/**
* Handles creating the child process and returning the STDOUT and STDERR.
*
Expand All @@ -75,8 +64,6 @@ protected function getHandles(): array
*/
protected function runProcess(string $job, array $settings): array
{
$handles = $this->getHandles();

$env = null;

if ($this->env) {
Expand All @@ -92,9 +79,9 @@ protected function runProcess(string $job, array $settings): array
}

$pipeSpec = [
0 => $handles[0] ?? ['pipe', 'r'],
1 => $handles[1] ?? ['pipe', 'w'],
2 => $handles[2] ?? ['pipe', 'w'],
0 => ['pipe', 'r'],
1 => ['pipe', 'w'],
2 => ['pipe', 'w'],
];

if ($this->stderrRedirection) {
Expand All @@ -121,10 +108,6 @@ protected function runProcess(string $job, array $settings): array

fclose($pipes[0]);

while (proc_get_status($process)['running'] === true) {
time_nanosleep(0, 100000);
}

$stderr = $stdout = '';

if (isset($pipes[1])) {
Expand All @@ -139,22 +122,6 @@ protected function runProcess(string $job, array $settings): array
fclose($pipes[2]);
}

if (isset($handles[1])) {
rewind($handles[1]);

$stdout = stream_get_contents($handles[1]);

fclose($handles[1]);
}

if (isset($handles[2])) {
rewind($handles[2]);

$stderr = stream_get_contents($handles[2]);

fclose($handles[2]);
}

proc_close($process);

$this->cleanup();
Expand Down
20 changes: 0 additions & 20 deletions src/Util/PHP/WindowsPhpProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,13 @@
*/
namespace PHPUnit\Util\PHP;

use function tmpfile;
use PHPUnit\Framework\Exception;

/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*
* @see https://bugs.php.net/bug.php?id=51800
*/
final class WindowsPhpProcess extends DefaultPhpProcess
{
/**
* @throws Exception
* @throws PhpProcessException
*/
protected function getHandles(): array
{
if (false === $stdout_handle = tmpfile()) {
throw new PhpProcessException(
'A temporary file could not be created; verify that your TEMP environment variable is writable',
);
}

return [
1 => $stdout_handle,
];
}

protected function useTemporaryFile(): bool
{
return false;
Expand Down

0 comments on commit eeddef5

Please sign in to comment.