Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Dec 30, 2021
1 parent c066d84 commit d7ec274
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 282 deletions.
233 changes: 32 additions & 201 deletions src/Framework/TestResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use PHPUnit\Event;
use PHPUnit\Framework\TestSize\TestSize;
use PHPUnit\Metadata\Api\Groups;
use PHPUnit\TextUI\Configuration\Registry;
use PHPUnit\Util\Printer;
use Throwable;

Expand Down Expand Up @@ -67,31 +68,31 @@ final class TestResult implements Countable
/**
* @psalm-var list<TestListener>
*/
private array $listeners = [];
private int $runTests = 0;
private float $time = 0;
private bool $convertDeprecationsToExceptions = false;
private bool $convertErrorsToExceptions = true;
private bool $convertNoticesToExceptions = true;
private bool $convertWarningsToExceptions = true;
private bool $stop = false;
private bool $stopOnError = false;
private bool $stopOnFailure = false;
private bool $stopOnWarning = false;
private bool $beStrictAboutTestsThatDoNotTestAnything = true;
private bool $beStrictAboutOutputDuringTests = false;
private bool $enforceTimeLimit = false;
private bool $requireCoverageMetadata = false;
private int $timeoutForSmallTests = 1;
private int $timeoutForMediumTests = 10;
private int $timeoutForLargeTests = 60;
private bool $stopOnRisky = false;
private bool $stopOnIncomplete = false;
private bool $stopOnSkipped = false;
private bool $lastTestFailed = false;
private int $defaultTimeLimit = 0;
private bool $stopOnDefect = false;
private bool $registerMockObjectsFromTestArgumentsRecursively = false;
private array $listeners = [];
private int $runTests = 0;
private float $time = 0;
private bool $stop = false;
private bool $stopOnError;
private bool $stopOnFailure;
private bool $stopOnWarning;
private bool $stopOnRisky;
private bool $stopOnIncomplete;
private bool $stopOnSkipped;
private bool $stopOnDefect;
private bool $lastTestFailed;

public function __construct()
{
$configuration = Registry::get();

$this->stopOnError = $configuration->stopOnError();
$this->stopOnFailure = $configuration->stopOnFailure();
$this->stopOnWarning = $configuration->stopOnWarning();
$this->stopOnRisky = $configuration->stopOnRisky();
$this->stopOnIncomplete = $configuration->stopOnIncomplete();
$this->stopOnSkipped = $configuration->stopOnSkipped();
$this->stopOnDefect = $configuration->stopOnDefect();
}

