Laravel Controller Tests

Write focused controller tests using HTTP assertions; keep heavy logic in Actions/Services and unit test them

noartem cf99c29 558 B Updated

File contents

Controller Tests

Feature tests for endpoints

it('rejects empty email', function () {
  $this->post('/register', ['email' => ''])->assertSessionHasErrors('email');
});

Better tests

  • Move validation to Form Requests; assert errors from the request class
  • Extract business logic into Actions; unit test them directly
  • Use factories for realistic data; avoid heavy mocking

noartem/laravel-vue-skills/tree/main/skills/laravel-controller-tests commit cf99c292ce

Frequently asked questions

npx skillmds@latest add noartem/laravel-controller-tests