mirror of
https://github.com/pestphp/pest.git
synced 2026-03-07 08:17:22 +01:00
first
This commit is contained in:
35
src/Support/ExceptionTrace.php
Normal file
35
src/Support/ExceptionTrace.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Pest\Support;
|
||||
|
||||
use Closure;
|
||||
use Throwable;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class ExceptionTrace
|
||||
{
|
||||
private const UNDEFINED_METHOD = 'Call to undefined method P\\';
|
||||
|
||||
/**
|
||||
* Ensures the given closure reports
|
||||
* the good execution context.
|
||||
*/
|
||||
public static function ensure(Closure $closure): void
|
||||
{
|
||||
try {
|
||||
$closure();
|
||||
} catch (Throwable $throwable) {
|
||||
if (Str::startsWith($message = $throwable->getMessage(), self::UNDEFINED_METHOD)) {
|
||||
$message = str_replace(self::UNDEFINED_METHOD, 'Call to undefined method ', $message);
|
||||
|
||||
Reflection::setPropertyValue($throwable, 'message', $message);
|
||||
}
|
||||
|
||||
throw $throwable;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user