Skip to content

Commit 4ce097f

Browse files
committed
Fix
1 parent 3151b5d commit 4ce097f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

rules/PHPUnit120/Rector/Class_/AllowMockObjectsWithoutExpectationsAttributeRector.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use PhpParser\Node\Stmt\Class_;
1616
use PhpParser\Node\Stmt\ClassMethod;
1717
use PHPStan\Reflection\ReflectionProvider;
18+
use PHPStan\Type\NeverType;
19+
use PHPStan\Type\ObjectType;
1820
use Rector\Doctrine\NodeAnalyzer\AttributeFinder;
1921
use Rector\PhpParser\Node\BetterNodeFinder;
2022
use Rector\PHPUnit\Enum\PHPUnitAttribute;
@@ -296,6 +298,14 @@ private function isMissingExpectsOnMockObjectMethodCallInSetUp(Class_ $class): b
296298
continue;
297299
}
298300

301+
$type = $this->getType($methodCall->var);
302+
if (
303+
// never type check is needed for fixture with mock final class, example use is possibly by dg/bypass-finals
304+
! $type instanceof NeverType &&
305+
! $this->isObjectType($methodCall->var, new ObjectType(PHPUnitClassName::MOCK_OBJECT))) {
306+
continue;
307+
}
308+
299309
if ($methodCall->var instanceof Variable || $methodCall->var instanceof PropertyFetch) {
300310
return true;
301311
}

0 commit comments

Comments
 (0)