StudentResponsibleTest.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace Tests\Unit\Models;
  3. use App\Models\StudentResponsible;
  4. use Illuminate\Validation\ValidationException;
  5. use Tests\TestCase;
  6. class StudentResponsibleTest extends TestCase
  7. {
  8. public function test_it_rejects_a_minor_when_saving_the_model(): void
  9. {
  10. $responsible = new TestableStudentResponsible;
  11. $responsible->birth_date = now()->subYears(17)->toDateString();
  12. $this->expectException(ValidationException::class);
  13. $this->expectExceptionMessage(__('validation.responsible_must_be_adult'));
  14. $responsible->fireSavingEvent();
  15. }
  16. public function test_it_allows_an_adult_when_saving_the_model(): void
  17. {
  18. $responsible = new TestableStudentResponsible;
  19. $responsible->birth_date = now()->subYears(18)->toDateString();
  20. $responsible->fireSavingEvent();
  21. $this->assertSame(18, $responsible->birth_date->age);
  22. }
  23. }
  24. class TestableStudentResponsible extends StudentResponsible
  25. {
  26. public function fireSavingEvent(): mixed
  27. {
  28. return $this->fireModelEvent('saving');
  29. }
  30. }