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

Clearer error reporting on seeInDatabase() #17408

Closed
wants to merge 1 commit into from
Closed

Clearer error reporting on seeInDatabase() #17408

wants to merge 1 commit into from

Conversation

markokeeffe
Copy link
Contributor

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.

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.
@sileence
Copy link
Contributor

@markokeeffe please check #16679

This will be available for Laravel 5.4 (next week).

@sileence
Copy link
Contributor

@markokeeffe maybe you could improve from there (adding the pretty print or anything else you might consider).

@GrahamCampbell
Copy link
Member

Already in Laravel 5.4. If there are any other changes you'd like to see, please send a PR to 5.4. :)

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