| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace Tests\Unit\Models;
- use App\Models\Student;
- use App\ValueObjects\Cpf;
- 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());
- }
- public function test_it_casts_the_student_document_number_to_cpf(): void
- {
- $student = new Student;
- $student->document_number = '529.982.247-25';
- $this->assertInstanceOf(Cpf::class, $student->document_number);
- $this->assertSame('52998224725', $student->document_number->value());
- }
- }
- class TestableStudent extends Student
- {
- public function fireCreatingEvent(): mixed
- {
- return $this->fireModelEvent('creating');
- }
- }
|