Improve display of failures for assertDatabaseHas #43736
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR attempts to improve the developer experience when debugging
assertDatabaseHas
test failures.Currently, when a
assertDatabaseHas
assertion has failed, similar results may be displayed. The current functionality forassertDatabaseHas
is helpful in many scenarios but in others, it can make it difficult to track down the cause the failure.For example, consider the following test assertion:
When a test failure occurs and similar results are displayed with the failure message, all of the table columns are shown even though, in this case, we were concerned with 3 columns. For example:
It can be time consuming to locate each column and compare it to the expectation. Also, when the assertion columns/values are in a different order than the table schema (like in the example above), it makes it that much more complex to find the cause of the failure. The more columns a table has, the more complex it is to track down failures and the less likely a developer is going to pass columns in to their assertions in the same order as the table schema.
The PR includes updates the "similar results" functionality so that only the columns that are being asserted on get displayed back as well as displaying them in the exact order they have been asserted on.
Using the example from above, but including with the changes in this PR make the comparison much simpilar: