如何在Laravel集成测试中等待页面重新加载

Ale*_*lex 6 php testing laravel

我们有一个操作来编辑重定向到同一页面的用户配置文件.这里seePageIs()似乎不等待加载新页面.

以下测试失败,因为在响应中找不到新用户名.当我们在测试后手动加载配置文件页面时,它已正确更新.

public function testCanEditUserProfileAsConsumer()
{
    $this->loginConsumer();

    $this->visit('/user/profile');
    $firstName = $this->faker->firstname;
    $name = $this->faker->name;


    $this->within('#userEditForm', function() use ($firstName, $name) {
        $this->type($firstName, 'firstname');
        $this->type($name, 'surname');
        $this->press('Speichern');
    });

    // here: how to wait for page reload ?
    $this->seePageIs('/user/profile');
    $this->see($firstName);
    $this->see($name);
}
Run Code Online (Sandbox Code Playgroud)

编辑

    $this->within('#userEditForm', function() use ($firstName, $lastname) {
        $this->type($firstName, 'firstname');
        $this->type($lastname, 'surname');
        $this->press('Speichern')
            ->seePageIs('/user/profile')
            ->see($firstName)
            ->see($lastname);
    });
Run Code Online (Sandbox Code Playgroud)

也不行

Ale*_*lex 0

问题是另一回事。按下按钮时Laravel正在重新加载页面。

在用户个人资料的视图中,我们用来Auth::user()显示信息。

当我做一个

    Auth::setUser(Auth::user()->fresh());
Run Code Online (Sandbox Code Playgroud)

在用户控制器中,它可以工作。

这不是一个非常令人满意的解决方案 - 但它使最初的问题变得清晰。