Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.8] Don't check for status code in assertJsonMissingValidationErrors() #28913

Merged
merged 2 commits into from
Jun 22, 2019
Merged

Conversation

SjorsO
Copy link
Contributor

@SjorsO SjorsO commented Jun 21, 2019

#28595 fixes a problem where returning an empty response causes the assertJsonMissingValidationErrors assertion to fail because an empty response is not valid json.

This PR removes the status code 204 check. With this PR you can write tests using assertJsonMissingValidationErrors without explicitly returning a response. For example:

Controller:

public function post(Request $request)
{
    $data = $request->validate([
        // a bunch of validation rules
    ]);

    SomeModel::create($data);
}

Test:

function it_stores_the_model()
{
    $this->postJson('/model/store', [
            // a bunch of values
        ])
        ->assertJsonMissingValidationErrors()
        ->assertStatus(200);
}

Using a combination of these two assertions is useful because if the validation fails, the test will output exactly what went wrong. It also checks if your code explodes and causes a 500 error.

Often when writing api endpoints, you don't return a response. It is either not necessary, or because the consumer should just do another index call. However, currently the test above fails because we are not explicitly returning a 204 status code.

@taylorotwell taylorotwell merged commit 7593d65 into laravel:5.8 Jun 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants