From 87b7682d0b83a51068f2c003598b9f1273a844ed Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 7 Aug 2026 14:47:08 +0200 Subject: [PATCH] Register PropertyExistsWithoutAssertRector in the composer-based set The rule was only registered in the removed phpunit100 set, so it would have been dropped from every set. It already declares a ">=10.0" package constraint, so the composer-based set is its natural home. Its assertObjectHasAttribute() and assertObjectNotHasAttribute() handling is removed, as both have a direct replacement in assertObjectHasProperty() and assertObjectNotHasProperty(). Those renames are already covered by the ">=10.1" RenameMethodRector configuration in the same set, which would otherwise conflict with this rule. --- config/sets/composer-based.php | 2 ++ .../assert_object_has_attribute.php.inc | 31 ------------------- .../skip_assert_object_has_attribute.php.inc | 17 ++++++++++ .../PropertyExistsWithoutAssertRector.php | 6 ++-- 4 files changed, 23 insertions(+), 33 deletions(-) delete mode 100644 rules-tests/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector/Fixture/assert_object_has_attribute.php.inc create mode 100644 rules-tests/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector/Fixture/skip_assert_object_has_attribute.php.inc diff --git a/config/sets/composer-based.php b/config/sets/composer-based.php index 7e210c47..2e90d7ca 100644 --- a/config/sets/composer-based.php +++ b/config/sets/composer-based.php @@ -23,6 +23,7 @@ use Rector\PHPUnit\PHPUnit100\Rector\Class_\ParentTestClassConstructorRector; use Rector\PHPUnit\PHPUnit100\Rector\Class_\PublicDataProviderClassMethodRector; use Rector\PHPUnit\PHPUnit100\Rector\Class_\StaticDataProviderClassMethodRector; +use Rector\PHPUnit\PHPUnit100\Rector\MethodCall\PropertyExistsWithoutAssertRector; use Rector\PHPUnit\PHPUnit100\Rector\MethodCall\RemoveSetMethodsMethodCallRector; use Rector\PHPUnit\PHPUnit100\Rector\StmtsAwareInterface\WithConsecutiveRector; use Rector\PHPUnit\PHPUnit110\Rector\CallLike\AssertContainsOnlyMethodCallRector; @@ -148,6 +149,7 @@ AddProphecyTraitRector::class, WithConsecutiveRector::class, RemoveSetMethodsMethodCallRector::class, + PropertyExistsWithoutAssertRector::class, ParentTestClassConstructorRector::class, // PHPUnit 11.0 diff --git a/rules-tests/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector/Fixture/assert_object_has_attribute.php.inc b/rules-tests/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector/Fixture/assert_object_has_attribute.php.inc deleted file mode 100644 index 865ad4ae..00000000 --- a/rules-tests/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector/Fixture/assert_object_has_attribute.php.inc +++ /dev/null @@ -1,31 +0,0 @@ -assertObjectHasAttribute('property', $someObject); - } -} - -?> ------ -assertTrue(property_exists($someObject, 'property')); - } -} - -?> diff --git a/rules-tests/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector/Fixture/skip_assert_object_has_attribute.php.inc b/rules-tests/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector/Fixture/skip_assert_object_has_attribute.php.inc new file mode 100644 index 00000000..446dd0e9 --- /dev/null +++ b/rules-tests/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector/Fixture/skip_assert_object_has_attribute.php.inc @@ -0,0 +1,17 @@ +assertObjectHasAttribute('property', $someObject); + $this->assertObjectNotHasAttribute('property', $someObject); + } +} + +?> diff --git a/rules/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector.php b/rules/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector.php index 2cfcce44..faffda21 100644 --- a/rules/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector.php +++ b/rules/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector.php @@ -34,16 +34,18 @@ public function provideComposerPackageConstraint(): ComposerPackageConstraint } /** + * The assertObjectHasAttribute() and assertObjectNotHasAttribute() methods are left out on purpose, + * as they have a direct replacement in assertObjectHasProperty() and assertObjectNotHasProperty(). + * Those renames are handled by RenameMethodRector in the composer-based set. + * * @var array */ private const array RENAME_METHODS_WITH_OBJECT_MAP = [ 'assertClassHasAttribute' => 'assertTrue', - 'assertObjectHasAttribute' => 'assertTrue', 'assertClassHasStaticAttribute' => 'assertTrue', // false 'assertClassNotHasStaticAttribute' => 'assertFalse', 'assertClassNotHasAttribute' => 'assertFalse', - 'assertObjectNotHasAttribute' => 'assertFalse', // no assert 'objectHasAttribute' => 'assertTrue', 'classHasAttribute' => 'assertTrue',