Tips
20 листопада 2026
HTTP-тести - перевірка ендпоінтів без Postman
Laravel може симулювати HTTP-запити у тестах.
Методи: get, post, put, patch, delete.
Порада: assertJsonStructure() перевіряє форму відповіді.
public function test_user_can_view_posts()
{
$response = $this->get('/api/posts');
$response->assertStatus(200)
->assertJsonStructure([
'data' => [
'*' => ['id', 'title', 'body'],
],
]);
}
public function test_post_requires_title()
{
$response = $this->post('/api/posts', ['body' => '...']);
$response->assertStatus(422)
->assertJsonValidationErrors(['title']);
}