| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- <?php
- namespace Tests\Unit\Models;
- use App\Models\Student;
- use Illuminate\Validation\ValidationException;
- use Tests\TestCase;
- class StudentTest extends TestCase
- {
- public function test_it_rejects_a_minor_without_a_responsible_when_creating(): void
- {
- app()->setLocale('pt');
- $student = new TestableStudent;
- $student->birth_date = now()->subYears(10)->toDateString();
- $this->expectException(ValidationException::class);
- $this->expectExceptionMessage('É obrigatório informar um responsável para estudantes menores de idade.');
- $student->fireCreatingEvent();
- }
- public function test_it_allows_a_minor_with_a_responsible_when_creating(): void
- {
- $student = (new TestableStudent)
- ->withResponsibleForCreation(['name' => 'Responsável']);
- $student->birth_date = now()->subYears(10)->toDateString();
- $student->fireCreatingEvent();
- $this->assertTrue($student->isMinor());
- }
- public function test_it_allows_an_adult_without_a_responsible_when_creating(): void
- {
- $student = new TestableStudent;
- $student->birth_date = now()->subYears(18)->toDateString();
- $student->fireCreatingEvent();
- $this->assertFalse($student->isMinor());
- }
- }
- class TestableStudent extends Student
- {
- public function fireCreatingEvent(): mixed
- {
- return $this->fireModelEvent('creating');
- }
- }
|