-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add withoutExceptionHandling method for testing.
- Loading branch information
1 parent
d4ae7b8
commit a171f44
Showing
2 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
src/Illuminate/Foundation/Testing/Concerns/InteractsWithExceptionHandling.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace Illuminate\Foundation\Testing\Concerns; | ||
|
||
use Exception; | ||
use Illuminate\Contracts\Debug\ExceptionHandler; | ||
use Symfony\Component\Console\Application as ConsoleApplication; | ||
|
||
trait InteractsWithExceptionHandling | ||
{ | ||
/** | ||
* The previous exception handler. | ||
* | ||
* @var ExceptionHandler|null | ||
*/ | ||
protected $previousExceptionHandler; | ||
|
||
/** | ||
* Restore exception handling. | ||
* | ||
* @return $this | ||
*/ | ||
protected function withExceptionHandling() | ||
{ | ||
if ($this->previousExceptionHandler) { | ||
$this->app->instance(ExceptionHandler::class, $this->previousExceptionHandler); | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Disable exception handling for the test. | ||
* | ||
* @return $this | ||
*/ | ||
protected function withoutExceptionHandling() | ||
{ | ||
$this->previousExceptionHandler = app(ExceptionHandler::class); | ||
|
||
$this->app->instance(ExceptionHandler::class, new class implements ExceptionHandler { | ||
public function __construct() {} | ||
public function report(Exception $e) {} | ||
public function render($request, Exception $e) { | ||
throw $e; | ||
} | ||
public function renderForConsole($output, Exception $e) { | ||
(new ConsoleApplication)->renderException($e, $output); | ||
} | ||
}); | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters