Created
June 20, 2018 16:30
-
-
Save calebporzio/57f978e7b0517c8f6a1284efacb71d3d to your computer and use it in GitHub Desktop.
little Laravel TestCase helper to get better validation output
This file contains hidden or 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
<?php | |
// Place this method somewhere in TestCase.php | |
protected function ddValidation(array $except = []) | |
{ | |
if ($this->originalExceptionHandler == null) { | |
$this->originalExceptionHandler = app(ExceptionHandler::class); | |
} | |
$this->app->instance(ExceptionHandler::class, new class($this->originalExceptionHandler) implements ExceptionHandler { | |
protected $originalHandler; | |
public function __construct($originalHandler) | |
{ | |
$this->originalHandler = $originalHandler; | |
} | |
public function report(Exception $e) | |
{ | |
// | |
} | |
public function render($request, Exception $e) | |
{ | |
if ($e instanceof ValidationException) { | |
dd($e->errors()); | |
} | |
throw $e; | |
} | |
public function renderForConsole($output, Exception $e) | |
{ | |
(new ConsoleApplication)->renderException($e, $output); | |
} | |
}); | |
return $this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment