From eec65623b9d1c5f1a8fa97da2e33827bf7f3ba65 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 2 Jun 2026 17:13:53 +0700 Subject: [PATCH 1/2] [PHPUnit12] Handle crash on property not exists on PropertyCreateMockToCreateStubRector --- .../skip_on_property_not_exists.php.inc | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 rules-tests/PHPUnit120/Rector/Class_/PropertyCreateMockToCreateStubRector/Fixture/skip_on_property_not_exists.php.inc diff --git a/rules-tests/PHPUnit120/Rector/Class_/PropertyCreateMockToCreateStubRector/Fixture/skip_on_property_not_exists.php.inc b/rules-tests/PHPUnit120/Rector/Class_/PropertyCreateMockToCreateStubRector/Fixture/skip_on_property_not_exists.php.inc new file mode 100644 index 00000000..521a88de --- /dev/null +++ b/rules-tests/PHPUnit120/Rector/Class_/PropertyCreateMockToCreateStubRector/Fixture/skip_on_property_not_exists.php.inc @@ -0,0 +1,20 @@ +someMock = $this->createMock(\stdClass::class); + } + + public function testThis() + { + $this->assertSame('...', $this->someMock); + } +} + +?> \ No newline at end of file From ce09d7327b5fadafcebf9be27ea133364afc3787 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 2 Jun 2026 17:18:37 +0700 Subject: [PATCH 2/2] fix --- .../CodeQuality/NodeAnalyser/MockObjectExprDetector.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/rules/CodeQuality/NodeAnalyser/MockObjectExprDetector.php b/rules/CodeQuality/NodeAnalyser/MockObjectExprDetector.php index 88573763..2ffc902a 100644 --- a/rules/CodeQuality/NodeAnalyser/MockObjectExprDetector.php +++ b/rules/CodeQuality/NodeAnalyser/MockObjectExprDetector.php @@ -11,6 +11,7 @@ use PhpParser\Node\Identifier; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; +use PhpParser\Node\Stmt\Property; use PHPStan\Reflection\MethodReflection; use PHPStan\Type\ObjectType; use Rector\NodeNameResolver\NodeNameResolver; @@ -132,6 +133,14 @@ public function isUsedForMocking(Expr $expr, ClassMethod $classMethod): bool public function isPropertyUsedForMocking(Class_ $class, string $propertyName): bool { + $property = $class->getProperty($propertyName); + + // possibly dynamic property on purpose + // mark as used + if (! $property instanceof Property) { + return true; + } + // find out, how many are used in call likes as args /** @var array $methodCalls */ $methodCalls = $this->betterNodeFinder->findInstancesOfScoped($class->getMethods(), [MethodCall::class]);