我如何在 laravel phpUnit 测试的另一个测试用例中登录用户?

Har*_*tel 2 phpunit laravel laravel-testing

图1

当我检查方法 in dd(\Auth()::check());case时,它​​会返回,但是当我使用in方法 in时,它会返回。testLoginTrueLoginTesttruedd(\Auth()::check());testClientCreateFormDisplayedClientTestfalse

图2

那么如何在另一个测试用例中获取登录用户呢?在每个测试用例之前都需要登录用户吗?

Ben*_*ing 5

它在他们的文档中https://laravel.com/docs/9.x/http-tests#session-and-authentication

->actingAs($user)所以只需在 a 之前添加get/post

如果您在创建用户后需要该用户(或只是一般情况下) - 您始终可以在测试中从数据库中获取它