【发布时间】:2018-04-07 09:15:37
【问题描述】:
对于 laravel 测试环境,Laravel gate 不工作。在phpunit.xml
文件,我使用sqlite 连接和:memory: 作为数据库。
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
在AuthServiceProvider 中,我在下面的代码中定义了门。
public function boot(GateContract $gate)
{
$this->registerPolicies($gate);
foreach($this->getPermissions() as $permission) {
$gate->define($permission->name, function($user) {
$user->hasRole($permission->roles);
});
}
}
protected function getPermissions() {
return Permission::with('roles')->get();
}
所以,每当我运行phpunit 时。它显示错误no such table: permissions (SQL: select * from "permissions")。
所以,请指导我如何在迁移后为测试环境定义门。
【问题讨论】: