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');
}
Route::apiResource('order', 'OrderController');api.php I added the line Route::get('order/store', 'OrderController@store'); but I got the error InvalidArgumentException: Action App\Http\Controllers\App\Http\Controllers\OrderController@store not defined.order/store. The error you got has to do with namespaces. Instead of action('App\Http\Controllers\OrderController@store') you could try just action('OrderController@store'), but you could just put the endpoint directly in the test. I just edited it.
$this->userand where is it defined? Please add this code to your question.