I've made unit tests for my Laravel project, and I have a setUp
method which looks like this:
public function setUp()
{
parent::setUp();
$this->user = factory(User::class)->states('admin', 'manager', 'code', 'coordinator')->create();
}
My goal is, to delete this row from my database after the tests are executed. I could delete it in a tearDown
method, but my question is: Is there a better way to do it, than manually delete it? I mean something like which handles this in the background?
You can use this action after testing
DB::statement("TRUNCATE TABLE users;");