-
-
Save oliuz/a3408476a3bfaaa840391e652f6f0db8 to your computer and use it in GitHub Desktop.
little Laravel TestCase helper to get better validation output
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
<?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