mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
feat: warnings support
This commit is contained in:
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
13
tests/Features/Warnings.php
Normal file
13
tests/Features/Warnings.php
Normal 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();
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user