/**
* @deprecated
Expand Down Expand Up @@ -122,7 +123,7 @@ public function addError(Test $test, Throwable $t, float $time): void
$this->recordError($test, $t);

if ($this->stopOnError || $this->stopOnFailure) {
$this->stop();
$this->stop = true;
}

// @see https://github.com/sebastianbergmann/phpunit/issues/1953
Expand All @@ -141,7 +142,7 @@ public function addError(Test $test, Throwable $t, float $time): void
public function addWarning(Test $test, Warning $e, float $time): void
{
if ($this->stopOnWarning || $this->stopOnDefect) {
$this->stop();
$this->stop = true;
}

$this->recordWarning($test, $e);
Expand Down Expand Up @@ -170,30 +171,30 @@ public function addFailure(Test $test, AssertionFailedError $e, float $time): vo
}

if ($this->stopOnRisky || $this->stopOnDefect) {
$this->stop();
$this->stop = true;
}
} elseif ($e instanceof IncompleteTest) {
$this->recordNotImplemented($test, $e);

$notifyMethod = 'addIncompleteTest';

if ($this->stopOnIncomplete) {
$this->stop();
$this->stop = true;
}
} elseif ($e instanceof SkippedTest) {
$this->recordSkipped($test, $e);

$notifyMethod = 'addSkippedTest';

if ($this->stopOnSkipped) {
$this->stop();
$this->stop = true;
}
} else {
$this->failures[] = new TestFailure($test, $e);
$notifyMethod = 'addFailure';

if ($this->stopOnFailure || $this->stopOnDefect) {
$this->stop();
$this->stop = true;
}
}

Expand Down Expand Up @@ -382,126 +383,6 @@ public function shouldStop(): bool
return $this->stop;
}

public function stop(): void
{
$this->stop = true;
}

public function convertDeprecationsToExceptions(bool $flag): void
{
$this->convertDeprecationsToExceptions = $flag;
}

public function shouldDeprecationsBeConvertedToExceptions(): bool
{
return $this->convertDeprecationsToExceptions;
}

public function convertErrorsToExceptions(bool $flag): void
{
$this->convertErrorsToExceptions = $flag;
}

public function shouldErrorsBeConvertedToExceptions(): bool
{
return $this->convertErrorsToExceptions;
}

public function convertNoticesToExceptions(bool $flag): void
{
$this->convertNoticesToExceptions = $flag;
}

public function shouldNoticeBeConvertedToExceptions(): bool
{
return $this->convertNoticesToExceptions;
}

public function convertWarningsToExceptions(bool $flag): void
{
$this->convertWarningsToExceptions = $flag;
}

public function shouldWarningsBeConvertedToExceptions(): bool
{
return $this->convertWarningsToExceptions;
}

public function stopOnError(bool $flag): void
{
$this->stopOnError = $flag;
}

public function stopOnFailure(bool $flag): void
{
$this->stopOnFailure = $flag;
}

public function stopOnWarning(bool $flag): void
{
$this->stopOnWarning = $flag;
}

public function beStrictAboutTestsThatDoNotTestAnything(bool $flag): void
{
$this->beStrictAboutTestsThatDoNotTestAnything = $flag;
}

public function isStrictAboutTestsThatDoNotTestAnything(): bool
{
return $this->beStrictAboutTestsThatDoNotTestAnything;
}

public function beStrictAboutOutputDuringTests(bool $flag): void
{
$this->beStrictAboutOutputDuringTests = $flag;
}

public function isStrictAboutOutputDuringTests(): bool
{
return $this->beStrictAboutOutputDuringTests;
}

public function enforceTimeLimit(bool $flag): void
{
$this->enforceTimeLimit = $flag;
}

public function enforcesTimeLimit(): bool
{
return $this->enforceTimeLimit;
}

public function requireCoverageMetadata(bool $flag): void
{
$this->requireCoverageMetadata = $flag;
}

public function requiresCoverageMetadata(): bool
{
return $this->requireCoverageMetadata;
}

public function stopOnRisky(bool $flag): void
{
$this->stopOnRisky = $flag;
}

public function stopOnIncomplete(bool $flag): void
{
$this->stopOnIncomplete = $flag;
}

public function stopOnSkipped(bool $flag): void
{
$this->stopOnSkipped = $flag;
}

public function stopOnDefect(bool $flag): void
{
$this->stopOnDefect = $flag;
}

public function time(): float
{
return $this->time;
Expand All @@ -522,56 +403,6 @@ public function wasSuccessfulAndNoTestIsRiskyOrSkippedOrIncomplete(): bool
return $this->wasSuccessful() && $this->allHarmless() && $this->allCompletelyImplemented() && $this->noneSkipped();
}

public function setDefaultTimeLimit(int $timeout): void
{
$this->defaultTimeLimit = $timeout;
}

public function defaultTimeLimit(): int
{
return $this->defaultTimeLimit;
}

public function setTimeoutForSmallTests(int $timeout): void
{
$this->timeoutForSmallTests = $timeout;
}

public function timeoutForSmallTests(): int
{
return $this->timeoutForSmallTests;
}

public function setTimeoutForMediumTests(int $timeout): void
{
$this->timeoutForMediumTests = $timeout;
}

public function timeoutForMediumTests(): int
{
return $this->timeoutForMediumTests;
}

public function setTimeoutForLargeTests(int $timeout): void
{
$this->timeoutForLargeTests = $timeout;
}

public function timeoutForLargeTests(): int
{
return $this->timeoutForLargeTests;
}

public function registerMockObjectsFromTestArgumentsRecursively(bool $flag): void
{
$this->registerMockObjectsFromTestArgumentsRecursively = $flag;
}

public function shouldMockObjectsFromTestArgumentsBeRegisteredRecursively(): bool
{
return $this->registerMockObjectsFromTestArgumentsRecursively;
}

private function recordError(Test $test, Throwable $t): void
{
$this->errors[] = new TestFailure($test, $t);
Expand Down
Loading

0 comments on commit d7ec274

Please sign in to comment.