refactor: split buspro ApiClient into domain clients

This commit is contained in:
fromme committed 2026-10-02 13:55:30 +02:00
1 parent 0a55544ca8
commit b755a6f43e
52 files changed
+805 -695

No files matched your search

@@ -4,7 +4,7 @@ declare(strict_types=1);
namespace App\Tests\Service;
use App\BusProNet\ApiClient;
use App\BusProNet\Client\BookingClient;
use App\BusProNet\DataProcessor\BookingDataProcessor;
use App\BusProNet\Model\BaseData;
use App\BusProNet\Model\Booking;
@@ -111,7 +111,7 @@ class BookingEditDataLoaderDraftRestoreTest extends TestCase
$crypt->method('decrypt')->willReturn('secret');
return new BookingEditDataLoader(
$this->createStub(ApiClient::class),
$this->createStub(BookingClient::class),
$bookingDataProcessor,
$this->createStub(BookingSessionManager::class),
new BookingChangeTracker(),
+21 -20
View File
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Tests\Service;
use App\BusProNet\Client\BookingClient;
use App\BusProNet\Exception\ApiClientException;
use App\BusProNet\Exception\TimeoutException;
use App\BusProNet\Model\Booking;
@@ -87,14 +88,14 @@ class BookingEditSubmitterTest extends TestCase
->with($bookingDto, $freshBookingData)
->willReturn(false);
$apiClient = $this->createMock(\App\BusProNet\ApiClient::class);
$apiClient->expects($this->once())
$bookingClient = $this->createMock(BookingClient::class);
$bookingClient->expects($this->once())
->method('updateBooking')
->with($bookingDto, true)
->willThrowException($exception);
$service = $this->createService(
apiClient: $apiClient,
bookingClient: $bookingClient,
dataLoader: $dataLoader,
travelDataService: $travelDataService,
submitGuard: $submitGuard,
@@ -137,17 +138,17 @@ class BookingEditSubmitterTest extends TestCase
->with($bookingDto, $freshBookingData)
->willReturn(false);
$apiClient = $this->createMock(\App\BusProNet\ApiClient::class);
$bookingClient = $this->createMock(BookingClient::class);
$bookingUpdate = new BookingUpdate();
$bookingUpdate->success = false;
$bookingUpdate->status = 'BPN-FAIL';
$apiClient->expects($this->once())
$bookingClient->expects($this->once())
->method('updateBooking')
->with($bookingDto, true)
->willReturn($bookingUpdate);
$service = $this->createService(
apiClient: $apiClient,
bookingClient: $bookingClient,
dataLoader: $dataLoader,
travelDataService: $travelDataService,
submitGuard: $submitGuard,
@@ -200,10 +201,10 @@ class BookingEditSubmitterTest extends TestCase
->with($bookingDto, $freshBookingData)
->willReturn(false);
$apiClient = $this->createMock(\App\BusProNet\ApiClient::class);
$bookingClient = $this->createMock(BookingClient::class);
$bookingUpdate = new BookingUpdate();
$bookingUpdate->success = true;
$apiClient->expects($this->once())
$bookingClient->expects($this->once())
->method('updateBooking')
->with($bookingDto, true)
->willReturn($bookingUpdate);
@@ -221,7 +222,7 @@ class BookingEditSubmitterTest extends TestCase
->with($user, 42);
$service = $this->createService(
apiClient: $apiClient,
bookingClient: $bookingClient,
dataLoader: $dataLoader,
draftService: $draftService,
travelDataService: $travelDataService,
@@ -267,10 +268,10 @@ class BookingEditSubmitterTest extends TestCase
->with($bookingDto, $freshBookingData)
->willReturn(true);
$apiClient = $this->createMock(\App\BusProNet\ApiClient::class);
$bookingClient = $this->createMock(BookingClient::class);
$bookingUpdate = new BookingUpdate();
$bookingUpdate->success = true;
$apiClient->expects($this->once())
$bookingClient->expects($this->once())
->method('updateBooking')
->with($bookingDto, true)
->willReturn($bookingUpdate);
@@ -289,7 +290,7 @@ class BookingEditSubmitterTest extends TestCase
->with($user, 42);
$service = $this->createService(
apiClient: $apiClient,
bookingClient: $bookingClient,
dataLoader: $dataLoader,
draftService: $draftService,
travelDataService: $travelDataService,
@@ -352,14 +353,14 @@ class BookingEditSubmitterTest extends TestCase
->with($bookingDto, $freshBookingData)
->willReturn(false);
$apiClient = $this->createMock(\App\BusProNet\ApiClient::class);
$apiClient->expects($this->once())
$bookingClient = $this->createMock(BookingClient::class);
$bookingClient->expects($this->once())
->method('updateBooking')
->with($bookingDto, true)
->willReturn($notification);
$service = $this->createService(
apiClient: $apiClient,
bookingClient: $bookingClient,
dataLoader: $dataLoader,
travelDataService: $travelDataService,
submitGuard: $submitGuard,
@@ -407,14 +408,14 @@ class BookingEditSubmitterTest extends TestCase
->with($bookingDto, $freshBookingData)
->willReturn(false);
$apiClient = $this->createMock(\App\BusProNet\ApiClient::class);
$apiClient->expects($this->once())
$bookingClient = $this->createMock(BookingClient::class);
$bookingClient->expects($this->once())
->method('updateBooking')
->with($bookingDto, true)
->willThrowException($exception);
$service = $this->createService(
apiClient: $apiClient,
bookingClient: $bookingClient,
dataLoader: $dataLoader,
travelDataService: $travelDataService,
submitGuard: $submitGuard,
@@ -428,7 +429,7 @@ class BookingEditSubmitterTest extends TestCase
}
private function createService(
?\App\BusProNet\ApiClient $apiClient = null,
?BookingClient $bookingClient = null,
?BookingEditDataLoader $dataLoader = null,
?BookingEditDraftManager $draftService = null,
?TravelDataProvider $travelDataService = null,
@@ -436,7 +437,7 @@ class BookingEditSubmitterTest extends TestCase
?BookingSessionManager $bookingSessionService = null,
): BookingEditSubmitter {
return new BookingEditSubmitter(
$apiClient ?? $this->createStub(\App\BusProNet\ApiClient::class),
$bookingClient ?? $this->createStub(BookingClient::class),
$dataLoader ?? $this->createStub(BookingEditDataLoader::class),
$draftService ?? $this->createStub(BookingEditDraftManager::class),
$travelDataService ?? $this->createStub(TravelDataProvider::class),
+16 -16
View File
@@ -4,7 +4,7 @@ declare(strict_types=1);
namespace App\Tests\Service;
use App\BusProNet\ApiClient;
use App\BusProNet\Client\AccountClient;
use App\BusProNet\Model\Address;
use App\BusProNet\Model\Communication;
use App\BusProNet\Model\Notification;
@@ -20,14 +20,14 @@ use Psr\Log\LoggerInterface;
class ParticipantDataPrefillerTest extends TestCase
{
private ApiClient $apiClient;
private AccountClient $accountClient;
private Crypt $crypt;
private LoggerInterface $logger;
private ?ParticipantDataPrefiller $service = null;
protected function setUp(): void
{
$this->apiClient = $this->createStub(ApiClient::class);
$this->accountClient = $this->createStub(AccountClient::class);
$this->crypt = $this->createStub(Crypt::class);
$this->logger = $this->createStub(LoggerInterface::class);
}
@@ -35,7 +35,7 @@ class ParticipantDataPrefillerTest extends TestCase
private function service(): ParticipantDataPrefiller
{
return $this->service ??= new ParticipantDataPrefiller(
$this->apiClient,
$this->accountClient,
$this->crypt,
$this->logger
);
@@ -43,7 +43,7 @@ class ParticipantDataPrefillerTest extends TestCase
public function testPrepopulateApplicantWithCompletePersonalData(): void
{
$this->apiClient = $this->createMock(ApiClient::class);
$this->accountClient = $this->createMock(AccountClient::class);
$this->crypt = $this->createMock(Crypt::class);
$user = $this->createUser('[email protected]', 'encrypted_password');
@@ -57,7 +57,7 @@ class ParticipantDataPrefillerTest extends TestCase
->with('encrypted_password')
->willReturn('decrypted_password');
$this->apiClient->expects($this->once())
$this->accountClient->expects($this->once())
->method('getPersonalData')
->with('[email protected]', 'decrypted_password')
->willReturn($personalData);
@@ -94,7 +94,7 @@ class ParticipantDataPrefillerTest extends TestCase
public function testPrepopulateApplicantWithPartialPersonalData(): void
{
$this->apiClient = $this->createMock(ApiClient::class);
$this->accountClient = $this->createMock(AccountClient::class);
$this->crypt = $this->createMock(Crypt::class);
$user = $this->createUser('[email protected]', 'encrypted_password');
@@ -107,7 +107,7 @@ class ParticipantDataPrefillerTest extends TestCase
->method('decrypt')
->willReturn('decrypted_password');
$this->apiClient->expects($this->once())
$this->accountClient->expects($this->once())
->method('getPersonalData')
->willReturn($personalData);
@@ -132,7 +132,7 @@ class ParticipantDataPrefillerTest extends TestCase
public function testPrepopulateApplicantWithApiNotificationError(): void
{
$this->apiClient = $this->createMock(ApiClient::class);
$this->accountClient = $this->createMock(AccountClient::class);
$this->crypt = $this->createMock(Crypt::class);
$this->logger = $this->createMock(LoggerInterface::class);
@@ -146,7 +146,7 @@ class ParticipantDataPrefillerTest extends TestCase
->method('decrypt')
->willReturn('decrypted_password');
$this->apiClient->expects($this->once())
$this->accountClient->expects($this->once())
->method('getPersonalData')
->willReturn($notification);
@@ -171,7 +171,7 @@ class ParticipantDataPrefillerTest extends TestCase
public function testPrepopulateApplicantWithDecryptionException(): void
{
$this->apiClient = $this->createMock(ApiClient::class);
$this->accountClient = $this->createMock(AccountClient::class);
$this->crypt = $this->createMock(Crypt::class);
$this->logger = $this->createMock(LoggerInterface::class);
@@ -183,7 +183,7 @@ class ParticipantDataPrefillerTest extends TestCase
->method('decrypt')
->willThrowException(new \RuntimeException('Decryption failed'));
$this->apiClient->expects($this->never())
$this->accountClient->expects($this->never())
->method('getPersonalData');
$this->logger->expects($this->once())
@@ -203,7 +203,7 @@ class ParticipantDataPrefillerTest extends TestCase
public function testPrepopulateApplicantWithApiException(): void
{
$this->apiClient = $this->createMock(ApiClient::class);
$this->accountClient = $this->createMock(AccountClient::class);
$this->crypt = $this->createMock(Crypt::class);
$this->logger = $this->createMock(LoggerInterface::class);
@@ -215,7 +215,7 @@ class ParticipantDataPrefillerTest extends TestCase
->method('decrypt')
->willReturn('decrypted_password');
$this->apiClient->expects($this->once())
$this->accountClient->expects($this->once())
->method('getPersonalData')
->willThrowException(new \RuntimeException('API connection failed'));
@@ -236,7 +236,7 @@ class ParticipantDataPrefillerTest extends TestCase
public function testPrepopulatePreservesBookingSpecificFields(): void
{
$this->apiClient = $this->createMock(ApiClient::class);
$this->accountClient = $this->createMock(AccountClient::class);
$this->crypt = $this->createMock(Crypt::class);
$user = $this->createUser('[email protected]', 'encrypted_password');
@@ -251,7 +251,7 @@ class ParticipantDataPrefillerTest extends TestCase
->method('decrypt')
->willReturn('decrypted_password');
$this->apiClient->expects($this->once())
$this->accountClient->expects($this->once())
->method('getPersonalData')
->willReturn($personalData);
+9 -9
View File
@@ -4,7 +4,7 @@ declare(strict_types=1);
namespace App\Tests\Service;
use App\BusProNet\ApiClient;
use App\BusProNet\Client\TravelClient;
use App\BusProNet\Model\Travel;
use App\BusProNet\XmlLoader\TravelLoader;
use App\Exception\TravelNotFoundException;
@@ -20,7 +20,7 @@ class TravelDataProviderTest extends TestCase
{
private ?TravelDataProvider $service = null;
private TravelLoader $travelLoader;
private ApiClient $apiClient;
private TravelClient $travelClient;
private CacheInterface $cache;
private LoggerInterface $logger;
private TravelSnapshotManager $travelSnapshotService;
@@ -30,7 +30,7 @@ class TravelDataProviderTest extends TestCase
protected function setUp(): void
{
$this->travelLoader = $this->createStub(TravelLoader::class);
$this->apiClient = $this->createStub(ApiClient::class);
$this->travelClient = $this->createStub(TravelClient::class);
$this->cache = $this->createStub(CacheInterface::class);
$this->logger = $this->createStub(LoggerInterface::class);
$this->travelSnapshotService = $this->createStub(TravelSnapshotManager::class);
@@ -42,7 +42,7 @@ class TravelDataProviderTest extends TestCase
{
return $this->service ??= new TravelDataProvider(
$this->travelLoader,
$this->apiClient,
$this->travelClient,
$this->cache,
$this->logger,
$this->travelSnapshotService,
@@ -144,7 +144,7 @@ class TravelDataProviderTest extends TestCase
public function testGetTravelDataFromApiSuccess(): void
{
$this->apiClient = $this->createMock(ApiClient::class);
$this->travelClient = $this->createMock(TravelClient::class);
$this->travelSnapshotService = $this->createMock(TravelSnapshotManager::class);
$this->travelLookupService = $this->createMock(TravelIndex::class);
$this->travelEnrichmentService = $this->createMock(TravelEnricher::class);
@@ -162,7 +162,7 @@ class TravelDataProviderTest extends TestCase
->with($dateId)
->willReturn($productId);
$this->apiClient
$this->travelClient
->expects($this->once())
->method('getTravelData')
->with($productId, $hotelId)
@@ -199,7 +199,7 @@ class TravelDataProviderTest extends TestCase
->method('mapDateIdToProductId')
->willReturn($productId);
$this->apiClient
$this->travelClient
->method('getTravelData')
->willReturn($travel);
@@ -221,7 +221,7 @@ class TravelDataProviderTest extends TestCase
public function testGetTravelDataFromApiCannotMapDateId(): void
{
$this->apiClient = $this->createMock(ApiClient::class);
$this->travelClient = $this->createMock(TravelClient::class);
$this->travelLookupService = $this->createMock(TravelIndex::class);
$dateId = 12345;
@@ -233,7 +233,7 @@ class TravelDataProviderTest extends TestCase
->with($dateId)
->willReturn(null);
$this->apiClient
$this->travelClient
->expects($this->never())
->method('getTravelData');
+12 -12
View File
@@ -4,7 +4,7 @@ declare(strict_types=1);
namespace App\Tests\Service;
use App\BusProNet\ApiClient;
use App\BusProNet\Client\TravelClient;
use App\BusProNet\Exception\ApiClientException;
use App\BusProNet\Model\ExtendedServiceAvailabilityResponse;
use App\BusProNet\Model\Hotel;
@@ -21,7 +21,7 @@ class TravelSnapshotManagerTest extends TestCase
{
private TravelSnapshotRepository $snapshotRepository;
private EntityManagerInterface $entityManager;
private ApiClient $apiClient;
private TravelClient $travelClient;
private LoggerInterface $logger;
private SerializerInterface $serializer;
private ?TravelSnapshotManager $service = null;
@@ -30,7 +30,7 @@ class TravelSnapshotManagerTest extends TestCase
{
$this->snapshotRepository = $this->createStub(TravelSnapshotRepository::class);
$this->entityManager = $this->createStub(EntityManagerInterface::class);
$this->apiClient = $this->createStub(ApiClient::class);
$this->travelClient = $this->createStub(TravelClient::class);
$this->logger = $this->createStub(LoggerInterface::class);
$this->serializer = $this->createStub(SerializerInterface::class);
}
@@ -40,7 +40,7 @@ class TravelSnapshotManagerTest extends TestCase
return $this->service ??= new TravelSnapshotManager(
$this->snapshotRepository,
$this->entityManager,
$this->apiClient,
$this->travelClient,
$this->logger,
$this->serializer,
14,
@@ -309,7 +309,7 @@ class TravelSnapshotManagerTest extends TestCase
{
$this->snapshotRepository = $this->createMock(TravelSnapshotRepository::class);
$this->entityManager = $this->createMock(EntityManagerInterface::class);
$this->apiClient = $this->createMock(ApiClient::class);
$this->travelClient = $this->createMock(TravelClient::class);
$this->serializer = $this->createMock(SerializerInterface::class);
$travel = new Travel();
@@ -334,7 +334,7 @@ class TravelSnapshotManagerTest extends TestCase
->with($oldPayload, Travel::class, 'json')
->willReturn($travel);
$this->apiClient
$this->travelClient
->expects($this->once())
->method('getAvailabilitiesExtended')
->with(100)
@@ -359,7 +359,7 @@ class TravelSnapshotManagerTest extends TestCase
{
$this->snapshotRepository = $this->createMock(TravelSnapshotRepository::class);
$this->entityManager = $this->createMock(EntityManagerInterface::class);
$this->apiClient = $this->createMock(ApiClient::class);
$this->travelClient = $this->createMock(TravelClient::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->serializer = $this->createMock(SerializerInterface::class);
@@ -380,7 +380,7 @@ class TravelSnapshotManagerTest extends TestCase
->method('deserialize')
->willReturn($travel);
$this->apiClient
$this->travelClient
->expects($this->once())
->method('getAvailabilitiesExtended')
->willThrowException(new ApiClientException('API error'));
@@ -437,7 +437,7 @@ class TravelSnapshotManagerTest extends TestCase
{
$this->snapshotRepository = $this->createMock(TravelSnapshotRepository::class);
$this->entityManager = $this->createMock(EntityManagerInterface::class);
$this->apiClient = $this->createMock(ApiClient::class);
$this->travelClient = $this->createMock(TravelClient::class);
$payload = '{"id":100}';
$snapshot = new TravelSnapshot(100, 200, $payload, hash('sha256', $payload));
@@ -447,7 +447,7 @@ class TravelSnapshotManagerTest extends TestCase
->method('findRefreshCandidates')
->willReturn([$snapshot]);
$this->apiClient
$this->travelClient
->expects($this->never())
->method('getAvailabilitiesExtended');
@@ -463,7 +463,7 @@ class TravelSnapshotManagerTest extends TestCase
public function testRefreshSkipsSnapshotsWithXmlAvailable(): void
{
$this->snapshotRepository = $this->createMock(TravelSnapshotRepository::class);
$this->apiClient = $this->createMock(ApiClient::class);
$this->travelClient = $this->createMock(TravelClient::class);
$payload = '{"id":100}';
$snapshot = new TravelSnapshot(100, 200, $payload, hash('sha256', $payload));
@@ -473,7 +473,7 @@ class TravelSnapshotManagerTest extends TestCase
->method('findRefreshCandidates')
->willReturn([$snapshot]);
$this->apiClient
$this->travelClient
->expects($this->never())
->method('getAvailabilitiesExtended');
+18 -18
View File
@@ -4,7 +4,7 @@ declare(strict_types=1);
namespace App\Tests\Service;
use App\BusProNet\ApiClient;
use App\BusProNet\Client\VoucherClient;
use App\BusProNet\Model\Notification;
use App\BusProNet\Model\VoucherPaymentMethod;
use App\BusProNet\Model\VoucherTemplate;
@@ -21,10 +21,10 @@ class VoucherTemplateProviderTest extends TestCase
public function testTemplatesAreCached(): void
{
$templates = new VoucherTemplates(10, 5000, [new VoucherTemplate(3, 'K', 'Allgemein')]);
$apiClient = $this->createMock(ApiClient::class);
$apiClient->expects(self::once())->method('getVoucherTemplates')->willReturn($templates);
$voucherClient = $this->createMock(VoucherClient::class);
$voucherClient->expects(self::once())->method('getVoucherTemplates')->willReturn($templates);
$provider = $this->createProvider($apiClient);
$provider = $this->createProvider($voucherClient);
self::assertEquals($templates, $provider->getTemplates());
self::assertEquals($templates, $provider->getTemplates());
@@ -33,11 +33,11 @@ class VoucherTemplateProviderTest extends TestCase
public function testARejectionIsNotCached(): void
{
$templates = new VoucherTemplates(10, 5000, [new VoucherTemplate(3, 'K', 'Allgemein')]);
$apiClient = $this->createMock(ApiClient::class);
$apiClient->expects(self::exactly(2))->method('getVoucherTemplates')
$voucherClient = $this->createMock(VoucherClient::class);
$voucherClient->expects(self::exactly(2))->method('getVoucherTemplates')
->willReturnOnConsecutiveCalls(new Notification(104, 'User fehlerhaft'), $templates);
$provider = $this->createProvider($apiClient);
$provider = $this->createProvider($voucherClient);
try {
$provider->getTemplates();
@@ -50,37 +50,37 @@ class VoucherTemplateProviderTest extends TestCase
public function testNoTemplatesOnSaleMeansNoShop(): void
{
$apiClient = $this->createStub(ApiClient::class);
$apiClient->method('getVoucherTemplates')->willReturn(new VoucherTemplates(10, 5000, []));
$voucherClient = $this->createStub(VoucherClient::class);
$voucherClient->method('getVoucherTemplates')->willReturn(new VoucherTemplates(10, 5000, []));
$this->expectException(VoucherShopUnavailableException::class);
$this->createProvider($apiClient)->getTemplates();
$this->createProvider($voucherClient)->getTemplates();
}
public function testThePaymentMethodIsTransfer(): void
{
$apiClient = $this->createStub(ApiClient::class);
$apiClient->method('getVoucherPaymentMethods')->willReturn([
$voucherClient = $this->createStub(VoucherClient::class);
$voucherClient->method('getVoucherPaymentMethods')->willReturn([
new VoucherPaymentMethod(1, 'Lastschrift', 'LAST'),
new VoucherPaymentMethod(2, 'Überweisung', 'UEBERW'),
]);
self::assertSame(2, $this->createProvider($apiClient)->getPaymentMethod()->id);
self::assertSame(2, $this->createProvider($voucherClient)->getPaymentMethod()->id);
}
public function testWithoutTransferThereIsNoShop(): void
{
$apiClient = $this->createStub(ApiClient::class);
$apiClient->method('getVoucherPaymentMethods')->willReturn([new VoucherPaymentMethod(1, 'Lastschrift', 'LAST')]);
$voucherClient = $this->createStub(VoucherClient::class);
$voucherClient->method('getVoucherPaymentMethods')->willReturn([new VoucherPaymentMethod(1, 'Lastschrift', 'LAST')]);
$this->expectException(VoucherShopUnavailableException::class);
$this->createProvider($apiClient)->getPaymentMethod();
$this->createProvider($voucherClient)->getPaymentMethod();
}
private function createProvider(ApiClient $apiClient): VoucherTemplateProvider
private function createProvider(VoucherClient $voucherClient): VoucherTemplateProvider
{
return new VoucherTemplateProvider($apiClient, new TagAwareAdapter(new ArrayAdapter()), new NullLogger());
return new VoucherTemplateProvider($voucherClient, new TagAwareAdapter(new ArrayAdapter()), new NullLogger());
}
}