Answer the question
In order to leave comments, you need to log in
How to check the value by condition in the response when testing api?
I created a test that checks if the record is created in the database. The answer comes back.
{
"status": "OK",
"message": "Запись с таким id обнаружена",
"data": {
"work": {
"id": 14,
"equipment_id": 64,
"time_start": "08:00",
"time_end": "19:59",
"comment": "08 -> 20",
"equipment": {
"id": 64,
"title": "Car1",
}
}
}
}
$this->json('GET', '/api/works/show/1')
->assertJson([
'status' => 'OK',
]);
Answer the question
In order to leave comments, you need to log in
They always tell me that I would read the documentation, well, I read it and found such a solution.
But maybe there are other ways, I would not mind, thanks.
$response = $this->get('/api/works/show/1');
$response
->assertJson(fn (AssertableJson $json) =>
$json->has('status')
->has('message')
->has('data.work', fn ($json) =>
$json->where('time_end', '19:59')
->etc()
)
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question