feat: warnings support

This commit is contained in:
Nuno Maduro
2023-03-02 17:50:57 +00:00
parent 69a0c3ba99
commit f25a9f5558
2 changed files with 23 additions and 13 deletions

View File

@ -39,20 +39,17 @@ final class HigherOrderTapProxy
*/ */
public function __get(string $property) public function __get(string $property)
{ {
try { if (property_exists($this->target, $property)) {
return $this->target->{$property}; // @phpstan-ignore-line return $this->target->{$property};
} 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;
} }
$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);
} }
/** /**

View File

@ -0,0 +1,13 @@
<?php
test('warning', function () {
$this->fooqwdfwqdfqw;
expect(true)->toBeTrue();
});
test('user warning', function () {
trigger_error('This is a warning description', E_USER_WARNING);
expect(true)->toBeTrue();
});