Merge pull request #534 from fabio-ivona/fix-phpunit-printer-refactor

Fix issues after PHPUnit refactoring
This commit is contained in:
Fabio Ivona
2022-08-02 10:58:54 +02:00
committed by GitHub
3 changed files with 69 additions and 3 deletions

View File

@ -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

59
src/Support/Printer.php Normal file
View File

@ -0,0 +1,59 @@
<?php
declare(strict_types=1);
namespace Pest\Support;
use PHPUnit\Util\Exception;
use PHPUnit\Util\Filesystem;
abstract class Printer implements \PHPUnit\Util\Printer
{
/** @var resource|false */
private $stream;
private bool $isPhpStream;
private bool $isOpen;
private function __construct(string $out)
{
if (str_starts_with($out, 'socket://')) {
$tmp = explode(':', str_replace('socket://', '', $out));
if (count($tmp) !== 2) {
throw new Exception(sprintf('"%s" does not match "socket://hostname:port" format', $out));
}
$this->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;
}
}
}

View File

@ -8,8 +8,15 @@ use PHPUnit\Framework\TestCase;
/**
* @internal
* @phpstan-ignore-next-line
*/
abstract class IgnorableTestCase extends TestCase
class IgnorableTestCase extends TestCase
{
// ..
/**
* @test
*/
public function fake(): void
{
self::markTestIncomplete();
}
}