| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- namespace Tests\Unit\Models;
- use App\Models\StudentResponsible;
- use Illuminate\Validation\ValidationException;
- use Tests\TestCase;
- class StudentResponsibleTest extends TestCase
- {
- public function test_it_rejects_a_minor_when_saving_the_model(): void
- {
- $responsible = new TestableStudentResponsible;
- $responsible->birth_date = now()->subYears(17)->toDateString();
- $this->expectException(ValidationException::class);
- $this->expectExceptionMessage(__('validation.responsible_must_be_adult'));
- $responsible->fireSavingEvent();
- }
- public function test_it_allows_an_adult_when_saving_the_model(): void
- {
- $responsible = new TestableStudentResponsible;
- $responsible->birth_date = now()->subYears(18)->toDateString();
- $responsible->fireSavingEvent();
- $this->assertSame(18, $responsible->birth_date->age);
- }
- }
- class TestableStudentResponsible extends StudentResponsible
- {
- public function fireSavingEvent(): mixed
- {
- return $this->fireModelEvent('saving');
- }
- }
|