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

@jasonmccreary jasonmccreary 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.

Loading

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

@SjorsO 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

Loading

@jasonmccreary
Copy link
Contributor Author

@jasonmccreary 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.

Loading

@taylorotwell taylorotwell merged commit 715da5b into laravel:5.8 Jul 30, 2019
2 checks passed
Loading
@jasonmccreary jasonmccreary deleted the session-input-assertion branch Jul 30, 2019
kennith added a commit to kennith/docs that referenced this issue Aug 4, 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
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants