27-05-2026 DHL Modul v2.1 / Optimierung tracking
This commit is contained in:
parent
036595be94
commit
2bdc9ada3c
33 changed files with 2367 additions and 2086 deletions
50
tests/Unit/Dhl/ShippingServiceParseAddressTest.php
Normal file
50
tests/Unit/Dhl/ShippingServiceParseAddressTest.php
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
use Acme\Dhl\Services\ShippingService;
|
||||
use Acme\Dhl\Support\DhlClient;
|
||||
|
||||
function invokeParseAddressFields(array $address): array
|
||||
{
|
||||
$service = new ShippingService(new DhlClient('https://example.test', null, null, null));
|
||||
|
||||
$reflection = (new ReflectionClass(ShippingService::class))->getMethod('parseAddressFields');
|
||||
$reflection->setAccessible(true);
|
||||
|
||||
return $reflection->invoke($service, $address);
|
||||
}
|
||||
|
||||
it('keeps an explicit house number unchanged', function () {
|
||||
$address = invokeParseAddressFields([
|
||||
'street' => 'Musterstrasse',
|
||||
'houseNumber' => '42a',
|
||||
]);
|
||||
|
||||
expect($address['street'])->toBe('Musterstrasse')
|
||||
->and($address['houseNumber'])->toBe('42a');
|
||||
});
|
||||
|
||||
it('extracts the house number from a combined street field', function () {
|
||||
$address = invokeParseAddressFields([
|
||||
'street' => 'Musterstrasse 42a',
|
||||
'houseNumber' => '',
|
||||
]);
|
||||
|
||||
expect($address['street'])->toBe('Musterstrasse')
|
||||
->and($address['houseNumber'])->toBe('42a');
|
||||
});
|
||||
|
||||
it('throws when the street contains no parseable house number instead of defaulting to 1', function () {
|
||||
invokeParseAddressFields([
|
||||
'street' => 'Postfach',
|
||||
'houseNumber' => '',
|
||||
]);
|
||||
})->throws(InvalidArgumentException::class, 'Hausnummer fehlt');
|
||||
|
||||
it('does not throw when neither street nor house number are provided', function () {
|
||||
$address = invokeParseAddressFields([
|
||||
'street' => '',
|
||||
'houseNumber' => '',
|
||||
]);
|
||||
|
||||
expect($address)->toBe(['street' => '', 'houseNumber' => '']);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue