mercredi 28 août 2019

Laravel Unit Test - how to get meaningful output?

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);
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire