mirror of
https://github.com/pestphp/pest.git
synced 2026-03-12 02:37:22 +01:00
fix: higher order message
This commit is contained in:
@ -55,14 +55,12 @@ final class HigherOrderMessage
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return is_array($this->arguments)
|
return Reflection::call($target, $this->name, is_array($this->arguments) ? $this->arguments : []);
|
||||||
? Reflection::call($target, $this->name, $this->arguments)
|
|
||||||
: $target->{$this->name}; /* @phpstan-ignore-line */
|
|
||||||
} catch (Throwable $throwable) {
|
} catch (Throwable $throwable) {
|
||||||
Reflection::setPropertyValue($throwable, 'file', $this->filename);
|
Reflection::setPropertyValue($throwable, 'file', $this->filename);
|
||||||
Reflection::setPropertyValue($throwable, 'line', $this->line);
|
Reflection::setPropertyValue($throwable, 'line', $this->line);
|
||||||
|
|
||||||
if ($throwable->getMessage() === self::getUndefinedMethodMessage($target, $this->name)) {
|
if ($throwable->getMessage() === $this->getUndefinedMethodMessage($target, $this->name)) {
|
||||||
/** @var ReflectionClass<TValue> $reflection */
|
/** @var ReflectionClass<TValue> $reflection */
|
||||||
$reflection = new ReflectionClass($target);
|
$reflection = new ReflectionClass($target);
|
||||||
/* @phpstan-ignore-next-line */
|
/* @phpstan-ignore-next-line */
|
||||||
@ -94,7 +92,7 @@ final class HigherOrderMessage
|
|||||||
return in_array($this->name, get_class_methods(HigherOrderCallables::class), true);
|
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) {
|
if (\PHP_MAJOR_VERSION >= 8) {
|
||||||
return sprintf(self::UNDEFINED_METHOD, sprintf('%s::%s()', $target::class, $methodName));
|
return sprintf(self::UNDEFINED_METHOD, sprintf('%s::%s()', $target::class, $methodName));
|
||||||
|
|||||||
19
tests/Unit/Support/HigherOrderMessage.php
Normal file
19
tests/Unit/Support/HigherOrderMessage.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Pest\Support\HigherOrderMessage;
|
||||||
|
|
||||||
|
test('undefined method exceptions', function () {
|
||||||
|
$message = new HigherOrderMessage(
|
||||||
|
__FILE__,
|
||||||
|
1,
|
||||||
|
'foqwdqwd',
|
||||||
|
null
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(fn () => $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__);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user