I have the same issue when I have a setUp method in my tests. But ...
/**
* Setup the test
*/
public function setUp()
{
parent::setUp();
$this->beginDatabaseTransaction();
}
Fixes it
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm writing the tests where the record gets added to a table with a unique email column. I'm using DatabaseTransactions trait, but when I run the test I get:
Illuminate\Database\QueryException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'cmd@gmail.com' for key 'users_email_unique'
The beginDatabaseTransaction method of the trait seem to run the rollBack for beforeApplicationDestroyed, which would indicate that it runs from within the tearDown method before the next test, but I still get the error above. However - if I manually call:
$this->app->make('db')->rollBack();
at the end of each test - the error is gone.
Any thoughts?
Please or to participate in this conversation.