Repository navigation
feat: restore coversNothing() - #1981
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What:
Description:
This PR restores
->coversNothing(). It adds PHPUnit's#[CoversNothing]attribute to the method of one test, the same way Pest 3 did:With
requireCoverageMetadata="true", PHPUnit flags each test without coverage metadata as risky. Today a Pest test can only satisfy that setting withcovers(), so tests that cover no code have no public way to say so. Typical examples arearch()tests and smoke tests. The only workaround reaches into@internalAPI ($call->testCaseMethod->attributes[] = new Attribute(CoversNothing::class, [])).Why it was removed. PHPUnit 12.3.0 deprecated
#[CoversNothing]on test methods (sebastianbergmann/phpunit#6246, ChangeLog-12.3). Pest 4 then dropped->coversNothing()in 711a60c (4.0.0-beta.1, first tagged inv4.0.0). The3.xline still has it (v3.8.7).Why it is safe now. PHPUnit 13.3.0 (2026-08-07) allows
#[CoversNothing]on methods again (sebastianbergmann/phpunit#6722, 3ae334f, listed under "Added" in ChangeLog-13.3). On 13.4.3, the method-level attribute:Metadata::coversNothingOnMethod()with no deprecation.requireCoverageMetadata(TestRunner::hasCoverageMetadata()).CodeCoverage::shouldCodeCoverageBeCollectedFor()).PHPUnit warns only when a class-level
#[CoversNothing]sits next to class-level#[Covers*]or#[Uses*](CodeCoverage::coversNothingContradictsCoversOrUses()reads class-level metadata only). Pest writescovers()as class attributes andcoversNothing()as a method attribute, so one file can use both without that warning.composer.jsonrequiresphpunit/phpunit: ^13.4.3and conflicts with>13.4.3. Thus each PHPUnit version that Pest 5.x installs accepts the method-level attribute.Tests.
tests/Features/Covers/CoversNothing.phpfollows the othertests/Features/Covers/*files:->coversNothing()putsCoversNothingon the test method, directly and throughdescribe()->coversNothing().tests/Fixtures/Suites/CoversNothing.xml(requireCoverageMetadata="true",failOnRisky="true",failOnWarning="true") passes thecoversNothing()test. It reports only the test without metadata as risky:1 risky, 1 passed.covers(CoversClass1::class)and one->coversNothing()test passes with no PHPUnit warning.All four tests fail on
5.xwithCall to undefined method PHPUnit\Framework\TestCase::coversNothing(). The last test also fails if the attribute goes on the class instead of the method, because PHPUnit then emits the#[Covers*] and #[Uses*] attributes do not have an effect when the #[CoversNothing] attribute is usedwarning.tests/.snapshots/success.txtand the summary intests/Visual/Parallel.phpare updated for the four new tests.Related:
#[CoversNothing]on a test method sebastianbergmann/phpunit#6246#[CoversNothing]on methods sebastianbergmann/phpunit#6722