[PHPUnit 11.5] Add AssertContainsOnlyMethodCallRector, bond deprecated generic asserts to phpunit >=11.5 - #738
Merged
Conversation
…ecated-generic-assert rules to phpunit >=11.5
…r direct upgrades
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.
PHPUnit 11.5 deprecated the generic
assertContainsOnly()andisType()assertions and added type-specific replacements for both (#6055, #6052).Neither was handled for projects actually running PHPUnit 11.5:
assertContainsOnly()at allAssertIsTypeMethodCallRectorexisted, but only in thephpunit120.phpset.ComposerTriggeredSetmatches with^+ version, so onphpunit/phpunit 11.5.xonlyphpunit110.phpis loaded and the rule never ran — despite the deprecation landing in 11.5.New rule:
AssertContainsOnlyMethodCallRectorfinal class SomeTest extends TestCase { public function test(): void { - $this->assertContainsOnly('string', ['a', 'b']); + $this->assertContainsOnlyString(['a', 'b']); - self::assertContainsOnly('int', [1], null, 'some message'); + self::assertContainsOnlyInt([1], 'some message'); } }The
$isNativeTypeargument is dropped when it is absent,nullortrue. When it isfalseor an unresolvable expression the type may be a class name, so the call is skipped.Version bonding
Both rules now implement
ComposerPackageConstraintInterface(rectorphp/rector-src#7877):ComposerTriggeredSetmatches with^+ version and is not cumulative, so a project on PHPUnit 12 never loadsphpunit110.php. Both rules are therefore registered in thephpunit110.php,phpunit120.phpandphpunit130.phpsets — someone upgrading straight from 11.4 to 12.0 still gets them.AssertIsTypeMethodCallRectorkeeps its current class name, so nothing breaks for existing PHPUnit 12 users.The
>=11.5constraint is what keeps both rules from firing on 11.0–11.4, where the type-specific methods do not exist yet.Needed rectorphp/rector-src#8237 (merged) — the autowired
InstalledPackageResolverbehindComposerPackageConstraintFilterlost its cwd fallback, so every rule implementingComposerPackageConstraintInterfacethrewThe installed package json not found.