toBeInstanceOf(Employee::class) ->and($employee)->toBeInstanceOf(Dto::class) ->and($employee->matriculePublique)->toBeInstanceOf(ArcadiaEmployeeId::class) ->and($employee->matriculePublique->value)->toBe('1234567') ->and($employee->lastname)->toBe('Dupont') ->and($employee->firstname)->toBe('Jean') ->and($employee->start_date)->toBe($startDate) ->and($employee->end_date)->toBe($endDate) ->and($employee->planned_end_date)->toBe($plannedEndDate) ->and($employee->establishment)->toBeInstanceOf(EstablishmentCode::class) ->and($employee->establishment->value)->toBe('EST01') ->and($employee->site)->toBeInstanceOf(SiteId::class) ->and($employee->site->value)->toBe('LDCSER') ->and($employee->service)->toBeInstanceOf(ServiceId::class) ->and($employee->service->value)->toBe('097') ->and($employee->created_at)->toBe($createdAt) ->and($employee->updated_at)->toBe($updatedAt); }); it('can jsonSerialize complete Employee object graph', function (): void { // GIVEN $employee = createCompleteEmployee(); // WHEN $serialized = $employee->jsonSerialize(); // THEN expect($serialized)->toBe([ 'matriculePublique' => '1234567', 'lastname' => 'Dupont', 'firstname' => 'Jean', 'start_date' => '2023-01-15T08:00:00+00:00', 'end_date' => '2025-12-31T18:00:00+00:00', 'planned_end_date' => '2025-06-30T17:00:00+00:00', 'establishment' => 'EST01', 'site' => 'LDCSER', 'service' => '097', 'created_at' => '2023-01-01T00:00:00+00:00', 'updated_at' => '2024-01-01T10:00:00+00:00', ]); $jsonEncoded = json_encode($employee); expect($jsonEncoded)->toBeString(); expect(json_decode((string) $jsonEncoded, true))->toBe($serialized); }); it('can instantiate Employee with nullable fields set to null', function (): void { // GIVEN $startDate = new DateTimeImmutable('2023-06-01T09:00:00+00:00'); $createdAt = new DateTimeImmutable('2023-06-01T09:00:00+00:00'); // WHEN $employee = new Employee( matriculePublique: new ArcadiaEmployeeId('9876543'), lastname: 'Martin', firstname: 'Claire', start_date: $startDate, end_date: null, planned_end_date: null, establishment: new EstablishmentCode('EST02'), site: new SiteId('SLELA'), service: new ServiceId('098'), created_at: $createdAt, updated_at: null, ); // THEN expect($employee->end_date)->toBeNull() ->and($employee->planned_end_date)->toBeNull() ->and($employee->updated_at)->toBeNull(); $serialized = $employee->jsonSerialize(); expect($serialized)->toBe([ 'matriculePublique' => '9876543', 'lastname' => 'Martin', 'firstname' => 'Claire', 'start_date' => '2023-06-01T09:00:00+00:00', 'end_date' => null, 'planned_end_date' => null, 'establishment' => 'EST02', 'site' => 'SLELA', 'service' => '098', 'created_at' => '2023-06-01T09:00:00+00:00', 'updated_at' => null, ]); }); });