From 10b204e19d0f6721e3e2ca3c4a46bfbd7e0c4547 Mon Sep 17 00:00:00 2001 From: Fabio Ivona Date: Fri, 18 Feb 2022 16:40:31 +0100 Subject: [PATCH] handles toThrow exception with a "class not found" error --- src/Mixins/Expectation.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Mixins/Expectation.php b/src/Mixins/Expectation.php index 3fbd2110..64235cfc 100644 --- a/src/Mixins/Expectation.php +++ b/src/Mixins/Expectation.php @@ -6,6 +6,7 @@ namespace Pest\Mixins; use BadMethodCallException; use Closure; +use Error; use InvalidArgumentException; use Pest\Exceptions\InvalidExpectationValue; use Pest\Support\Arr; @@ -824,6 +825,10 @@ final class Expectation ($this->value)(); } catch (Throwable $e) { // @phpstan-ignore-line if (!class_exists($exception)) { + if ($e instanceof Error && $e->getMessage() === "Class \"$exception\" not found") { + throw $e; + } + Assert::assertStringContainsString($exception, $e->getMessage()); return $this;