diff --git a/src/Support/HigherOrderTapProxy.php b/src/Support/HigherOrderTapProxy.php index 1b5f12cf..8df75e3a 100644 --- a/src/Support/HigherOrderTapProxy.php +++ b/src/Support/HigherOrderTapProxy.php @@ -39,20 +39,17 @@ final class HigherOrderTapProxy */ public function __get(string $property) { - try { - return $this->target->{$property}; // @phpstan-ignore-line - } catch (Throwable $throwable) { // @phpstan-ignore-line - Reflection::setPropertyValue($throwable, 'file', Backtrace::file()); - Reflection::setPropertyValue($throwable, 'line', Backtrace::line()); - - if (Str::startsWith($message = $throwable->getMessage(), self::UNDEFINED_PROPERTY)) { - /** @var ReflectionClass $reflection */ - $reflection = (new ReflectionClass($this->target))->getParentClass(); - Reflection::setPropertyValue($throwable, 'message', sprintf('Undefined property %s::$%s', $reflection->getName(), $property)); - } - - throw $throwable; + if (property_exists($this->target, $property)) { + return $this->target->{$property}; } + + $className = (new ReflectionClass($this->target))->getName(); + + if (str_starts_with($className, "P\\")) { + $className = substr($className, 2); + } + + trigger_error(sprintf('Undefined property %s::$%s', $className, $property), E_USER_WARNING); } /** diff --git a/tests/Features/Warnings.php b/tests/Features/Warnings.php new file mode 100644 index 00000000..e638b3f0 --- /dev/null +++ b/tests/Features/Warnings.php @@ -0,0 +1,13 @@ +fooqwdfwqdfqw; + + expect(true)->toBeTrue(); +}); + +test('user warning', function () { + trigger_error('This is a warning description', E_USER_WARNING); + + expect(true)->toBeTrue(); +});