Skip to content

Instantly share code, notes, and snippets.

@inxilpro
Created April 24, 2023 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inxilpro/b9e7d8ecbcb3111cf2f349eabcad26eb to your computer and use it in GitHub Desktop.
Save inxilpro/b9e7d8ecbcb3111cf2f349eabcad26eb to your computer and use it in GitHub Desktop.
<?php
use Illuminate\Contracts\Debug\ExceptionHandler;
trait InteractsWithExceptionReports
{
protected function expectsExceptionReport(
string|Closure $expected,
?string $message = null
) {
if (is_string($expected)) {
$class = $expected;
$expected = static fn($exception) => $exception instanceof $class
&& (null === $message || $exception->getMessage() === $message);
}
return $this->partialMock(ExceptionHandler::class)
->shouldReceive('report')
->withArgs($expected);
}
protected function doesntExpectExceptionReports()
{
return $this->partialMock(ExceptionHandler::class)
->shouldNotReceive('report');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment