问题描述
我正在 laravel 中运行测试。但它是失败的测试。我没有得到原因可能是因为中间件,但不确定。
这里是测试功能
public function test_example()
{
$staff = factory(Staff::class)->create();
$response = $this->actingAs($staff)
->withSession(['foo' => 'bar'])
->get('/products');
$response->assertStatus(200);
}
}
这是输出
PHPUnit\TextUI\Command::main()
Tests: 1 Failed,2 passed
Time: 0.98s
PS C:\projects\coldxlogistics> PHP artisan test
Warning: TTY mode is not supported on Windows platform.
PASS Tests\Feature\DashboardTest
✓ dashboard loads fine
✓ user cannot see dashboard without login
FAIL Tests\Feature\ProductTest
⨯ example
---
• Tests\Feature\ProductTest > example
Expected status code 200 but received 302.
Failed asserting that 200 is identical to 302.
at C:\projects\coldxlogistics\tests\Feature\ProductTest.PHP:24
20▕ $response = $this->actingAs($staff)
21▕ ->withSession(['foo' => 'bar'])
22▕ ->get('/products');
23▕
➜ 24▕ $response->assertStatus(200);
25▕ }
26▕ }
27▕
1 C:\projects\coldxlogistics\vendor\PHPunit\PHPunit\PHPunit:61
PHPUnit\TextUI\Command::main()
Tests: 1 Failed,2 passed
Time: 1.00s
有多个中间件在处理路由。例如
auth,login_auth,two_factor_auth
withSession() 的目的是什么?如何使用它?我看到了文档,但无法理解什么是 foo,bar
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)