getProperty('cachedDhlConfig'); $property->setAccessible(true); $property->setValue(null, [ 'api_key' => 'cached-test-api-key-1234', ]); }); afterEach(function () { SettingController::flushDhlConfigCache(); DhlTrackingService::clearQuotaPause(); }); it('retries a transient server error and returns the successful response', function () { Http::fakeSequence() ->push(['title' => 'Internal Server Error'], 500) ->push(['shipments' => [[ 'id' => '00340434292135100148', 'status' => ['statusCode' => 'delivered', 'description' => 'Zugestellt'], ]]], 200); $result = (new DhlTrackingService)->trackShipment('00340434292135100148'); expect($result)->toHaveKey('success', true) ->and($result['status'])->toBe('delivered'); Http::assertSentCount(2); }); it('gives up after the configured number of attempts and reports the status once', function () { Http::fake([ 'api-eu.dhl.com/track/shipments*' => Http::response(['title' => 'Internal Server Error'], 500), ]); $result = (new DhlTrackingService)->trackShipment('00340434292135100148'); expect($result)->toHaveKey('success', false) ->toHaveKey('http_status', 500); Http::assertSentCount(3); }); it('does not retry a client error', function () { Http::fake([ 'api-eu.dhl.com/track/shipments*' => Http::response(['title' => 'Not Found'], 404), ]); $result = (new DhlTrackingService)->trackShipment('00340434292135100148'); expect($result)->toHaveKey('not_found', true); Http::assertSentCount(1); });