Skip to content

Conversation

@3Descape
Copy link
Contributor

@3Descape 3Descape commented Apr 13, 2025

Problem Statement:

Currently, when passing multiple key-value pairs to assertViewHasAll() and an error occurs, there is no feedback to which of the many fields caused the assertion to fail. Not even the stacktrace and line numbers provide sufficient information.

Example:

$response->assertViewHasAll([
    'key_without_value',
    'key_with_value' => 10,
    'key_with_closure' => fn ($value) => $value == 10,
    'key_with_model' => Customer::first(),
    'key_with_collection' => Customer::factory()->count(10)->create(),
]);

Before:

image

Solution:

This PR adds custom error messages to the underlying assertions to give the user better feedback, which of the fields caused the assertion error.

Please feel free to make any suggestions regarding the exact text that we want to use in the error messages - these are just what I came up with when doing a quick test.

After:

key_without_value:
image

key_with_value
image

key_with_closure
image

key_with_model
image

key_with_collection
image

@taylorotwell taylorotwell merged commit 0549cba into laravel:12.x Apr 14, 2025
13 checks passed
toshitsuna-otsuka pushed a commit to toshitsuna-otsuka/laravel-framework that referenced this pull request Apr 15, 2025
* Add descriptive error messages to assertViewHas()

* Fix inconsistency and add missing dot

* Add message to key-value case, move $actual for reuse, adjust messages.

* formatting

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
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