I am using Laravel 5.8 and I am trying to run tests using phpunit in my console but I keep getting
Expected status code 200 but received 409. Failed asserting that false is true.. I have validation errors set to return 409, however this error tells me nothing. How can I output or view more meaningful output like the full exception instead of this error message which doesn't help me at all. I have tried to disable the default error reporting but its not working $this->withoutExceptionHandling();
SaveResults Controller
public function save(Request $request) {
$model = new User();
$data = $request->all();
$now = Carbon::now();
$validator = Validator::make($data, $model->getValidationRules());
// Here is where the error is thrown
if($validator->fails()) {
return response()->json(['error' => $validator->errors()->first()], 409);
}
Test.php
public function testCreateCachedData() {
$this->withoutExceptionHandling();
$this->withoutExceptionHandling();
$user = factory(User::class)->create();
$userRepo = factory(UserRepo::class)->create(['c_id' => $user->id]);
$response = $this->post('/api/users/save', $user->toArray());
$response->assertStatus(200);
}
You could do that but that would stop all tests :) So it's okay for "debugging" the tests.
But you can usually pass another parameter to the assert methods to put out your own message.
$response->assertStatus(200, "Response is: " . $response->getContent());
Something like that (depending on the situation). Then you your tests will keep running but you get more output.