Skip to content

[5.8] Add assertSessionHasInput to TestResponse#29327

Merged
taylorotwell merged 1 commit into
laravel:5.8from
jasonmccreary:session-input-assertion
Jul 30, 2019
Merged

[5.8] Add assertSessionHasInput to TestResponse#29327
taylorotwell merged 1 commit into
laravel:5.8from
jasonmccreary:session-input-assertion

Conversation

@jasonmccreary

@jasonmccreary jasonmccreary commented Jul 29, 2019

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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

SjorsO commented Jul 30, 2019

Copy link
Copy Markdown
Contributor

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

jasonmccreary commented Jul 30, 2019

Copy link
Copy Markdown
Contributor Author

@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