Answer the question
In order to leave comments, you need to log in
How to test api correctly?
There is an api for posts. Implemented resource controller (CRUD)
How to properly test this controller?
Well, for example, in my index method
$data = Post::all();
return PostResource::collection($data);
Answer the question
In order to leave comments, you need to log in
In this case, I usually use a test sqlite in memory database, adding to phpunit.xml:
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
$task = factory(\App\Task::class)->create([
'archive' => false
]);
$response->assertStatus(200)
->assertJson([$task->toArray()]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question