59996, 'weight_kg' => 0.5, 'product_code' => 'V01PAK', 'label_format' => 'PDF', 'shipper' => [ 'name' => 'mivita care gmbh', 'street' => 'Leinfeld', 'houseNumber' => '2', 'postalCode' => '87755', 'city' => 'Kirchhaslach', 'country' => 'DE', ], 'consignee' => [ 'name' => 'Max Mustermann', 'street' => 'Hauptstrasse', 'houseNumber' => '5', 'postalCode' => '10115', 'city' => 'Berlin', 'country' => 'DE', ], 'reference' => 'Order-59996', ]; foreach ($overrides as $key => $value) { if ($key === 'consignee') { $data['consignee'] = array_merge($data['consignee'], $value); continue; } $data[$key] = $value; } return $data; } function validateDhlOrderData(array $data): array { $service = makeDhlNormalizationService(); $method = new ReflectionMethod($service, 'validateOrderData'); $method->setAccessible(true); return $method->invoke($service, $data); } it('normalises a phone number that would otherwise exceed the DHL limit', function () { $validated = validateDhlOrderData(normalizeDhlOrderData([ 'consignee' => ['phone' => '+49 (0) 8333 / 94 61 767'], ])); expect($validated['consignee']['phone'])->toBe('+49083339461767') ->and(strlen($validated['consignee']['phone']))->toBeLessThanOrEqual(20); }); it('drops an implausibly short phone number rather than failing the shipment', function () { $validated = validateDhlOrderData(normalizeDhlOrderData([ 'consignee' => ['phone' => '123'], ])); expect($validated['consignee'])->not->toHaveKey('phone'); }); it('drops a phone number that stays too long after normalisation', function () { $validated = validateDhlOrderData(normalizeDhlOrderData([ 'consignee' => ['phone' => '+49 8333 9461767 9461767 9461767'], ])); expect($validated['consignee'])->not->toHaveKey('phone'); }); it('truncates name2 to the DHL limit instead of rejecting the shipment', function () { $validated = validateDhlOrderData(normalizeDhlOrderData([ 'consignee' => ['name2' => str_repeat('Firmenname ', 10)], ])); expect(mb_strlen($validated['consignee']['name2']))->toBe(50); }); it('replaces a reference shorter than the DHL minimum with the order reference', function () { $validated = validateDhlOrderData(normalizeDhlOrderData(['reference' => 'NL'])); expect($validated['reference'])->toBe('Order-59996') ->and(mb_strlen($validated['reference']))->toBeGreaterThanOrEqual(DhlDataHelper::REFERENCE_MIN_LENGTH); }); it('keeps a reference that already satisfies the DHL length rule', function () { $validated = validateDhlOrderData(normalizeDhlOrderData(['reference' => 'Kundenreferenz-4711'])); expect($validated['reference'])->toBe('Kundenreferenz-4711'); });