-
Notifications
You must be signed in to change notification settings - Fork 11.3k
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
[8.x] Add assertExists
testing method
#38766
Conversation
Can you just assert on the $this->assertTrue($product->exists); |
In a unit test that's definitely a possibility. While testing an API endpoint or a job where the model gets reloaded elsewhere that wouldn't work. For instance a command that would prune inactive users, unless they have a subscription or whatever other criteria were set. |
I love it. I have this exact method in my app's testcase. I added it after being annoyed many times that there wasn't an assertion like it, and I was considering making this pr. The only suggestion I have would be to call it I may be missing use cases though. I only use it to test if something is deleted. |
You’re making a very good point here and I fully agree with you. Perhaps As for use cases, I found myself using this when testing endpoints with deleting multiple records which don’t necessarily return a 422 or 403 when you’re not allowed to delete a thing. This could also prove useful with pruning as stated in a previous comment of mine. |
Renamed to |
@taylorotwell Could it make sense to introduce a Model assertion wrapper so that we can call PS: This would allow adding |
* [8.x] Add `assertExists` testing method * add methods Co-authored-by: Taylor Otwell <taylorotwell@gmail.com>
This PR adds the
assertExists
method for use in testing.This method aims to make checking whether a model exists in the database easier, much like
assertDeleted
did forassertDatabaseMissing
.With this method, the following:
Could be rewritten to: