Log-Analyse 26.08. (P0-2, P1-5, P2-3): - Produktcode fuer DHL Paket International ist V53WPAK; mit V53PAK wurde kein einziges Auslandslabel erzeugt. Alte Codes werden gemappt (LEGACY_PRODUCT_CODE_ALIASES), Abrechnungsnummer und Masse suchen auch unter den alten Setting-Schluesseln (dhl_account_v53pak) und Env-Namen. - Zu lange Felder (Name, Stadt, Telefon, Referenz) werden auf die DHL-Grenzen gekuerzt bzw. bereinigt statt den Versand abzulehnen; refNo mindestens 8 Zeichen, sonst die Bestellreferenz. - Tracking wiederholt bei HTTP 5xx der Unified-API bis zu dreimal. Zolldaten fuer die Schweiz (P0-3) sind nicht Teil dieses Commits. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
104 lines
3.3 KiB
PHP
104 lines
3.3 KiB
PHP
<?php
|
|
|
|
use Acme\Dhl\Services\ShippingService;
|
|
use Acme\Dhl\Support\DhlClient;
|
|
use App\Services\DhlDataHelper;
|
|
|
|
function makeDhlNormalizationService(): ShippingService
|
|
{
|
|
return new ShippingService(new DhlClient('https://api-sandbox.dhl.com', null, null, null));
|
|
}
|
|
|
|
function normalizeDhlOrderData(array $overrides = []): array
|
|
{
|
|
$data = [
|
|
'order_id' => 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');
|
|
});
|