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

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

This comment has been minimized.

Copy link
Contributor Author

commented Jul 29, 2019

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

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor Author

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

2 checks passed

continuous-integration/styleci/pr The analysis has passed
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@jasonmccreary jasonmccreary deleted the jasonmccreary:session-input-assertion branch Jul 30, 2019

kennith added a commit to kennith/docs that referenced this pull request Aug 4, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.