Skip to content

Instantly share code, notes, and snippets.

@calebporzio
Created June 20, 2018 16:30
Show Gist options
  • Save calebporzio/57f978e7b0517c8f6a1284efacb71d3d to your computer and use it in GitHub Desktop.
Save calebporzio/57f978e7b0517c8f6a1284efacb71d3d to your computer and use it in GitHub Desktop.
little Laravel TestCase helper to get better validation output
<?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