mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
handles toThrow exception with a "class not found" error
This commit is contained in:
@ -6,6 +6,7 @@ namespace Pest;
|
|||||||
|
|
||||||
use BadMethodCallException;
|
use BadMethodCallException;
|
||||||
use Closure;
|
use Closure;
|
||||||
|
use Error;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use Pest\Concerns\Extendable;
|
use Pest\Concerns\Extendable;
|
||||||
use Pest\Concerns\RetrievesValues;
|
use Pest\Concerns\RetrievesValues;
|
||||||
@ -911,8 +912,12 @@ final class Expectation
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
($this->value)();
|
($this->value)();
|
||||||
} catch (Throwable $e) { // @phpstan-ignore-line
|
} catch (Throwable $e) {
|
||||||
if (!class_exists($exception)) {
|
if (!class_exists($exception)) {
|
||||||
|
if ($e instanceof Error && (bool) preg_match("/Class [\"']{$exception}[\"'] not found/", $e->getMessage())) {
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
Assert::assertStringContainsString($exception, $e->getMessage());
|
Assert::assertStringContainsString($exception, $e->getMessage());
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|||||||
@ -26,6 +26,7 @@ final class Backtrace
|
|||||||
$current = null;
|
$current = null;
|
||||||
|
|
||||||
foreach (debug_backtrace(self::BACKTRACE_OPTIONS) as $trace) {
|
foreach (debug_backtrace(self::BACKTRACE_OPTIONS) as $trace) {
|
||||||
|
assert(array_key_exists(self::FILE, $trace));
|
||||||
if (Str::endsWith($trace[self::FILE], (string) realpath('vendor/phpunit/phpunit/src/Util/FileLoader.php'))) {
|
if (Str::endsWith($trace[self::FILE], (string) realpath('vendor/phpunit/phpunit/src/Util/FileLoader.php'))) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -45,7 +46,11 @@ final class Backtrace
|
|||||||
*/
|
*/
|
||||||
public static function file(): string
|
public static function file(): string
|
||||||
{
|
{
|
||||||
return debug_backtrace(self::BACKTRACE_OPTIONS)[1][self::FILE];
|
$trace = debug_backtrace(self::BACKTRACE_OPTIONS)[1];
|
||||||
|
|
||||||
|
assert(array_key_exists(self::FILE, $trace));
|
||||||
|
|
||||||
|
return $trace[self::FILE];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -53,7 +58,11 @@ final class Backtrace
|
|||||||
*/
|
*/
|
||||||
public static function dirname(): string
|
public static function dirname(): string
|
||||||
{
|
{
|
||||||
return dirname(debug_backtrace(self::BACKTRACE_OPTIONS)[1][self::FILE]);
|
$trace = debug_backtrace(self::BACKTRACE_OPTIONS)[1];
|
||||||
|
|
||||||
|
assert(array_key_exists(self::FILE, $trace));
|
||||||
|
|
||||||
|
return dirname($trace[self::FILE]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,6 +70,10 @@ final class Backtrace
|
|||||||
*/
|
*/
|
||||||
public static function line(): int
|
public static function line(): int
|
||||||
{
|
{
|
||||||
return debug_backtrace(self::BACKTRACE_OPTIONS)[1]['line'];
|
$trace = debug_backtrace(self::BACKTRACE_OPTIONS)[1];
|
||||||
|
|
||||||
|
assert(array_key_exists('line', $trace));
|
||||||
|
|
||||||
|
return $trace['line'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -496,6 +496,8 @@
|
|||||||
✓ not failures
|
✓ not failures
|
||||||
✓ closure missing parameter
|
✓ closure missing parameter
|
||||||
✓ closure missing type-hint
|
✓ closure missing type-hint
|
||||||
|
✓ it can handle a non-defined exception
|
||||||
|
✓ it can handle a class not found Error
|
||||||
|
|
||||||
PASS Tests\Features\Expect\unless
|
PASS Tests\Features\Expect\unless
|
||||||
✓ it pass
|
✓ it pass
|
||||||
@ -720,5 +722,5 @@
|
|||||||
✓ it is a test
|
✓ it is a test
|
||||||
✓ it uses correct parent class
|
✓ it uses correct parent class
|
||||||
|
|
||||||
Tests: 4 incompleted, 9 skipped, 478 passed
|
Tests: 4 incompleted, 9 skipped, 480 passed
|
||||||
|
|
||||||
Reference in New Issue
Block a user