From 070139eda7a066bf15b5f233f055d2b3fb08ae57 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Thu, 15 Jun 2023 10:42:31 +0200 Subject: [PATCH] fix: higher order message --- src/Support/HigherOrderMessage.php | 8 +++----- tests/Unit/Support/HigherOrderMessage.php | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 tests/Unit/Support/HigherOrderMessage.php diff --git a/src/Support/HigherOrderMessage.php b/src/Support/HigherOrderMessage.php index bcec5b20..5a6e227f 100644 --- a/src/Support/HigherOrderMessage.php +++ b/src/Support/HigherOrderMessage.php @@ -55,14 +55,12 @@ final class HigherOrderMessage } try { - return is_array($this->arguments) - ? Reflection::call($target, $this->name, $this->arguments) - : $target->{$this->name}; /* @phpstan-ignore-line */ + return Reflection::call($target, $this->name, is_array($this->arguments) ? $this->arguments : []); } catch (Throwable $throwable) { Reflection::setPropertyValue($throwable, 'file', $this->filename); Reflection::setPropertyValue($throwable, 'line', $this->line); - if ($throwable->getMessage() === self::getUndefinedMethodMessage($target, $this->name)) { + if ($throwable->getMessage() === $this->getUndefinedMethodMessage($target, $this->name)) { /** @var ReflectionClass $reflection */ $reflection = new ReflectionClass($target); /* @phpstan-ignore-next-line */ @@ -94,7 +92,7 @@ final class HigherOrderMessage return in_array($this->name, get_class_methods(HigherOrderCallables::class), true); } - private static function getUndefinedMethodMessage(object $target, string $methodName): string + private function getUndefinedMethodMessage(object $target, string $methodName): string { if (\PHP_MAJOR_VERSION >= 8) { return sprintf(self::UNDEFINED_METHOD, sprintf('%s::%s()', $target::class, $methodName)); diff --git a/tests/Unit/Support/HigherOrderMessage.php b/tests/Unit/Support/HigherOrderMessage.php new file mode 100644 index 00000000..cc698ab3 --- /dev/null +++ b/tests/Unit/Support/HigherOrderMessage.php @@ -0,0 +1,19 @@ + $message->call($this))->toThrow(function (ReflectionException $exception) { + expect($exception) + ->getMessage()->toBe('Call to undefined method PHPUnit\Framework\TestCase::foqwdqwd()') + ->getLine()->toBe(1) + ->getFile()->toBe(__FILE__); + }); +});