From cb94473c3bfb9f18af0d4d9b4cf03240cdbd4c13 Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Thu, 29 Oct 2026 11:48:25 +0000 Subject: [PATCH] fix: resolve class string method detection --- src/Type/Pest/HigherOrderExpectationTypeExtension.php | 2 +- tests/Rules/HigherOrderMethodCallTest.php | 6 +++++- tests/Rules/data/higher-order-method-call-errors.php | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Type/Pest/HigherOrderExpectationTypeExtension.php b/src/Type/Pest/HigherOrderExpectationTypeExtension.php index fa81874..efac3dd 100644 --- a/src/Type/Pest/HigherOrderExpectationTypeExtension.php +++ b/src/Type/Pest/HigherOrderExpectationTypeExtension.php @@ -217,7 +217,7 @@ private function resolveHigherOrderMethodCall(Type $varType, string $methodName, private function resolveMethodReturnType(Type $objectType, string $methodName, MethodCall $expr, Scope $scope): Type { - if ($objectType->hasMethod($methodName)->no()) { + if ($objectType->hasMethod($methodName)->no() || $objectType->isObject()->no()) { return new MixedType; } diff --git a/tests/Rules/HigherOrderMethodCallTest.php b/tests/Rules/HigherOrderMethodCallTest.php index 4408cec..04e7754 100644 --- a/tests/Rules/HigherOrderMethodCallTest.php +++ b/tests/Rules/HigherOrderMethodCallTest.php @@ -26,9 +26,13 @@ 'Call to an undefined method Pest\Expectation::foo().', 20, ], + [ + 'Call to an undefined method Pest\Expectation::foo().', + 22, + ], [ 'Call to an undefined method Pest\Expectations\HigherOrderExpectation, Tests\Type\Fixtures\Policy>::invalidMethod().', - 24, + 26, ], ]); }); diff --git a/tests/Rules/data/higher-order-method-call-errors.php b/tests/Rules/data/higher-order-method-call-errors.php index 2efdc02..6abea77 100644 --- a/tests/Rules/data/higher-order-method-call-errors.php +++ b/tests/Rules/data/higher-order-method-call-errors.php @@ -19,6 +19,8 @@ expect('string')->foo(); + expect(Post::class)->foo(); + expect($policy) ->view()->toBeTrue() ->invalidMethod()->toBeTrue();