From 5f70de5502297b86f1e7295eb6797ab71fb29d6e Mon Sep 17 00:00:00 2001 From: Dominik Peters Date: Mon, 8 Mar 2021 11:21:27 +0100 Subject: [PATCH] [Phpunit] Prevent MethodCall instances of being processed (#5798) Co-authored-by: Dominik Peters --- .../MethodCall/AssertFalseStrposToContainsRector.php | 2 +- .../Rector/MethodCall/AssertPropertyExistsRector.php | 2 +- .../AssertTrueFalseToSpecificMethodRector.php | 2 +- .../Fixture/skip_method_call.php.inc | 12 ++++++++++++ .../Fixture/skip_method_call.php.inc | 12 ++++++++++++ .../Fixture/skip_method_call.php.inc | 12 ++++++++++++ 6 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 rules/phpunit/tests/Rector/MethodCall/AssertFalseStrposToContainsRector/Fixture/skip_method_call.php.inc create mode 100644 rules/phpunit/tests/Rector/MethodCall/AssertPropertyExistsRector/Fixture/skip_method_call.php.inc create mode 100644 rules/phpunit/tests/Rector/MethodCall/AssertTrueFalseToSpecificMethodRector/Fixture/skip_method_call.php.inc diff --git a/rules/phpunit/src/Rector/MethodCall/AssertFalseStrposToContainsRector.php b/rules/phpunit/src/Rector/MethodCall/AssertFalseStrposToContainsRector.php index 8f6e9902a04c..34b580f3e677 100644 --- a/rules/phpunit/src/Rector/MethodCall/AssertFalseStrposToContainsRector.php +++ b/rules/phpunit/src/Rector/MethodCall/AssertFalseStrposToContainsRector.php @@ -79,7 +79,7 @@ public function refactor(Node $node): ?Node } $firstArgumentValue = $node->args[0]->value; - if ($firstArgumentValue instanceof StaticCall) { + if ($firstArgumentValue instanceof StaticCall || $firstArgumentValue instanceof MethodCall) { return null; } if (! $this->isNames($firstArgumentValue, ['strpos', 'stripos'])) { diff --git a/rules/phpunit/src/Rector/MethodCall/AssertPropertyExistsRector.php b/rules/phpunit/src/Rector/MethodCall/AssertPropertyExistsRector.php index f0261e2d5e75..7a3b1f1b8e79 100644 --- a/rules/phpunit/src/Rector/MethodCall/AssertPropertyExistsRector.php +++ b/rules/phpunit/src/Rector/MethodCall/AssertPropertyExistsRector.php @@ -89,7 +89,7 @@ public function refactor(Node $node): ?Node } $firstArgumentValue = $node->args[0]->value; - if ($firstArgumentValue instanceof StaticCall) { + if ($firstArgumentValue instanceof StaticCall || $firstArgumentValue instanceof MethodCall) { return null; } if (! $this->isName($firstArgumentValue, 'property_exists')) { diff --git a/rules/phpunit/src/Rector/MethodCall/AssertTrueFalseToSpecificMethodRector.php b/rules/phpunit/src/Rector/MethodCall/AssertTrueFalseToSpecificMethodRector.php index c5e85a4ba829..cc1c4d21c7a8 100644 --- a/rules/phpunit/src/Rector/MethodCall/AssertTrueFalseToSpecificMethodRector.php +++ b/rules/phpunit/src/Rector/MethodCall/AssertTrueFalseToSpecificMethodRector.php @@ -89,7 +89,7 @@ public function refactor(Node $node): ?Node } $firstArgumentValue = $node->args[0]->value; - if ($firstArgumentValue instanceof StaticCall) { + if ($firstArgumentValue instanceof StaticCall || $firstArgumentValue instanceof MethodCall) { return null; } diff --git a/rules/phpunit/tests/Rector/MethodCall/AssertFalseStrposToContainsRector/Fixture/skip_method_call.php.inc b/rules/phpunit/tests/Rector/MethodCall/AssertFalseStrposToContainsRector/Fixture/skip_method_call.php.inc new file mode 100644 index 000000000000..c79ed194d1fd --- /dev/null +++ b/rules/phpunit/tests/Rector/MethodCall/AssertFalseStrposToContainsRector/Fixture/skip_method_call.php.inc @@ -0,0 +1,12 @@ +someMethod()); + } +} diff --git a/rules/phpunit/tests/Rector/MethodCall/AssertPropertyExistsRector/Fixture/skip_method_call.php.inc b/rules/phpunit/tests/Rector/MethodCall/AssertPropertyExistsRector/Fixture/skip_method_call.php.inc new file mode 100644 index 000000000000..49481eacdedf --- /dev/null +++ b/rules/phpunit/tests/Rector/MethodCall/AssertPropertyExistsRector/Fixture/skip_method_call.php.inc @@ -0,0 +1,12 @@ +someMethod()); + } +} diff --git a/rules/phpunit/tests/Rector/MethodCall/AssertTrueFalseToSpecificMethodRector/Fixture/skip_method_call.php.inc b/rules/phpunit/tests/Rector/MethodCall/AssertTrueFalseToSpecificMethodRector/Fixture/skip_method_call.php.inc new file mode 100644 index 000000000000..37085e298f06 --- /dev/null +++ b/rules/phpunit/tests/Rector/MethodCall/AssertTrueFalseToSpecificMethodRector/Fixture/skip_method_call.php.inc @@ -0,0 +1,12 @@ +someMethod()); + } +}