Skip to content

Instantly share code, notes, and snippets.

@oliuz
Forked from calebporzio/ddValidation.php
Created August 18, 2019 00:04
Show Gist options
  • Save oliuz/a3408476a3bfaaa840391e652f6f0db8 to your computer and use it in GitHub Desktop.
Save oliuz/a3408476a3bfaaa840391e652f6f0db8 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