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-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 37536b7c..60a86585 100644 --- a/rules/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector.php +++ b/rules/PHPUnit100/Rector/MethodCall/PropertyExistsWithoutAssertRector.php @@ -27,9 +27,17 @@ final class PropertyExistsWithoutAssertRector extends AbstractRector * @var array */ 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( @@ -41,19 +49,17 @@ public function __construct( public function getRuleDefinition(): RuleDefinition { return new RuleDefinition( - 'Replace deleted PHPUnit methods: assertClassHasStaticAttribute, classHasStaticAttribute and assertClassNotHasStaticAttribute by 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 ), ]