Jk33
Jk33

Reputation: 905

Laravel Dusk, DatabaseTransactions not doing the RollBack

I'm using Laravel Dusk, the following Register test works fine, except that it doesn't rollBack the transaction (i.e. the user record created on 'Register' always stays in the DB). My tables are all set to use InnoDB engine.

Any ideas of what is going on? I have put Logs in many places and nothing looks particularly wrong. I don't get any errors at all in laravel.log file either.

use DatabaseTransactions;

protected $connectionsToTransact = [ 'mysql' ];

/**
 * A basic browser test example.
 *
 * @return void
 */
public function testBasicExample()
{
    $this->browse(function (Browser $browser) {
        $browser->visit('/')
                ->type('name', 'Automated User')
                ->type('email', '[email protected]')
                ->type('password', 'aaaaaa')
                ->type('password_confirmation', 'aaaaaa')
                ->press('Register')
                ->assertPathIs('/login');
    });

}

This is my connection in config/database.php

'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => false,
        'engine' => 'innoDB',
    ],

UPDATE

I tried to update a model after the assert, but it doesn't work either. It seems like it's all DB transactions in general not being executed.

Upvotes: 2

Views: 1346

Answers (1)

Jonas Staudenmeir
Jonas Staudenmeir

Reputation: 25926

You can't use DatabaseTransactions in Dusk tests. Since a real browser is opening your website, your test runs in a different process.

You have to reverse the changes yourself, e.g. by deleting the registered user.

Upvotes: 4

Related Questions