AuthenticationTest.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace Tests\Feature\Auth;
  3. use App\Models\User;
  4. use Illuminate\Foundation\Testing\RefreshDatabase;
  5. use Tests\TestCase;
  6. class AuthenticationTest extends TestCase
  7. {
  8. use RefreshDatabase;
  9. public function test_users_can_authenticate_using_the_login_screen(): void
  10. {
  11. $user = User::factory()->create();
  12. $response = $this->post('/login', [
  13. 'email' => $user->email,
  14. 'password' => 'password',
  15. ]);
  16. $this->assertAuthenticated();
  17. $response->assertNoContent();
  18. }
  19. public function test_users_can_not_authenticate_with_invalid_password(): void
  20. {
  21. $user = User::factory()->create();
  22. $this->post('/login', [
  23. 'email' => $user->email,
  24. 'password' => 'wrong-password',
  25. ]);
  26. $this->assertGuest();
  27. }
  28. public function test_users_can_logout(): void
  29. {
  30. $user = User::factory()->create();
  31. $response = $this->actingAs($user)->post('/logout');
  32. $this->assertGuest();
  33. $response->assertNoContent();
  34. }
  35. }