From bd7ac99cf05a92f43fb14a7200d409cde28e1e8b Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Tue, 3 Feb 2026 23:56:46 +0100 Subject: [PATCH 1/2] add fixture --- .../Fixture/final_property_as_well.php.inc | 56 +++++++++++++++++++ .../Source/SomeFinalClass.php | 8 +++ ...ectsWithoutExpectationsAttributeRector.php | 7 +-- 3 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 rules-tests/PHPUnit120/Rector/Class_/AllowMockObjectsWithoutExpectationsAttributeRector/Fixture/final_property_as_well.php.inc create mode 100644 rules-tests/PHPUnit120/Rector/Class_/AllowMockObjectsWithoutExpectationsAttributeRector/Source/SomeFinalClass.php diff --git a/rules-tests/PHPUnit120/Rector/Class_/AllowMockObjectsWithoutExpectationsAttributeRector/Fixture/final_property_as_well.php.inc b/rules-tests/PHPUnit120/Rector/Class_/AllowMockObjectsWithoutExpectationsAttributeRector/Fixture/final_property_as_well.php.inc new file mode 100644 index 00000000..82c573a3 --- /dev/null +++ b/rules-tests/PHPUnit120/Rector/Class_/AllowMockObjectsWithoutExpectationsAttributeRector/Fixture/final_property_as_well.php.inc @@ -0,0 +1,56 @@ +someMock = $this->createMock(SomeFinalClass::class); + $this->someMock->method('some')->willReturn(true); + } + + public function testOne() + { + } + + public function testTwo() + { + } +} + +?> +----- +someMock = $this->createMock(SomeFinalClass::class); + $this->someMock->method('some')->willReturn(true); + } + + public function testOne() + { + } + + public function testTwo() + { + } +} + +?> diff --git a/rules-tests/PHPUnit120/Rector/Class_/AllowMockObjectsWithoutExpectationsAttributeRector/Source/SomeFinalClass.php b/rules-tests/PHPUnit120/Rector/Class_/AllowMockObjectsWithoutExpectationsAttributeRector/Source/SomeFinalClass.php new file mode 100644 index 00000000..f3419b06 --- /dev/null +++ b/rules-tests/PHPUnit120/Rector/Class_/AllowMockObjectsWithoutExpectationsAttributeRector/Source/SomeFinalClass.php @@ -0,0 +1,8 @@ +isObjectType($methodCall->var, new ObjectType(PHPUnitClassName::MOCK_OBJECT))) { - continue; + if ($methodCall->var instanceof Node\Expr\Variable || $methodCall->var instanceof PropertyFetch) { + return true; } - - return true; } return false; From 833fc46a8423dc71c03d039705d7a3854918815e Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Tue, 3 Feb 2026 23:42:54 +0000 Subject: [PATCH 2/2] [rector] Rector fixes --- .../AllowMockObjectsWithoutExpectationsAttributeRector.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rules/PHPUnit120/Rector/Class_/AllowMockObjectsWithoutExpectationsAttributeRector.php b/rules/PHPUnit120/Rector/Class_/AllowMockObjectsWithoutExpectationsAttributeRector.php index a4bfcab3..058d52ef 100644 --- a/rules/PHPUnit120/Rector/Class_/AllowMockObjectsWithoutExpectationsAttributeRector.php +++ b/rules/PHPUnit120/Rector/Class_/AllowMockObjectsWithoutExpectationsAttributeRector.php @@ -4,6 +4,7 @@ namespace Rector\PHPUnit\PHPUnit120\Rector\Class_; +use PhpParser\Node\Expr\Variable; use PhpParser\Node; use PhpParser\Node\Attribute; use PhpParser\Node\AttributeGroup; @@ -297,7 +298,7 @@ private function isMissingExpectsOnMockObjectMethodCallInSetUp(Class_ $class): b continue; } - if ($methodCall->var instanceof Node\Expr\Variable || $methodCall->var instanceof PropertyFetch) { + if ($methodCall->var instanceof Variable || $methodCall->var instanceof PropertyFetch) { return true; } }