From 999b8a7ff102caea41c84ab019aaf0b01d3f6349 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 15 Nov 2025 22:17:25 +0100 Subject: [PATCH 1/3] add assertClassHasAttribute() to PropertyExistsWithoutAssertRector --- .../Fixture/assert_has_attribute.php.inc | 31 +++++++++++++++++++ .../PropertyExistsWithoutAssertRector.php | 4 ++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 rules-tests/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector/Fixture/assert_has_attribute.php.inc diff --git a/rules-tests/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector/Fixture/assert_has_attribute.php.inc b/rules-tests/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector/Fixture/assert_has_attribute.php.inc new file mode 100644 index 00000000..f1f02c13 --- /dev/null +++ b/rules-tests/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector/Fixture/assert_has_attribute.php.inc @@ -0,0 +1,31 @@ +assertClassHasAttribute('property', 'stdClass'); + } +} + +?> +----- +assertTrue(property_exists('stdClass', 'property')); + } +} + +?> diff --git a/rules/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector.php b/rules/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector.php index 37536b7c..5ece4256 100644 --- a/rules/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector.php +++ b/rules/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector.php @@ -27,9 +27,11 @@ final class PropertyExistsWithoutAssertRector extends AbstractRector * @var array */ private const RENAME_METHODS_WITH_OBJECT_MAP = [ + 'assertClassHasAttribute' => 'assertTrue', 'assertClassHasStaticAttribute' => 'assertTrue', 'classHasStaticAttribute' => 'assertTrue', 'assertClassNotHasStaticAttribute' => 'assertFalse', + 'assertClassNotHasAttribute' => 'assertFalse', ]; public function __construct( @@ -41,7 +43,7 @@ public function __construct( public function getRuleDefinition(): RuleDefinition { return new RuleDefinition( - 'Replace deleted PHPUnit methods: assertClassHasStaticAttribute, classHasStaticAttribute and assertClassNotHasStaticAttribute by property_exists()', + 'Replace removed assertClassHasStaticAttribute, classHasStaticAttribute and assertClassNotHasStaticAttribute with property_exists()', [ new CodeSample( <<<'CODE_SAMPLE' From 97e14f074f064ea2de5d9125c91484d0018aa5b6 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 15 Nov 2025 22:18:12 +0100 Subject: [PATCH 2/3] cs --- .../Rector/MethodCall/PropertyExistsWithoutAssertRector.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/rules/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector.php b/rules/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector.php index 5ece4256..b070c0d7 100644 --- a/rules/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector.php +++ b/rules/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector.php @@ -43,19 +43,17 @@ public function __construct( public function getRuleDefinition(): RuleDefinition { return new RuleDefinition( - 'Replace removed assertClassHasStaticAttribute, classHasStaticAttribute and assertClassNotHasStaticAttribute with property_exists()', + 'Replace removed assertClassHas*Attribute() with property_exists()', [ new CodeSample( <<<'CODE_SAMPLE' +$this->assertClassHasAttribute("Class", "property"); $this->assertClassHasStaticAttribute("Class", "property"); -$this->classHasStaticAttribute("Class", "property"); -$this->assertClassNotHasStaticAttribute("Class", "property"); CODE_SAMPLE , <<<'CODE_SAMPLE' $this->assertTrue(property_exists("Class", "property")); $this->assertTrue(property_exists("Class", "property")); -$this->assertFalse(property_exists("Class", "property")); CODE_SAMPLE ), ] From 7fd80567ffaf8e4fa2ab4817744c2409c5d3587d Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sat, 15 Nov 2025 22:20:16 +0100 Subject: [PATCH 3/3] add assertObjectHasAttribute() support to PropertyExistsWithoutAssertRector --- .../assert_object_has_attribute.php.inc | 31 +++++++++++++++++++ .../PropertyExistsWithoutAssertRector.php | 8 ++++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 rules-tests/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector/Fixture/assert_object_has_attribute.php.inc 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 new file mode 100644 index 00000000..865ad4ae --- /dev/null +++ b/rules-tests/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector/Fixture/assert_object_has_attribute.php.inc @@ -0,0 +1,31 @@ +assertObjectHasAttribute('property', $someObject); + } +} + +?> +----- +assertTrue(property_exists($someObject, 'property')); + } +} + +?> diff --git a/rules/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector.php b/rules/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector.php index b070c0d7..60a86585 100644 --- a/rules/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector.php +++ b/rules/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector.php @@ -28,10 +28,16 @@ final class PropertyExistsWithoutAssertRector extends AbstractRector */ private const RENAME_METHODS_WITH_OBJECT_MAP = [ 'assertClassHasAttribute' => 'assertTrue', + 'assertObjectHasAttribute' => 'assertTrue', 'assertClassHasStaticAttribute' => 'assertTrue', - 'classHasStaticAttribute' => 'assertTrue', + // false 'assertClassNotHasStaticAttribute' => 'assertFalse', 'assertClassNotHasAttribute' => 'assertFalse', + 'assertObjectNotHasAttribute' => 'assertFalse', + // no assert + 'objectHasAttribute' => 'assertTrue', + 'classHasAttribute' => 'assertTrue', + 'classHasStaticAttribute' => 'assertTrue', ]; public function __construct(