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'); } }