Laravel Dusk, DatabaseTransactions not doing the RollBack

我是研究僧i 提交于 2020-01-25 03:49:12

问题


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', 'autoemail@hotmail.com')
                ->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.


回答1:


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.



来源:https://stackoverflow.com/questions/49542889/laravel-dusk-databasetransactions-not-doing-the-rollback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!