[英]Unit Testing controller in laravel 8
I am very new to testing in Laravel, I'm working in laravel 8, the function that I want to test is :我对 Laravel 测试很陌生,我在 Laravel 8 中工作,我想测试的功能是:
When I run my test I get this error:当我运行我的测试时,我收到此错误:
ErrorException: Trying to get property 'id' of non-object ErrorException: 试图获取非对象的属性“id”
Thank you for any help!感谢您的任何帮助!
Usually you don't even need to use the Request
class in your tests.通常,您甚至不需要在测试中使用Request
类。
public function testStore()
{
Sanctum::actingAs($this->user, ['*']);
$response = $this->postJson('/order/store', [
'doAssigned' => false,
'doValidate' => false,
]);
$response->assertJsonPath('status', 'draft');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.