Is it possible to print the message out from the error bag when testing API's using unit test? Yes it already shows the exception but it does not specify exactly what and in which validation the error is.
To make it clear, please have a look at this:
Tests: 1 failed, 23 passed, 3 pending
Illuminate\Validation\ValidationException
The given data was invalid
And what I'm expecting:
Tests: 1 failed, 23 passed, 3 pending
Illuminate\Validation\ValidationException
The given data was invalid, [
'errors' => [all the validation errors listed here]
]
UPDATE
Already tried this but doesn't work:
// inside setUp method
$this->withoutExceptionHandling();
// inside test method
$this->postJson($uri, $this->newUser)
// ->dumpSession()
// ->dumpHeader()
->dump();
Also please, have a look at my script:
public function testCustomerCanStoreNewUser()
{
$this->actingAs($this->customer, 'api');
$uri = route('users.store');
$this->postJson($uri, $this->newUser)
->dumpSession()
->dumpHeaders()
->dump()
->assertCreated()
->assertJsonStructure(['success', 'data']);
$this->assertDatabaseHas('users', $this->newUser);
}