48 lines
1.7 KiB
PHP
48 lines
1.7 KiB
PHP
<?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']);
|
|
});
|