laravel-dusk - Laravel Dusk 意外的数据库刷新
问题描述
我有什么:
Laravel:5.7.28
PHP:7.2
Homestead:8.0.2
测试类:
class ExampleTest extends DuskTestCase
{
use DatabaseMigrations;
public function testExample()
{
$user = factory(User::class)->create(/**/);
$faker = Factory::create();
$this->browse(function (Browser $browser) use ($user) {
$browser->loginAs($user)
->visit(/**/)
->type(/**/)
->press(/**/)
->assertRouteIs(/**/);
});
}
public function testExample2() //identical to testExample
{
//...
$this->browse(function (Browser $browser) use ($user) {
//...
}); // <-- Base table or view not found: 1146 Table 'testing.users' doesn't exist
}
}
问题:为什么数据库会刷新(?)$this->browse()
?
我在每次测试之前运行了一些种子,但它们与users
表没有直接关系。
abstract class DuskTestCase extends BaseTestCase
{
use CreatesApplication;
protected function setUp(): void
{
parent::setUp();
$this->seed(\RolesSeeder::class);
}
}
trait CreatesApplication
{
public function createApplication()
{
//...
$this->clearCache();
return $app;
}
protected function clearCache()
{
$commands = ['clear-compiled', 'cache:clear', 'view:clear', 'config:clear', 'route:clear'];
foreach ($commands as $command) {
Artisan::call($command);
}
}
}
每个测试类都有一个测试方法,一切正常。
解决方案
推荐阅读
- javascript - 使用 HTML5 Canvas 和 Socket.io 服务器将用户(玩家)定位在移动后始终处于中心位置
- python - 使用无头 chrome webdriver 时出现超时异常错误
- python - 大数据集中的统计微积分错误值
- reactjs - 如何使用 redux 选择器进行单元测试
- apache-nifi - 使用表达式语言从缓存颠簸规范中获取,并且放置属性不计算表达式语言
- python - 为什么 Python 请求会导致 InsecureRequestWarning 但我的浏览器似乎可以使用 HTTPS 进行连接?
- javascript - 将所需的输入模式添加到 if 内部的变量中
- swift - 在for循环中为元组赋值
- python - 如何在 Python Torch 中对两个单位向量进行球面插值?
- javascript - 根据最近的日期对MongoDB中的集合进行排序