Skip to content

[cleanup] remove per-version PHPUnit set configs and constants - #760

Merged
TomasVotruba merged 1 commit into
mainfrom
cleanup-version-sets
Aug 7, 2026
Merged

[cleanup] remove per-version PHPUnit set configs and constants#760
TomasVotruba merged 1 commit into
mainfrom
cleanup-version-sets

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Aug 7, 2026

Copy link
Copy Markdown
Member

Follow-up to #758 / #759.

After every per-version rule was moved into the composer-based set, the phpunit40.phpphpunit130.php configs held nothing of their own — each rule and rename they registered is already in config/sets/composer-based.php, guarded by a phpunit/phpunit version constraint. So they are removed, along with their PHPUnitSetList constants.

Verified coverage

Each removed set was checked rule by rule against composer-based.php:

removed set already in composer-based as
phpunit40 staticExpects() rename, >=4.0
phpunit50 GetMockRector
phpunit60 DelegateExceptionArgumentsRector, ExceptionAnnotationRector, AddDoesNotPerformAssertionToNonAssertingTestRector, GetMockBuilderGetMockToCreateMockRector + the >=6.0 rename/class maps
phpunit70 RemoveDataProviderTestPrefixRector, scenariotest, >=7.0
phpunit80 the SpecificAssert* rules + param/return type declarations, >=8.0 (its PHPUnit_Framework_MockObject_MockObject rename is part of the >=6.0 class map)
phpunit90 TestListenerToHooksRector, ExplicitPhpErrorApiRector, SpecificAssertContainsWithoutIdentityRector, AssertRegExpRector + the >=9.1 assert renames
phpunit100 the data provider / prophecy / withConsecutive rules + >=10.0 renames and annotation-to-attribute config. PropertyExistsWithoutAssertRector was the one rule not yet there, so it is added in this PR (see below)
phpunit110 NamedArgumentForDataProviderRector
phpunit120 RemoveOverrideFinalConstructTestCaseRector and the mock-to-stub rules
phpunit125 the 3 AllowMockObjects* rules
phpunit130 expectExceptionMessageIsOrContains() rename, >=13.2

For users

 return RectorConfig::configure()
     ->withSets([
-        PHPUnitSetList::PHPUNIT_90,
+        PHPUnitSetList::COMPOSER_BASED,
     ]);

COMPOSER_BASED picks the applicable rules from the installed phpunit/phpunit version, so there is no longer a version constant to pick by hand.

Test fixture change

tests/Issues/PHPUnit10DataProvider moved from PHPUNIT_100 to COMPOSER_BASED. That set is broader, so AddDoesNotPerformAssertionToNonAssertingTestRector now also applies to the fixture and the expected output gains one attribute:

 #[\PHPUnit\Framework\Attributes\DataProvider('fooProvider')]
 #[\PHPUnit\Framework\Attributes\Test]
+#[\PHPUnit\Framework\Attributes\DoesNotPerformAssertions]
 public function it_should_do_stuff(string $foo): void

PropertyExistsWithoutAssertRector

This rule lived only in phpunit100.php, so removing that set would have dropped it from every set. It already declares a >=10.0 constraint, so it is now registered in composer-based.php.

Registering it surfaced a pre-existing overlap: the rule and the set's >=10.1 RenameMethodRector both claimed assertObjectHasAttribute(). Both were registered together in the old phpunit100.php too, so the conflict is not new — it was simply never exercised by a fixture.

Resolved in favour of the rename, since these two methods have a direct replacement:

-$this->assertObjectHasAttribute('someProperty', new stdClass());
+$this->assertObjectHasProperty('someProperty', new stdClass());

assertObjectHasAttribute and assertObjectNotHasAttribute are therefore removed from the rule's map, and its fixture becomes a skip case. The rule keeps the 7 methods that have no direct replacement:

-$this->assertClassHasAttribute('property', 'stdClass');
+$this->assertTrue(property_exists('stdClass', 'property'));

Every rule and configuration these sets carried is already registered in
the composer-based set, guarded by a "phpunit/phpunit" version constraint.
Keeping the per-version sets around only duplicated that content.
@TomasVotruba
TomasVotruba merged commit 4050e43 into main Aug 7, 2026
7 checks passed
@TomasVotruba
TomasVotruba deleted the cleanup-version-sets branch August 7, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant