From 402995bf29a11ed3f4485ecf44d3932705332a8e Mon Sep 17 00:00:00 2001 From: Fabio Ivona Date: Thu, 23 Jun 2022 14:24:10 +0200 Subject: [PATCH] implement our own Printer class because PhpUnit DefaultPrinter has become final --- src/Logging/JUnit.php | 2 +- src/Support/Printer.php | 59 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 src/Support/Printer.php diff --git a/src/Logging/JUnit.php b/src/Logging/JUnit.php index 207912ac..22c05afd 100644 --- a/src/Logging/JUnit.php +++ b/src/Logging/JUnit.php @@ -12,7 +12,7 @@ declare(strict_types=1); namespace Pest\Logging; -use PHPUnit\Util\Printer; +use Pest\Support\Printer; /** * @internal This class is not covered by the backward compatibility promise for PHPUnit diff --git a/src/Support/Printer.php b/src/Support/Printer.php new file mode 100644 index 00000000..f121fc19 --- /dev/null +++ b/src/Support/Printer.php @@ -0,0 +1,59 @@ +stream = fsockopen($tmp[0], (int) $tmp[1]); + $this->isOpen = true; + + return; + } + + $this->isPhpStream = str_starts_with($out, 'php://'); + + if (!$this->isPhpStream && !Filesystem::createDirectory(dirname($out))) { + throw new Exception(sprintf('Directory "%s" was not created', dirname($out))); + } + + $this->stream = fopen($out, 'wb'); + $this->isOpen = true; + } + + final public function print(string $buffer): void + { + assert($this->isOpen); + assert($this->stream !== false); + + fwrite($this->stream, $buffer); + } + + final public function flush(): void + { + if ($this->isOpen && $this->isPhpStream && $this->stream !== false) { + fclose($this->stream); + + $this->isOpen = false; + } + } +}