diff --git a/src/CodeCoverage.php b/src/CodeCoverage.php index 374df0191..314bd968a 100644 --- a/src/CodeCoverage.php +++ b/src/CodeCoverage.php @@ -277,11 +277,13 @@ public function append(RawCodeCoverageData $rawData, $id = null, bool $append = return; } - $size = 'unknown'; - $status = -1; + $size = 'unknown'; + $status = -1; + $fromTestcase = false; if ($id instanceof TestCase) { - $_size = $id->getSize(); + $fromTestcase = true; + $_size = $id->getSize(); if ($_size === Test::SMALL) { $size = 'small'; @@ -294,11 +296,12 @@ public function append(RawCodeCoverageData $rawData, $id = null, bool $append = $status = $id->getStatus(); $id = get_class($id) . '::' . $id->getName(); } elseif ($id instanceof PhptTestCase) { - $size = 'large'; - $id = $id->getName(); + $fromTestcase = true; + $size = 'large'; + $id = $id->getName(); } - $this->tests[$id] = ['size' => $size, 'status' => $status]; + $this->tests[$id] = ['size' => $size, 'status' => $status, 'fromTestcase' => $fromTestcase]; $this->data->markCodeAsExecutedByTestCase($id, $rawData); } diff --git a/src/Report/Html/Renderer/File.php b/src/Report/Html/Renderer/File.php index e393a087c..09c1ae7bd 100644 --- a/src/Report/Html/Renderer/File.php +++ b/src/Report/Html/Renderer/File.php @@ -990,43 +990,44 @@ private function abbreviateMethodName(string $methodName): string private function createPopoverContentForTest(string $test, array $testData): string { - switch ($testData['status']) { - case BaseTestRunner::STATUS_PASSED: - switch ($testData['size']) { - case 'small': - $testCSS = ' class="covered-by-small-tests"'; + $testCSS = ''; - break; + if ($testData['fromTestcase']) { + switch ($testData['status']) { + case BaseTestRunner::STATUS_PASSED: + switch ($testData['size']) { + case 'small': + $testCSS = ' class="covered-by-small-tests"'; - case 'medium': - $testCSS = ' class="covered-by-medium-tests"'; + break; - break; + case 'medium': + $testCSS = ' class="covered-by-medium-tests"'; - default: - $testCSS = ' class="covered-by-large-tests"'; + break; - break; - } + default: + $testCSS = ' class="covered-by-large-tests"'; - break; + break; + } - case BaseTestRunner::STATUS_SKIPPED: - case BaseTestRunner::STATUS_INCOMPLETE: - case BaseTestRunner::STATUS_RISKY: - case BaseTestRunner::STATUS_WARNING: - $testCSS = ' class="warning"'; + break; - break; + case BaseTestRunner::STATUS_SKIPPED: + case BaseTestRunner::STATUS_INCOMPLETE: + case BaseTestRunner::STATUS_RISKY: + case BaseTestRunner::STATUS_WARNING: + $testCSS = ' class="warning"'; - case BaseTestRunner::STATUS_FAILURE: - case BaseTestRunner::STATUS_ERROR: - $testCSS = ' class="danger"'; + break; - break; + case BaseTestRunner::STATUS_FAILURE: + case BaseTestRunner::STATUS_ERROR: + $testCSS = ' class="danger"'; - default: - $testCSS = ''; + break; + } } return sprintf( diff --git a/tests/tests/CodeCoverageTest.php b/tests/tests/CodeCoverageTest.php index 9e8996e5f..14df3f824 100644 --- a/tests/tests/CodeCoverageTest.php +++ b/tests/tests/CodeCoverageTest.php @@ -64,10 +64,10 @@ public function testCollect(): void $this->assertEquals( [ - 'BankAccountTest::testBalanceIsInitiallyZero' => ['size' => 'unknown', 'status' => -1], - 'BankAccountTest::testBalanceCannotBecomeNegative' => ['size' => 'unknown', 'status' => -1], - 'BankAccountTest::testBalanceCannotBecomeNegative2' => ['size' => 'unknown', 'status' => -1], - 'BankAccountTest::testDepositWithdrawMoney' => ['size' => 'unknown', 'status' => -1], + 'BankAccountTest::testBalanceIsInitiallyZero' => ['size' => 'unknown', 'status' => -1, 'fromTestcase' => true], + 'BankAccountTest::testBalanceCannotBecomeNegative' => ['size' => 'unknown', 'status' => -1, 'fromTestcase' => true], + 'BankAccountTest::testBalanceCannotBecomeNegative2' => ['size' => 'unknown', 'status' => -1, 'fromTestcase' => true], + 'BankAccountTest::testDepositWithdrawMoney' => ['size' => 'unknown', 'status' => -1, 'fromTestcase' => true], ], $coverage->getTests() );