From 91ae1dbcb975d5ee78a256896a38582dff1e7227 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Sun, 18 Jan 2026 17:08:54 +0100 Subject: [PATCH] fix a class name that should be string --- composer.json | 2 +- .../Class_/TypeWillReturnCallableArrowFunctionRector.php | 8 ++++++-- .../MethodCall/AssertTrueFalseToSpecificMethodRector.php | 5 +---- src/Enum/PHPUnitClassName.php | 4 ++++ 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/composer.json b/composer.json index 3f8e488b..3c4ffe1c 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ "phpstan/phpstan": "^2.1.33", "phpstan/phpstan-deprecation-rules": "^2.0", "phpstan/phpstan-webmozart-assert": "^2.0", - "phpunit/phpunit": "^11.5|^12.0", + "phpunit/phpunit": "^12.5", "rector/jack": "^0.5", "rector/rector-src": "dev-main", "rector/swiss-knife": "^2.3", diff --git a/rules/CodeQuality/Rector/Class_/TypeWillReturnCallableArrowFunctionRector.php b/rules/CodeQuality/Rector/Class_/TypeWillReturnCallableArrowFunctionRector.php index acd6962f..609427c5 100644 --- a/rules/CodeQuality/Rector/Class_/TypeWillReturnCallableArrowFunctionRector.php +++ b/rules/CodeQuality/Rector/Class_/TypeWillReturnCallableArrowFunctionRector.php @@ -19,12 +19,12 @@ use PHPStan\Type\NeverType; use PHPStan\Type\ObjectType; use PHPStan\Type\Type; -use PHPUnit\Framework\MockObject\Builder\InvocationMocker; use Rector\Enum\ClassName; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; use Rector\PHPUnit\CodeQuality\NodeAnalyser\SetUpAssignedMockTypesResolver; use Rector\PHPUnit\CodeQuality\Reflection\MethodParametersAndReturnTypesResolver; use Rector\PHPUnit\CodeQuality\ValueObject\ParamTypesAndReturnType; +use Rector\PHPUnit\Enum\PHPUnitClassName; use Rector\PHPUnit\NodeAnalyzer\TestsNodeAnalyzer; use Rector\Rector\AbstractRector; use Rector\Reflection\ReflectionResolver; @@ -166,7 +166,11 @@ public function refactor(Node $node): ?Class_ $methodName = $methodNameExpr->value; $callerType = $this->getType($parentMethodCall->var); - if ($callerType instanceof ObjectType && $callerType->getClassName() === InvocationMocker::class) { + if ($callerType instanceof ObjectType && in_array( + $callerType->getClassName(), + [PHPUnitClassName::INVOCATION_MOCKER, PHPUnitClassName::INVOCATION_STUBBER], + true + )) { $parentMethodCall = $parentMethodCall->var; if ($parentMethodCall instanceof MethodCall) { diff --git a/rules/CodeQuality/Rector/MethodCall/AssertTrueFalseToSpecificMethodRector.php b/rules/CodeQuality/Rector/MethodCall/AssertTrueFalseToSpecificMethodRector.php index 1fa078e3..d33d85a8 100644 --- a/rules/CodeQuality/Rector/MethodCall/AssertTrueFalseToSpecificMethodRector.php +++ b/rules/CodeQuality/Rector/MethodCall/AssertTrueFalseToSpecificMethodRector.php @@ -120,10 +120,7 @@ public function refactor(Node $node): ?Node [$functionName, $assetMethodName, $notAssertMethodName] = self::FUNCTION_NAME_WITH_ASSERT_METHOD_NAMES[$firstArgumentName]; - $functionNameWithAssertMethods = new FunctionNameWithAssertMethods( - $assetMethodName, - $notAssertMethodName - ); + $functionNameWithAssertMethods = new FunctionNameWithAssertMethods($assetMethodName, $notAssertMethodName); $this->renameMethod($node, $functionNameWithAssertMethods); diff --git a/src/Enum/PHPUnitClassName.php b/src/Enum/PHPUnitClassName.php index 7d95373a..51a4ee21 100644 --- a/src/Enum/PHPUnitClassName.php +++ b/src/Enum/PHPUnitClassName.php @@ -17,6 +17,10 @@ final class PHPUnitClassName public const string INVOCATION_ORDER = 'PHPUnit\Framework\MockObject\Rule\InvocationOrder'; + public const string INVOCATION_MOCKER = 'PHPUnit\Framework\MockObject\Builder\InvocationMocker'; + + public const string INVOCATION_STUBBER = 'PHPUnit\Framework\MockObject\InvocationStubber'; + public const string TEST_LISTENER = 'PHPUnit\Framework\TestListener'; /**