简体   繁体   中英

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 :

When I run my test I get this error:

ErrorException: Trying to get property 'id' of non-object

Thank you for any help!

Usually you don't even need to use the Request class in your tests.

public function testStore()
{
    Sanctum::actingAs($this->user, ['*']);

    $response = $this->postJson('/order/store', [
        'doAssigned' => false,
        'doValidate' => false,
    ]);

    $response->assertJsonPath('status', 'draft');
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM