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] Add assertSessionHasInput to TestResponse #29327

Merged
merged 1 commit into from
Jul 30, 2019

Conversation

jasonmccreary
Copy link
Contributor

@jasonmccreary jasonmccreary commented Jul 29, 2019

This adds an assertSessionHasInput() helper method to the TestReponse class. Inline with the other session assertions, it accepts an array or a key value pair to verify exists in the flashed session array input.

Although you can test this with the available assertions, this new assertion avoids writing brittle tests which rely on internal framework values like the _old_input key.

$response->assertSessionHas('_old_input', [
    'connection_id' => $connection->id,
    'repository' => $repository,
    'source_branch' => $branch,
]);

Instead, you can now write:

$response->assertSessionHasInput([
    'connection_id' => $connection->id,
    'repository' => $repository,
    'source_branch' => $branch,
]);

@jasonmccreary
Copy link
Contributor Author

If merged, I will submit a PR to update the docs as well by adding this to the list of Available Assertions.

@driesvints driesvints changed the title Add assertSessionHasInput to TestResponse [5.8] Add assertSessionHasInput to TestResponse Jul 29, 2019
@SjorsO
Copy link
Contributor

SjorsO commented Jul 30, 2019

I think it would be useful if the assertions prints the actual old input when the assertion fails, similar to how it happens in this pr

@jasonmccreary
Copy link
Contributor Author

jasonmccreary commented Jul 30, 2019

@SjorsO, I'm not sure the difference in the output this would have. Maybe you could share the suggested code or could PR it if this were merged.

@taylorotwell taylorotwell merged commit 715da5b into laravel:5.8 Jul 30, 2019
@jasonmccreary jasonmccreary deleted the session-input-assertion branch July 30, 2019 13:42
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.

3 participants