handles toThrow exception with a "class not found" error

This commit is contained in:
Fabio Ivona
2022-02-18 16:40:31 +01:00
parent 36130eb7a0
commit 10b204e19d

View File

@ -6,6 +6,7 @@ namespace Pest\Mixins;
use BadMethodCallException; use BadMethodCallException;
use Closure; use Closure;
use Error;
use InvalidArgumentException; use InvalidArgumentException;
use Pest\Exceptions\InvalidExpectationValue; use Pest\Exceptions\InvalidExpectationValue;
use Pest\Support\Arr; use Pest\Support\Arr;
@ -824,6 +825,10 @@ final class Expectation
($this->value)(); ($this->value)();
} catch (Throwable $e) { // @phpstan-ignore-line } catch (Throwable $e) { // @phpstan-ignore-line
if (!class_exists($exception)) { if (!class_exists($exception)) {
if ($e instanceof Error && $e->getMessage() === "Class \"$exception\" not found") {
throw $e;
}
Assert::assertStringContainsString($exception, $e->getMessage()); Assert::assertStringContainsString($exception, $e->getMessage());
return $this; return $this;