Jir*_*ren 3 php teardown laravel laravel-dusk
public function tearDown()
{
$this->browse(function (Browser $browser) {
$browser->click('#navbarDropdown')
->click('.dropdown-item');
});
parent::tearDown();
}
Run Code Online (Sandbox Code Playgroud)
当我将 tearDown() 方法应用于我的测试类时,我收到一条错误消息,告诉我the tearDown() must be compatible with Illuminate\Foundation\Testing\TestCase::tearDown()我做错了什么?
每次我运行测试时,我都需要登录。我想在 setUp() 方法中登录并在 tearDown 中再次注销,以便我可以独立执行我的测试。
这是我的 setUp() 方法
use databaseMigrations;
public function setUp(): void
{
parent::setUp();
$this->seed('DatabaseSeeder');
$this->browse(function (Browser $browser) {
$browser->visit('/admin')
->type('email', 'admin@admin.com')
->type('password', 'admin')
->press('Login');
});
}
Run Code Online (Sandbox Code Playgroud)
setUp() 方法工作得很好。即使我没有在 tearDown() 方法中添加任何代码,除了parent::tearDown();,我也会收到一个错误,那么我在我的 tearDown() 方法中做错了什么?
public function tearDown()
{
parent::tearDown();
}
Run Code Online (Sandbox Code Playgroud)
你缺少: void的tearDown():
public function tearDown(): void
{
parent::tearDown();
}
Run Code Online (Sandbox Code Playgroud)
你有setUp()正确的,但作为父类的方法,这两种方法都需要兼容并省略: void不是。
每当您看到该错误时,最好检查您正在扩展的类的来源。通过继承,也就是
Illuminate\Foundation\Testing\TestCase.php
/**
* Setup the test environment.
*
* @return void
*/
protected function setUp(): void
{
...
}
...
/**
* Clean up the testing environment before the next test.
*
* @return void
*/
protected function tearDown(): void
{
...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
550 次 |
| 最近记录: |