class DefaultPrinter
@no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
@internal This class is not covered by the backward compatibility promise for PHPUnit
Hierarchy
- class \PHPUnit\TextUI\Output\DefaultPrinter implements \PHPUnit\TextUI\Output\Printer
Expanded class hierarchy of DefaultPrinter
1 file declares its use of DefaultPrinter
- Application.php in vendor/
phpunit/ phpunit/ src/ TextUI/ Application.php
File
-
vendor/
phpunit/ phpunit/ src/ TextUI/ Output/ Printer/ DefaultPrinter.php, line 32
Namespace
PHPUnit\TextUI\OutputView source
final class DefaultPrinter implements Printer {
/**
* @psalm-var closed-resource|resource
*/
private $stream;
private readonly bool $isPhpStream;
private bool $isOpen;
/**
* @throws CannotOpenSocketException
* @throws DirectoryDoesNotExistException
* @throws InvalidSocketException
*/
public static function from(string $out) : self {
return new self($out);
}
/**
* @throws CannotOpenSocketException
* @throws DirectoryDoesNotExistException
* @throws InvalidSocketException
*/
public static function standardOutput() : self {
return new self('php://stdout');
}
/**
* @throws CannotOpenSocketException
* @throws DirectoryDoesNotExistException
* @throws InvalidSocketException
*/
public static function standardError() : self {
return new self('php://stderr');
}
/**
* @throws CannotOpenSocketException
* @throws DirectoryDoesNotExistException
* @throws InvalidSocketException
*/
private function __construct(string $out) {
$this->isPhpStream = str_starts_with($out, 'php://');
if (str_starts_with($out, 'socket://')) {
$tmp = explode(':', str_replace('socket://', '', $out));
if (count($tmp) !== 2) {
throw new InvalidSocketException($out);
}
$stream = @fsockopen($tmp[0], (int) $tmp[1]);
if ($stream === false) {
throw new CannotOpenSocketException($tmp[0], (int) $tmp[1]);
}
$this->stream = $stream;
$this->isOpen = true;
return;
}
if (!$this->isPhpStream && !Filesystem::createDirectory(dirname($out))) {
throw new DirectoryDoesNotExistException(dirname($out));
}
$this->stream = fopen($out, 'wb');
$this->isOpen = true;
}
public function print(string $buffer) : void {
assert($this->isOpen);
fwrite($this->stream, $buffer);
}
public function flush() : void {
if ($this->isOpen && $this->isPhpStream) {
fclose($this->stream);
$this->isOpen = false;
}
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
DefaultPrinter::$isOpen | private | property | ||
DefaultPrinter::$isPhpStream | private | property | ||
DefaultPrinter::$stream | private | property | @psalm-var closed-resource|resource | |
DefaultPrinter::flush | public | function | Overrides Printer::flush | |
DefaultPrinter::from | public static | function | ||
DefaultPrinter::print | public | function | Overrides Printer::print | |
DefaultPrinter::standardError | public static | function | ||
DefaultPrinter::standardOutput | public static | function | ||
DefaultPrinter::__construct | private | function |