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
48
tests/Unit/Dhl/ReturnsServiceCountryCodeTest.php
Normal file
48
tests/Unit/Dhl/ReturnsServiceCountryCodeTest.php
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
use Acme\Dhl\Services\ReturnsService;
|
||||
use Acme\Dhl\Support\DhlClient;
|
||||
|
||||
function invokeReturnsServiceConvert(string $method, $argument)
|
||||
{
|
||||
$service = new ReturnsService(new DhlClient('https://example.test', null, null, null));
|
||||
|
||||
$reflection = (new ReflectionClass(ReturnsService::class))->getMethod($method);
|
||||
$reflection->setAccessible(true);
|
||||
|
||||
return $reflection->invoke($service, $argument);
|
||||
}
|
||||
|
||||
it('converts known ISO-2 country codes to DHL ISO-3 via the resolver', function (string $input, string $expected) {
|
||||
expect(invokeReturnsServiceConvert('convertCountryCode', $input))->toBe($expected);
|
||||
})->with([
|
||||
'germany' => ['DE', 'DEU'],
|
||||
'austria' => ['AT', 'AUT'],
|
||||
'switzerland' => ['CH', 'CHE'],
|
||||
'spain' => ['ES', 'ESP'],
|
||||
'germany lowercase' => ['de', 'DEU'],
|
||||
'germany already iso-3' => ['DEU', 'DEU'],
|
||||
]);
|
||||
|
||||
it('throws on unsupported country codes instead of silently using DEU', function () {
|
||||
invokeReturnsServiceConvert('convertCountryCode', 'XX');
|
||||
})->throws(InvalidArgumentException::class);
|
||||
|
||||
it('normalizes addresses back to ISO-2 via the resolver', function () {
|
||||
$converted = invokeReturnsServiceConvert('convertAddressFor2LetterCountry', [
|
||||
'name' => 'Test',
|
||||
'country' => 'AUT',
|
||||
]);
|
||||
|
||||
expect($converted['country'])->toBe('AT');
|
||||
});
|
||||
|
||||
it('throws when normalizing an address with an unsupported country', function () {
|
||||
invokeReturnsServiceConvert('convertAddressFor2LetterCountry', ['country' => 'ZZ']);
|
||||
})->throws(InvalidArgumentException::class);
|
||||
|
||||
it('keeps the address unchanged when the country key is missing', function () {
|
||||
$converted = invokeReturnsServiceConvert('convertAddressFor2LetterCountry', ['name' => 'Test']);
|
||||
|
||||
expect($converted)->toBe(['name' => 'Test']);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue