If you call truncate(), either through the query builder, or via an Eloquent model, then the database records added during a test are not rolled back when using the RefreshDatabase.
User model.User::truncate() after creating the user.User::count(). It will equal 1 instead of 0.On MySQL, data definition language (DDL) statements like TRUNCATE cannot be rolled back and automatically commit the transaction: https://dev.mysql.com/doc/refman/8.0/en/cannot-roll-back.html
As a workaround, you can start a new transaction (this doesn't roll back queries before User::truncate()):
User::truncate();
DB::rollBack();
DB::beginTransaction();
User::create();
Ah, I didn't know that! Thanks for the clarification.
It's not an issue as such since you can simply do something like this:
User::query() -> delete();
In any event, if someone searches for this again, they'll find this issue and the explanation.
Most helpful comment
Ah, I didn't know that! Thanks for the clarification.
It's not an issue as such since you can simply do something like this:
User::query() -> delete();In any event, if someone searches for this again, they'll find this issue and the explanation.