Skip to content

Commit

Permalink
Remove code that is no longer needed
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jun 15, 2022
1 parent 27ac4a6 commit 850bd7f
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 82 deletions.
12 changes: 3 additions & 9 deletions .psalm/baseline.xml
Expand Up @@ -9,11 +9,7 @@
</UndefinedInterfaceMethod>
</file>
<file src="src/Event/Emitter/DispatchingEmitter.php">
<MissingThrowsDocblock occurrences="62">
<code>dispatch</code>
<code>dispatch</code>
<code>dispatch</code>
<code>dispatch</code>
<MissingThrowsDocblock occurrences="58">
<code>dispatch</code>
<code>dispatch</code>
<code>dispatch</code>
Expand Down Expand Up @@ -432,7 +428,7 @@
<InvalidScalarArgument occurrences="1">
<code>$var</code>
</InvalidScalarArgument>
<MissingThrowsDocblock occurrences="12">
<MissingThrowsDocblock occurrences="11">
<code>CodeCoverage::instance()</code>
<code>CodeCoverage::instance()</code>
<code>CodeCoverage::instance()</code>
Expand All @@ -441,7 +437,6 @@
<code>GlobalState::getIncludedFilesAsString()</code>
<code>cacheDirectory</code>
<code>saveConfigurationForChildProcess</code>
<code>stop</code>
</MissingThrowsDocblock>
</file>
<file src="src/Framework/TestSuite.php">
Expand Down Expand Up @@ -607,10 +602,9 @@
<code>RawCodeCoverageData::fromXdebugWithoutPathCoverage([])</code>
<code>RawCodeCoverageData::fromXdebugWithoutPathCoverage([])</code>
</InternalMethod>
<MissingThrowsDocblock occurrences="4">
<MissingThrowsDocblock occurrences="3">
<code>append</code>
<code>cacheDirectory</code>
<code>stop</code>
</MissingThrowsDocblock>
<PossiblyInvalidArgument occurrences="1">
<code>$sections['FILEEOF']</code>
Expand Down
7 changes: 2 additions & 5 deletions src/Framework/TestCase.php
Expand Up @@ -1658,7 +1658,6 @@ private function handleDependencies(): bool
$this->result->addFailure(
$this,
new SkippedDueToDependencyOnLargerTestException,
0
);

return false;
Expand Down Expand Up @@ -1707,10 +1706,9 @@ private function markErrorForInvalidDependency(?ExecutionOrderDependency $depend
$this->result->addError(
$this,
$exception,
0
);

$this->result->endTest($this, 0);
$this->result->endTest($this);
}

private function markSkippedForMissingDependency(ExecutionOrderDependency $dependency): void
Expand All @@ -1734,10 +1732,9 @@ private function markSkippedForMissingDependency(ExecutionOrderDependency $depen
new SkippedDueToMissingDependencyException(
$dependency->getTarget()
),
0
);

$this->result->endTest($this, 0);
$this->result->endTest($this);
}

/**
Expand Down
20 changes: 4 additions & 16 deletions src/Framework/TestResult.php
Expand Up @@ -64,7 +64,6 @@ final class TestResult implements Countable
*/
private array $skipped = [];
private int $runTests = 0;
private float $time = 0;
private bool $stop = false;
private bool $stopOnError;
private bool $stopOnFailure;
Expand All @@ -88,7 +87,7 @@ public function __construct()
$this->stopOnDefect = $configuration->stopOnDefect();
}

public function addError(Test $test, Throwable $t, float $time): void
public function addError(Test $test, Throwable $t): void
{
$this->recordError($test, $t);

Expand All @@ -97,21 +96,18 @@ public function addError(Test $test, Throwable $t, float $time): void
}

$this->lastTestFailed = true;
$this->time += $time;
}

public function addWarning(Test $test, Warning $e, float $time): void
public function addWarning(Test $test, Warning $e): void
{
if ($this->stopOnWarning || $this->stopOnDefect) {
$this->stop = true;
}

$this->recordWarning($test, $e);

$this->time += $time;
}

public function addFailure(Test $test, AssertionFailedError $e, float $time): void
public function addFailure(Test $test, AssertionFailedError $e): void
{
if ($e instanceof RiskyTest) {
$this->recordRisky($test, $e);
Expand Down Expand Up @@ -144,7 +140,6 @@ public function addFailure(Test $test, AssertionFailedError $e, float $time): vo
}

$this->lastTestFailed = true;
$this->time += $time;
}

public function startTestSuite(): void
Expand All @@ -165,7 +160,7 @@ public function startTest(Test $test): void
$this->runTests += count($test);
}

public function endTest(Test $test, float $time): void
public function endTest(Test $test): void
{
if (!$this->lastTestFailed && $test instanceof TestCase) {
$class = $test::class;
Expand All @@ -183,8 +178,6 @@ public function endTest(Test $test, float $time): void
'result' => $test->result(),
'size' => $size,
];

$this->time += $time;
}

if ($this->lastTestFailed && $test instanceof TestCase) {
Expand Down Expand Up @@ -273,11 +266,6 @@ public function shouldStop(): bool
return $this->stop;
}

public function time(): float
{
return $this->time;
}

private function recordError(Test $test, Throwable $t): void
{
$this->errors[] = new TestFailure($test, $t);
Expand Down
21 changes: 4 additions & 17 deletions src/Framework/TestRunner.php
Expand Up @@ -35,7 +35,6 @@
use SebastianBergmann\Invoker\Invoker;
use SebastianBergmann\Invoker\TimeoutException;
use SebastianBergmann\Template\Template;
use SebastianBergmann\Timer\Timer;
use Throwable;

/**
Expand Down Expand Up @@ -89,9 +88,6 @@ public function run(TestCase $test, TestResult $result): void
CodeCoverage::start($test);
}

$timer = new Timer;
$timer->start();

try {
if ($this->canTimeLimitBeEnforced() &&
$this->shouldTimeLimitBeEnforced($test)) {
Expand Down Expand Up @@ -135,8 +131,6 @@ public function run(TestCase $test, TestResult $result): void
$error = true;
}

$time = $timer->stop()->asSeconds();

$test->addToAssertionCount(Assert::getCount());

if ($this->configuration->reportUselessTests() &&
Expand All @@ -157,7 +151,6 @@ public function run(TestCase $test, TestResult $result): void
$result->addFailure(
$test,
$riskyDueToMissingCodeCoverageMetadataException,
$time
);

$risky = true;
Expand Down Expand Up @@ -185,7 +178,6 @@ public function run(TestCase $test, TestResult $result): void
new Warning(
$cce->getMessage()
),
$time
);
}
}
Expand All @@ -211,11 +203,11 @@ public function run(TestCase $test, TestResult $result): void
ErrorHandler::instance()->disable();

if ($error && isset($e)) {
$result->addError($test, $e, $time);
$result->addError($test, $e);
} elseif ($failure && isset($e)) {
$result->addFailure($test, $e, $time);
$result->addFailure($test, $e);
} elseif ($warning && isset($e)) {
$result->addWarning($test, $e, $time);
$result->addWarning($test, $e);
} elseif (isset($unintentionallyCoveredCodeError)) {
Event\Facade::emitter()->testConsideredRisky(
$test->valueObjectForEvents(),
Expand All @@ -225,7 +217,6 @@ public function run(TestCase $test, TestResult $result): void
$result->addFailure(
$test,
$unintentionallyCoveredCodeError,
$time
);
} elseif ($this->configuration->reportUselessTests() &&
!$test->doesNotPerformAssertions() &&
Expand All @@ -235,7 +226,6 @@ public function run(TestCase $test, TestResult $result): void
$result->addFailure(
$test,
$riskyBecauseNoAssertionsWerePerformedException,
$time
);

Event\Facade::emitter()->testConsideredRisky(
Expand All @@ -252,7 +242,6 @@ public function run(TestCase $test, TestResult $result): void
$result->addFailure(
$test,
$riskyDueToUnexpectedAssertionsException,
$time
);

Event\Facade::emitter()->testConsideredRisky(
Expand All @@ -270,7 +259,6 @@ public function run(TestCase $test, TestResult $result): void
$result->addFailure(
$test,
$riskyDueToOutputException,
$time
);

Event\Facade::emitter()->testConsideredRisky(
Expand All @@ -279,7 +267,7 @@ public function run(TestCase $test, TestResult $result): void
);
}

$result->endTest($test, $time);
$result->endTest($test);

if ($test->wasPrepared()) {
Event\Facade::emitter()->testFinished(
Expand Down Expand Up @@ -502,7 +490,6 @@ private function runTestWithTimeout(TestCase $test, TestResult $result): bool
$result->addFailure(
$test,
$riskyDueToTimeoutException,
$_timeout
);

Event\Facade::emitter()->testConsideredRisky(
Expand Down
13 changes: 6 additions & 7 deletions src/Framework/TestSuite.php
Expand Up @@ -360,8 +360,8 @@ public function run(TestResult $result): void
} catch (SkippedTestSuiteError $error) {
foreach ($this->tests() as $test) {
$result->startTest($test);
$result->addFailure($test, $error, 0);
$result->endTest($test, 0);
$result->addFailure($test, $error);
$result->endTest($test);
}

$result->endTestSuite($this);
Expand Down Expand Up @@ -393,18 +393,17 @@ public function run(TestResult $result): void
$result->startTest($test);

if (!$errorAdded) {
$result->addError($test, $t, 0);
$result->addError($test, $t);

$errorAdded = true;
} else {
$result->addFailure(
$test,
new SkippedDueToErrorInHookMethodException,
0
);
}

$result->endTest($test, 0);
$result->endTest($test);
}

$result->endTestSuite($this);
Expand Down Expand Up @@ -458,8 +457,8 @@ public function run(TestResult $result): void
$placeholderTest->setName($afterClassMethod);

$result->startTest($placeholderTest);
$result->addFailure($placeholderTest, $error, 0);
$result->endTest($placeholderTest, 0);
$result->addFailure($placeholderTest, $error);
$result->endTest($placeholderTest);
}
}
}
Expand Down
20 changes: 7 additions & 13 deletions src/Runner/PhptTestCase.php
Expand Up @@ -59,7 +59,6 @@
use PHPUnit\Util\PHP\AbstractPhpProcess;
use SebastianBergmann\CodeCoverage\Data\RawCodeCoverageData;
use SebastianBergmann\Template\Template;
use SebastianBergmann\Timer\Timer;
use Throwable;

/**
Expand Down Expand Up @@ -121,8 +120,8 @@ public function run(TestResult $result): void
$e = new Exception($e->getMessage());

$result->startTest($this);
$result->addError($this, $e, 0);
$result->endTest($this, 0);
$result->addError($this, $e);
$result->endTest($this);

$emitter->testPrepared($this->valueObjectForEvents());
$emitter->testErrored($this->valueObjectForEvents(), EventThrowable::from($e));
Expand Down Expand Up @@ -184,11 +183,7 @@ public function run(TestResult $result): void
);
}

$timer = new Timer;
$timer->start();

$jobResult = $this->phpUtil->runJob($code, $this->stringifyIni($settings));
$time = $timer->stop()->asSeconds();
$this->output = $jobResult['stdout'] ?? '';

if (CodeCoverage::isActive() && ($coverage = $this->cleanupForCoverage())) {
Expand Down Expand Up @@ -223,30 +218,30 @@ public function run(TestResult $result): void
);
}

$result->addFailure($this, $failure, $time);
$result->addFailure($this, $failure);

if ($failure instanceof IncompleteTestError) {
$emitter->testMarkedAsIncomplete($this->valueObjectForEvents(), EventThrowable::from($failure));
} else {
$emitter->testFailed($this->valueObjectForEvents(), EventThrowable::from($failure));
}
} catch (Throwable $t) {
$result->addError($this, $t, $time);
$result->addError($this, $t);

$emitter->testErrored($this->valueObjectForEvents(), EventThrowable::from($t));
}

if ($xfail !== false && $result->allCompletelyImplemented()) {
$e = new IncompleteTestError('XFAIL section but test passes');

$result->addFailure($this, $e, $time);
$result->addFailure($this, $e);

$emitter->testMarkedAsIncomplete($this->valueObjectForEvents(), EventThrowable::from($e));
}

$this->runClean($sections, CodeCoverage::isActive());

$result->endTest($this, $time);
$result->endTest($this);

$emitter->testFinished($this->valueObjectForEvents(), 1);
}
Expand Down Expand Up @@ -414,9 +409,8 @@ private function shouldTestBeSkipped(array &$sections, TestResult $result, array
$result->addFailure(
$this,
new SyntheticSkippedError($message, 0, $trace[0]['file'], $trace[0]['line'], $trace),
0
);
$result->endTest($this, 0);
$result->endTest($this);

EventFacade::emitter()->testSkipped(
$this->valueObjectForEvents(),
Expand Down

0 comments on commit 850bd7f

Please sign in to comment.