测试工匠司令部Laravel 9
我正在尝试在Laravel 9中编写一个测试命令。在以下代码中,新用户将成功创建,但是在创建仪表板页面之后,如何
public function test_an_action_that_requires_authentication()
{
$user = $this->artisan('make:user',[
'name' => "username",
'email' => "useremail",
'password' => Str::random(8)
]);
}
在成功创建成功之后如何重定向到路线
I'm trying to write a test command in Laravel 9. In the below code the new user will create successfully But after creating need to redirect the Dashboard page
public function test_an_action_that_requires_authentication()
{
$user = $this->artisan('make:user',[
'name' => "username",
'email' => "useremail",
'password' => Str::random(8)
]);
}
How to redirect to the route after success created
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们将使用
assertexitCode
方法来断言命令是用给定的退出代码完成的。有关更多信息,您可以在此处找到
https://lararavel.com/docs/9.x /控制台检验
We will use the
assertExitCode
method to assert that the command completed with a given exit code.for more information you can find here
https://laravel.com/docs/9.x/console-tests
NB此代码在测试中不起作用。您无法重定向工匠司令部。
说,在Laravel中,要重定向到主页,您可以在控制器函数中使用此代码:
N.B. This code does not work in test. You can not redirect in an artisan command.
Said that, in laravel, to redirect to the home page, you can use this code in a controller function: