Skip to content

Commit

Permalink
Use better typing for internal property
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug authored and sebastianbergmann committed Dec 31, 2019
1 parent d1f0e90 commit b03c1b8
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/TextUI/TestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ final class TestRunner extends BaseTestRunner
private $loader;

/**
* @var ResultPrinter
* @var Printer&TestListener
*/
private $printer;

Expand Down Expand Up @@ -269,11 +269,11 @@ public function doRun(Test $suite, array $arguments = [], bool $exit = true): Te

if ($this->printer === null) {
if (isset($arguments['printer'])) {
if ($arguments['printer'] instanceof Printer) {
if ($arguments['printer'] instanceof Printer && $arguments['printer'] instanceof TestListener) {
$this->printer = $arguments['printer'];
} elseif (\is_string($arguments['printer']) && \class_exists($arguments['printer'], false)) {
try {
$class = new \ReflectionClass($arguments['printer']);
new \ReflectionClass($arguments['printer']);
// @codeCoverageIgnoreStart
} catch (\ReflectionException $e) {
throw new Exception(
Expand All @@ -284,7 +284,7 @@ public function doRun(Test $suite, array $arguments = [], bool $exit = true): Te
}
// @codeCoverageIgnoreEnd

if ($class->isSubclassOf(ResultPrinter::class)) {
if (is_subclass_of($arguments['printer'], ResultPrinter::class)) {
$this->printer = $this->createPrinter($arguments['printer'], $arguments);
}
}
Expand Down Expand Up @@ -1303,6 +1303,11 @@ private function writeMessage(string $type, string $message): void
$this->messagePrinted = true;
}

/**
* @template T as Printer
* @param class-string<T> $class
* @return T
*/
private function createPrinter(string $class, array $arguments): Printer
{
return new $class(
Expand Down

0 comments on commit b03c1b8

Please sign in to comment.