I am running laravel 5.4
and noticed that rollbacks in transactions do not work. I set my database engine to InnoDB
in the settings.php
file and tried DB::rollback();
and DB::rollBack();
(i.e. upper and lower case b) but it does not roll back my database.
I wrote a unit test bellow. It creates a record, commits it, then rolls back. However, the last assertion fails. After it rolls back, the record is still found in the database. Is there something I am missing? Or is there a bug with laravel?
public function testRollback()
{
$this->artisan('migrate:refresh', [
'--seed' => '1'
]);
DB::beginTransaction();
Season::create(['start_date' => Carbon::now(), 'end_date' => Carbon::now(),]);
DB::commit();
$this->assertDatabaseHas('seasons', [
'start_date' => Carbon::now(), 'end_date' => Carbon::now(),
]);
DB::rollBack();
// This assertion fails. It still finds the record after calling roll back
$this->assertDatabaseMissing('seasons', [
'start_date' => Carbon::now(), 'end_date' => Carbon::now(),
]);
}