Clearer error reporting on seeInDatabase() #17408
Closed
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.
I seem to spend a fair amount of time debugging my unit tests when I encounter an "Unable to find row in database table ..." error using the seeInDatabase() method. The output tells me the data I was looking for in the table (which is already in my unit test) and I have to add extra code such as
$allRows = MyModel::all()->all()
before calling$this->seeInDatabase(...)
and stepping through with a debugger to see what data is in the table to find out where I'm going wrong.I can only assume that other people are having a similar experience, I think anyone using an in-memory sqlite database for unit testing will have some frustration debugging these errors.
This change executes a second "SELECT * FROM {table}" query if the count is zero, and formats the JSON data for better reading in the console.