diff --git a/src/Type/Pest/HigherOrderExpectationTypeExtension.php b/src/Type/Pest/HigherOrderExpectationTypeExtension.php index 22cafb5..fa81874 100644 --- a/src/Type/Pest/HigherOrderExpectationTypeExtension.php +++ b/src/Type/Pest/HigherOrderExpectationTypeExtension.php @@ -300,18 +300,6 @@ private function isKnownExpectationMethod(string $methodName): bool $classReflection = $this->reflectionProvider->getClass(Expectation::class); - if ($classReflection->hasNativeMethod($methodName)) { - return true; - } - - foreach ($classReflection->getResolvedMixinTypes() as $mixinType) { - foreach ($mixinType->getObjectClassReflections() as $mixinClassReflection) { - if ($mixinClassReflection->hasNativeMethod($methodName)) { - return true; - } - } - } - - return false; + return $classReflection->hasMethod($methodName); } } diff --git a/tests/Rules/CustomExpectationMethodCallTest.php b/tests/Rules/CustomExpectationMethodCallTest.php new file mode 100644 index 0000000..f65d7fd --- /dev/null +++ b/tests/Rules/CustomExpectationMethodCallTest.php @@ -0,0 +1,21 @@ +analyse([ + __DIR__.'/data/custom-expectation-method-call.php', + ], []); +}); diff --git a/tests/Rules/Fixtures/CustomExpectations.php b/tests/Rules/Fixtures/CustomExpectations.php new file mode 100644 index 0000000..0d7e31d --- /dev/null +++ b/tests/Rules/Fixtures/CustomExpectations.php @@ -0,0 +1,15 @@ + + */ + public function toBeCustom(): Expectation; +} diff --git a/tests/Rules/Fixtures/CustomExpectationsExtension.php b/tests/Rules/Fixtures/CustomExpectationsExtension.php new file mode 100644 index 0000000..35a16e2 --- /dev/null +++ b/tests/Rules/Fixtures/CustomExpectationsExtension.php @@ -0,0 +1,32 @@ +getName() === Expectation::class + && $this->customExpectations()->hasNativeMethod($methodName); + } + + public function getMethod(ClassReflection $classReflection, string $methodName): MethodReflection + { + return $this->customExpectations()->getNativeMethod($methodName); + } + + private function customExpectations(): ClassReflection + { + return $this->reflectionProvider->getClass(CustomExpectations::class); + } +} diff --git a/tests/Rules/custom-expectations.neon b/tests/Rules/custom-expectations.neon new file mode 100644 index 0000000..800b215 --- /dev/null +++ b/tests/Rules/custom-expectations.neon @@ -0,0 +1,8 @@ +includes: + - ../extension.neon + +services: + - + class: Tests\Rules\Fixtures\CustomExpectationsExtension + tags: + - phpstan.broker.methodsClassReflectionExtension diff --git a/tests/Rules/data/custom-expectation-method-call.php b/tests/Rules/data/custom-expectation-method-call.php new file mode 100644 index 0000000..888c705 --- /dev/null +++ b/tests/Rules/data/custom-expectation-method-call.php @@ -0,0 +1,13 @@ +toBeCustom(); + + expect(new Post)->toBeCustom(); + + expect('Hello')->toBeCustom(); +});