Laravel Dusk,DatabaseTransactions 不执行回滚 [英] Laravel Dusk, DatabaseTransactions not doing the RollBack

查看:49
本文介绍了Laravel Dusk,DatabaseTransactions 不执行回滚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Laravel Dusk,下面的注册测试工作正常,只是它不回滚事务(即在注册"上创建的用户记录始终保留在数据库中).我的表都设置为使用 InnoDB 引擎.

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.

对正在发生的事情有任何想法吗?我已经把 Logs 放在了很多地方,看起来没有什么特别的错误.我也没有在 laravel.log 文件中收到任何错误.

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');
    });

}

这是我在 config/database.php 中的连接

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',
    ],

更新

我尝试在断言后更新模型,但它也不起作用.似乎所有的数据库事务一般都没有被执行.

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.

推荐答案

您不能在 Dusk 测试中使用 DatabaseTransactions.由于真正的浏览器正在打开您的网站,因此您的测试会在不同的进程中运行.

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.

这篇关于Laravel Dusk,DatabaseTransactions 不执行回滚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