如何在 Laravel 中使用 Codeception 设置用于测试的数据库对象


How to setup DB object for Testing using Codeception in Laravel

我想在Laravel内部运行的一组Codeception测试中使用DB对象。具体来说,我想这样做作为测试_before的一部分:

DB::table('name')->truncate();

在我的TestCest.php文件的开头,我有这个:

use 'AcceptanceTester;
namespace App'Modules'Admin'Controllers;
use DB;

但是,数据库对象不允许我使用它 - 我收到一条消息

登录失败

当我运行编码测试时。

确定我缺少有关设置数据库对象的基本内容,但我无法弄清楚。

这就是我解决它的方式。

在测试/_bootstrap.php中,我放置了以下代码

// This is global bootstrap for autoloading
require __DIR__.'/../../bootstrap/autoload.php';
require __DIR__.'/../../bootstrap/start.php';