From b25c2499faeb842766e295ab881e04360d526388 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Sat, 7 Dec 2024 14:32:00 +0100 Subject: [PATCH] Remove deprecated methods --- ChangeLog-12.0.md | 1 + src/CodeCoverage.php | 21 +- tests/TestCase.php | 251 ------------------ ...NamespacedBankAccount-text-with-colors.txt | 14 - tests/_files/NamespacedBankAccount-text.txt | 14 - tests/_files/NamespacedBankAccount.php | 38 --- tests/tests/Report/TextTest.php | 40 --- 7 files changed, 2 insertions(+), 377 deletions(-) delete mode 100644 tests/_files/NamespacedBankAccount-text-with-colors.txt delete mode 100644 tests/_files/NamespacedBankAccount-text.txt delete mode 100644 tests/_files/NamespacedBankAccount.php diff --git a/ChangeLog-12.0.md b/ChangeLog-12.0.md index fe5b6f069..77665fd0f 100644 --- a/ChangeLog-12.0.md +++ b/ChangeLog-12.0.md @@ -6,6 +6,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt ### Removed +* Methods `CodeCoverage::includeUncoveredFiles()` and `CodeCoverage::excludeUncoveredFiles()` * Optional argument `$linesToBeUsed` of `CodeCoverage::stop()` and `CodeCoverage::append()` methods * This component is no longer supported on PHP 8.2 diff --git a/src/CodeCoverage.php b/src/CodeCoverage.php index 959c238f6..df6fedc62 100644 --- a/src/CodeCoverage.php +++ b/src/CodeCoverage.php @@ -48,7 +48,6 @@ final class CodeCoverage private readonly Filter $filter; private readonly Wizard $wizard; private bool $checkForUnintentionallyCoveredCode = false; - private bool $includeUncoveredFiles = true; private bool $ignoreDeprecatedCode = false; private ?string $currentId = null; private ?TestSize $currentSize = null; @@ -122,9 +121,7 @@ public function filter(): Filter public function getData(bool $raw = false): ProcessedCodeCoverageData { if (!$raw) { - if ($this->includeUncoveredFiles) { - $this->addUncoveredFilesFromFilter(); - } + $this->addUncoveredFilesFromFilter(); } return $this->data; @@ -271,22 +268,6 @@ public function disableCheckForUnintentionallyCoveredCode(): void $this->checkForUnintentionallyCoveredCode = false; } - /** - * @deprecated - */ - public function includeUncoveredFiles(): void - { - $this->includeUncoveredFiles = true; - } - - /** - * @deprecated - */ - public function excludeUncoveredFiles(): void - { - $this->includeUncoveredFiles = false; - } - public function enableAnnotationsForIgnoringCode(): void { $this->useAnnotationsForIgnoringCode = true; diff --git a/tests/TestCase.php b/tests/TestCase.php index d520a1fd4..09ac99a81 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -1165,123 +1165,6 @@ protected function getPathCoverageForSourceWithoutNamespace(): CodeCoverage return $coverage; } - protected function getXdebugDataForNamespacedBankAccount() - { - return [ - RawCodeCoverageData::fromXdebugWithoutPathCoverage([ - TEST_FILES_PATH . 'NamespacedBankAccount.php' => [ - 13 => 1, - 14 => -2, - 18 => -1, - 19 => -1, - 20 => -1, - 21 => -1, - 23 => -1, - 27 => -1, - 29 => -1, - 30 => -2, - 34 => -1, - 36 => -1, - 37 => -2, - ], - ]), - RawCodeCoverageData::fromXdebugWithoutPathCoverage([ - TEST_FILES_PATH . 'NamespacedBankAccount.php' => [ - 13 => 1, - 18 => 1, - 21 => 1, - 34 => 1, - ], - ]), - RawCodeCoverageData::fromXdebugWithoutPathCoverage([ - TEST_FILES_PATH . 'NamespacedBankAccount.php' => [ - 13 => 1, - 18 => 1, - 21 => 1, - 27 => 1, - ], - ]), - RawCodeCoverageData::fromXdebugWithoutPathCoverage([ - TEST_FILES_PATH . 'NamespacedBankAccount.php' => [ - 13 => 1, - 18 => 1, - 19 => 1, - 20 => 1, - 23 => 1, - 27 => 1, - 29 => 1, - 34 => 1, - 36 => 1, - ], - ]), - ]; - } - - protected function getLineCoverageForNamespacedBankAccount(): CodeCoverage - { - $data = $this->getXdebugDataForNamespacedBankAccount(); - - $stub = $this->createStub(Driver::class); - - $stub->method('stop') - ->willReturn(...$data); - - $filter = new Filter; - $filter->includeFile(TEST_FILES_PATH . 'NamespacedBankAccount.php'); - - $coverage = new CodeCoverage($stub, $filter); - - $coverage->start( - 'BankAccountTest::testBalanceIsInitiallyZero', - null, - true - ); - - $coverage->stop( - true, - null, - [TEST_FILES_PATH . 'NamespacedBankAccount.php' => range(11, 14)] - ); - - $coverage->start( - 'BankAccountTest::testBalanceCannotBecomeNegative' - ); - - $coverage->stop( - true, - null, - [TEST_FILES_PATH . 'NamespacedBankAccount.php' => range(32, 37)] - ); - - $coverage->start( - 'BankAccountTest::testBalanceCannotBecomeNegative2' - ); - - $coverage->stop( - true, - null, - [TEST_FILES_PATH . 'NamespacedBankAccount.php' => range(25, 30)] - ); - - $coverage->start( - 'BankAccountTest::testDepositWithdrawMoney' - ); - - $coverage->stop( - true, - null, - [ - TEST_FILES_PATH . 'NamespacedBankAccount.php' => array_merge( - range(11, 14), - range(25, 30), - range(32, 37) - ), - ] - ); - - return $coverage; - } - protected function getLineCoverageForBankAccountForFirstTwoTests(): CodeCoverage { $data = $this->getLineCoverageXdebugDataForBankAccount(); @@ -1867,138 +1750,4 @@ protected function removeTemporaryFiles(): void $fileInfo->isDir() ? rmdir($pathname) : unlink($pathname); } } - - protected function getCoverageForFilesWithUncoveredIncluded(): CodeCoverage - { - $data = $this->getLineCoverageXdebugDataForBankAccount(); - - $stub = $this->createStub(Driver::class); - - $stub->method('stop') - ->willReturn(...$data); - - $filter = new Filter; - $filter->includeFile(TEST_FILES_PATH . 'BankAccount.php'); - $filter->includeFile(TEST_FILES_PATH . 'NamespacedBankAccount.php'); - - $coverage = new CodeCoverage($stub, $filter); - $coverage->includeUncoveredFiles(); - - $coverage->start( - 'BankAccountTest::testBalanceIsInitiallyZero', - null, - true - ); - - $coverage->stop( - true, - null, - [TEST_FILES_PATH . 'BankAccount.php' => range(6, 9)] - ); - - $coverage->start( - 'BankAccountTest::testBalanceCannotBecomeNegative' - ); - - $coverage->stop( - true, - null, - [TEST_FILES_PATH . 'BankAccount.php' => range(27, 32)] - ); - - $coverage->start( - 'BankAccountTest::testBalanceCannotBecomeNegative2' - ); - - $coverage->stop( - true, - null, - [TEST_FILES_PATH . 'BankAccount.php' => range(20, 25)] - ); - - $coverage->start( - 'BankAccountTest::testDepositWithdrawMoney' - ); - - $coverage->stop( - true, - null, - [ - TEST_FILES_PATH . 'BankAccount.php' => array_merge( - range(6, 9), - range(20, 25), - range(27, 32) - ), - ] - ); - - return $coverage; - } - - protected function getCoverageForFilesWithUncoveredExcluded(): CodeCoverage - { - $data = $this->getLineCoverageXdebugDataForBankAccount(); - - $stub = $this->createStub(Driver::class); - - $stub->method('stop') - ->willReturn(...$data); - - $filter = new Filter; - $filter->includeFile(TEST_FILES_PATH . 'BankAccount.php'); - $filter->includeFile(TEST_FILES_PATH . 'NamespacedBankAccount.php'); - - $coverage = new CodeCoverage($stub, $filter); - $coverage->excludeUncoveredFiles(); - - $coverage->start( - 'BankAccountTest::testBalanceIsInitiallyZero', - null, - true - ); - - $coverage->stop( - true, - null, - [TEST_FILES_PATH . 'BankAccount.php' => range(6, 9)] - ); - - $coverage->start( - 'BankAccountTest::testBalanceCannotBecomeNegative' - ); - - $coverage->stop( - true, - null, - [TEST_FILES_PATH . 'BankAccount.php' => range(27, 32)] - ); - - $coverage->start( - 'BankAccountTest::testBalanceCannotBecomeNegative2' - ); - - $coverage->stop( - true, - null, - [TEST_FILES_PATH . 'BankAccount.php' => range(20, 25)] - ); - - $coverage->start( - 'BankAccountTest::testDepositWithdrawMoney' - ); - - $coverage->stop( - true, - null, - [ - TEST_FILES_PATH . 'BankAccount.php' => array_merge( - range(6, 9), - range(20, 25), - range(27, 32) - ), - ] - ); - - return $coverage; - } } diff --git a/tests/_files/NamespacedBankAccount-text-with-colors.txt b/tests/_files/NamespacedBankAccount-text-with-colors.txt deleted file mode 100644 index 83f3901e1..000000000 --- a/tests/_files/NamespacedBankAccount-text-with-colors.txt +++ /dev/null @@ -1,14 +0,0 @@ - - -Code Coverage Report:  - %s  -  - Summary:  - Classes: 0.00% (0/1) - Methods: 75.00% (3/4) - Lines: 62.50% (5/8) - -SomeNamespace\BankAccount - Methods: ( 0/ 0) Lines: ( 0/ 0) -SomeNamespace\BankAccountTrait - Methods: 75.00% ( 3/ 4) Lines: 62.50% ( 5/ 8) diff --git a/tests/_files/NamespacedBankAccount-text.txt b/tests/_files/NamespacedBankAccount-text.txt deleted file mode 100644 index f535d120b..000000000 --- a/tests/_files/NamespacedBankAccount-text.txt +++ /dev/null @@ -1,14 +0,0 @@ - - -Code Coverage Report: - %s - - Summary: - Classes: 0.00% (0/1) - Methods: 75.00% (3/4) - Lines: 62.50% (5/8) - -SomeNamespace\BankAccount - Methods: ( 0/ 0) Lines: ( 0/ 0) -SomeNamespace\BankAccountTrait - Methods: 75.00% ( 3/ 4) Lines: 62.50% ( 5/ 8) diff --git a/tests/_files/NamespacedBankAccount.php b/tests/_files/NamespacedBankAccount.php deleted file mode 100644 index 93f90ac80..000000000 --- a/tests/_files/NamespacedBankAccount.php +++ /dev/null @@ -1,38 +0,0 @@ -balance; - } - - protected function setBalance($balance) - { - if ($balance >= 0) { - $this->balance = $balance; - } else { - throw new \RuntimeException; - } - } - - public function depositMoney($balance) - { - $this->setBalance($this->getBalance() + $balance); - - return $this->getBalance(); - } - - public function withdrawMoney($balance) - { - $this->setBalance($this->getBalance() - $balance); - - return $this->getBalance(); - } -} diff --git a/tests/tests/Report/TextTest.php b/tests/tests/Report/TextTest.php index 8cefd57c9..b790e3762 100644 --- a/tests/tests/Report/TextTest.php +++ b/tests/tests/Report/TextTest.php @@ -47,26 +47,6 @@ public function testTextOnlySummaryForBankAccountTest(): void ); } - public function testTextForNamespacedBankAccountTest(): void - { - $text = new Text(Thresholds::default(), true, false); - - $this->assertStringMatchesFormatFile( - TEST_FILES_PATH . 'NamespacedBankAccount-text.txt', - str_replace(PHP_EOL, "\n", $text->process($this->getLineCoverageForNamespacedBankAccount())), - ); - } - - public function testTextForNamespacedBankAccountTestWhenColorsAreEnabled(): void - { - $text = new Text(Thresholds::default(), true, false); - - $this->assertStringMatchesFormatFile( - TEST_FILES_PATH . 'NamespacedBankAccount-text-with-colors.txt', - str_replace(PHP_EOL, "\n", $text->process($this->getLineCoverageForNamespacedBankAccount(), true)), - ); - } - public function testTextForFileWithIgnoredLines(): void { $text = new Text(Thresholds::default(), false, false); @@ -86,24 +66,4 @@ public function testTextForClassWithAnonymousFunction(): void str_replace(PHP_EOL, "\n", $text->process($this->getCoverageForClassWithAnonymousFunction())), ); } - - public function testUncoveredFilesAreIncludedWhenConfiguredTest(): void - { - $text = new Text(Thresholds::default(), false, false); - - $this->assertStringMatchesFormatFile( - TEST_FILES_PATH . 'BankAccountWithUncovered-text-line.txt', - str_replace(PHP_EOL, "\n", $text->process($this->getCoverageForFilesWithUncoveredIncluded())), - ); - } - - public function testUncoveredFilesAreExcludedWhenConfiguredTest(): void - { - $text = new Text(Thresholds::default(), false, false); - - $this->assertStringMatchesFormatFile( - TEST_FILES_PATH . 'BankAccountWithoutUncovered-text-line.txt', - str_replace(PHP_EOL, "\n", $text->process($this->getCoverageForFilesWithUncoveredExcluded())), - ); - } }