我有什么:
PHP:7.2版
宅基地: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);
}
}
}
当每个测试类都有一个测试方法时,一切都正常。