refactor: split buspro ApiClient into domain clients
This commit is contained in:
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\Controller\Account;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Client\AccountClient;
|
||||
use App\BusProNet\Model\Notification;
|
||||
use App\BusProNet\Model\PersonalData;
|
||||
use App\Controller\Account\PersonalDataController;
|
||||
@@ -28,10 +28,10 @@ class PersonalDataControllerTest extends TestCase
|
||||
public function testIndexRendersNewsletterSubscribeCtaWhenNotSubscribed(): void
|
||||
{
|
||||
$controller = $this->createController(
|
||||
apiClient: $this->createMock(ApiClient::class),
|
||||
accountClient: $this->createMock(AccountClient::class),
|
||||
newsletterManager: $this->createMock(NewsletterManager::class),
|
||||
);
|
||||
$controller->apiClient
|
||||
$controller->accountClient
|
||||
->expects(self::once())
|
||||
->method('getPersonalData')
|
||||
->with('[email protected]', 'secret')
|
||||
@@ -59,10 +59,10 @@ class PersonalDataControllerTest extends TestCase
|
||||
public function testIndexStillTracksPendingNewsletterConfirmationWhenSubscribed(): void
|
||||
{
|
||||
$controller = $this->createController(
|
||||
apiClient: $this->createMock(ApiClient::class),
|
||||
accountClient: $this->createMock(AccountClient::class),
|
||||
newsletterManager: $this->createMock(NewsletterManager::class),
|
||||
);
|
||||
$controller->apiClient
|
||||
$controller->accountClient
|
||||
->expects(self::once())
|
||||
->method('getPersonalData')
|
||||
->with('[email protected]', 'secret')
|
||||
@@ -89,10 +89,10 @@ class PersonalDataControllerTest extends TestCase
|
||||
public function testNewsletterActionReturnsHtmxRedirectAndFlash(): void
|
||||
{
|
||||
$controller = $this->createController(
|
||||
apiClient: $this->createMock(ApiClient::class),
|
||||
accountClient: $this->createMock(AccountClient::class),
|
||||
newsletterManager: $this->createMock(NewsletterManager::class),
|
||||
);
|
||||
$controller->apiClient
|
||||
$controller->accountClient
|
||||
->expects(self::once())
|
||||
->method('getPersonalData')
|
||||
->with('[email protected]', 'secret')
|
||||
@@ -132,10 +132,10 @@ class PersonalDataControllerTest extends TestCase
|
||||
public function testNewsletterActionResendsPendingConfirmation(): void
|
||||
{
|
||||
$controller = $this->createController(
|
||||
apiClient: $this->createMock(ApiClient::class),
|
||||
accountClient: $this->createMock(AccountClient::class),
|
||||
newsletterManager: $this->createMock(NewsletterManager::class),
|
||||
);
|
||||
$controller->apiClient
|
||||
$controller->accountClient
|
||||
->expects(self::once())
|
||||
->method('getPersonalData')
|
||||
->with('[email protected]', 'secret')
|
||||
@@ -170,7 +170,7 @@ class PersonalDataControllerTest extends TestCase
|
||||
public function testIndexLocksTheEmailField(): void
|
||||
{
|
||||
$controller = $this->createController();
|
||||
$controller->apiClient
|
||||
$controller->accountClient
|
||||
->method('getPersonalData')
|
||||
->willReturn($this->createPersonalData('Mia', 'Muster'));
|
||||
|
||||
@@ -186,14 +186,14 @@ class PersonalDataControllerTest extends TestCase
|
||||
public function testIndexDoesNotSubmitTheFormWhenPersonalDataCouldNotBeLoaded(): void
|
||||
{
|
||||
$controller = $this->createController(
|
||||
apiClient: $this->createMock(ApiClient::class),
|
||||
accountClient: $this->createMock(AccountClient::class),
|
||||
form: $this->createMock(FormInterface::class),
|
||||
);
|
||||
$controller->apiClient
|
||||
$controller->accountClient
|
||||
->expects(self::once())
|
||||
->method('getPersonalData')
|
||||
->willReturn(new Notification(500, 'no such customer'));
|
||||
$controller->apiClient
|
||||
$controller->accountClient
|
||||
->expects(self::never())
|
||||
->method('updatePersonalData');
|
||||
|
||||
@@ -214,7 +214,7 @@ class PersonalDataControllerTest extends TestCase
|
||||
* expectations on, and reaches it again through the controller's public property.
|
||||
*/
|
||||
private function createController(
|
||||
?ApiClient $apiClient = null,
|
||||
?AccountClient $accountClient = null,
|
||||
?NewsletterManager $newsletterManager = null,
|
||||
?FormInterface $form = null,
|
||||
): TestablePersonalDataController {
|
||||
@@ -236,7 +236,7 @@ class PersonalDataControllerTest extends TestCase
|
||||
->willReturn(false);
|
||||
|
||||
return new TestablePersonalDataController(
|
||||
$apiClient ?? $this->createStub(ApiClient::class),
|
||||
$accountClient ?? $this->createStub(AccountClient::class),
|
||||
$crypt,
|
||||
$this->createStub(BookingEditDataLoader::class),
|
||||
$this->createStub(ProfileCompletenessChecker::class),
|
||||
@@ -281,7 +281,7 @@ final class TestablePersonalDataController extends PersonalDataController
|
||||
public array $createFormOptions = [];
|
||||
|
||||
public function __construct(
|
||||
public readonly ApiClient $apiClient,
|
||||
public readonly AccountClient $accountClient,
|
||||
Crypt $crypt,
|
||||
BookingEditDataLoader $dataLoader,
|
||||
ProfileCompletenessChecker $completenessChecker,
|
||||
@@ -292,7 +292,7 @@ final class TestablePersonalDataController extends PersonalDataController
|
||||
public readonly FormInterface $form,
|
||||
) {
|
||||
parent::__construct(
|
||||
$apiClient,
|
||||
$accountClient,
|
||||
$crypt,
|
||||
$dataLoader,
|
||||
$completenessChecker,
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller\Api;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Client\AccountClient;
|
||||
use App\BusProNet\Model\PersonalData;
|
||||
use App\Controller\Api\UserinfoController;
|
||||
use App\Entity\User;
|
||||
@@ -104,10 +104,10 @@ class UserinfoControllerTest extends TestCase
|
||||
|
||||
public function testUpstreamFailureIsReportedRatherThanAnswered(): void
|
||||
{
|
||||
$apiClient = $this->createStub(ApiClient::class);
|
||||
$apiClient->method('getPersonalData')->willThrowException(new \App\BusProNet\Exception\ApiClientException('nope'));
|
||||
$accountClient = $this->createStub(AccountClient::class);
|
||||
$accountClient->method('getPersonalData')->willThrowException(new \App\BusProNet\Exception\ApiClientException('nope'));
|
||||
|
||||
$response = $this->call($apiClient, []);
|
||||
$response = $this->call($accountClient, []);
|
||||
|
||||
self::assertSame(Response::HTTP_BAD_REQUEST, $response->getStatusCode());
|
||||
}
|
||||
@@ -120,10 +120,10 @@ class UserinfoControllerTest extends TestCase
|
||||
*/
|
||||
private function claims(array $grantedScopeRoles = [], array $roles = [Role::TEAMER]): array
|
||||
{
|
||||
$apiClient = $this->createStub(ApiClient::class);
|
||||
$apiClient->method('getPersonalData')->willReturn($this->personalData());
|
||||
$accountClient = $this->createStub(AccountClient::class);
|
||||
$accountClient->method('getPersonalData')->willReturn($this->personalData());
|
||||
|
||||
$response = $this->call($apiClient, $grantedScopeRoles, $roles);
|
||||
$response = $this->call($accountClient, $grantedScopeRoles, $roles);
|
||||
|
||||
self::assertSame(Response::HTTP_OK, $response->getStatusCode());
|
||||
|
||||
@@ -134,12 +134,12 @@ class UserinfoControllerTest extends TestCase
|
||||
* @param string[] $grantedScopeRoles
|
||||
* @param string[] $roles
|
||||
*/
|
||||
private function call(ApiClient $apiClient, array $grantedScopeRoles, array $roles = [Role::TEAMER]): Response
|
||||
private function call(AccountClient $accountClient, array $grantedScopeRoles, array $roles = [Role::TEAMER]): Response
|
||||
{
|
||||
$crypt = $this->createStub(Crypt::class);
|
||||
$crypt->method('decrypt')->willReturn('md5-of-the-password');
|
||||
|
||||
$controller = new UserinfoController($apiClient, $crypt);
|
||||
$controller = new UserinfoController($accountClient, $crypt);
|
||||
$controller->setContainer($this->container($this->user($roles), $grantedScopeRoles));
|
||||
|
||||
return $controller->index();
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller\Booking\Edit;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Client\AccountClient;
|
||||
use App\BusProNet\Model\Booking;
|
||||
use App\BusProNet\Model\Insurance;
|
||||
use App\BusProNet\Model\Travel;
|
||||
@@ -87,7 +87,7 @@ class ParticipantControllerTest extends TestCase
|
||||
->with($user, 42, $bookingDto);
|
||||
|
||||
$prepopulationService = new ParticipantDataPrefiller(
|
||||
$this->createStub(ApiClient::class),
|
||||
$this->createStub(AccountClient::class),
|
||||
$this->createStub(Crypt::class),
|
||||
$this->createStub(LoggerInterface::class),
|
||||
);
|
||||
@@ -231,7 +231,7 @@ class ParticipantControllerTest extends TestCase
|
||||
->willReturn($context);
|
||||
|
||||
$prepopulationService = new ParticipantDataPrefiller(
|
||||
$this->createStub(ApiClient::class),
|
||||
$this->createStub(AccountClient::class),
|
||||
$this->createStub(Crypt::class),
|
||||
$this->createStub(LoggerInterface::class),
|
||||
);
|
||||
@@ -331,7 +331,7 @@ class ParticipantControllerTest extends TestCase
|
||||
$this->createStub(BookingConfigurator::class),
|
||||
$bookingSessionService,
|
||||
new ParticipantDataPrefiller(
|
||||
$this->createStub(ApiClient::class),
|
||||
$this->createStub(AccountClient::class),
|
||||
$this->createStub(Crypt::class),
|
||||
$this->createStub(LoggerInterface::class),
|
||||
),
|
||||
@@ -409,7 +409,7 @@ class ParticipantControllerTest extends TestCase
|
||||
$this->createStub(BookingConfigurator::class),
|
||||
$bookingSessionService,
|
||||
new ParticipantDataPrefiller(
|
||||
$this->createStub(ApiClient::class),
|
||||
$this->createStub(AccountClient::class),
|
||||
$this->createStub(Crypt::class),
|
||||
$this->createStub(LoggerInterface::class),
|
||||
),
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Controller\Voucher;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Client\VoucherClient;
|
||||
use App\BusProNet\Exception\TimeoutException;
|
||||
use App\BusProNet\Model\Notification;
|
||||
use App\BusProNet\Model\VoucherPaymentMethod;
|
||||
@@ -42,11 +42,11 @@ class Step3ControllerTest extends TestCase
|
||||
$dto->termsAccepted = true;
|
||||
$dto->purchaseConfirmed = true;
|
||||
|
||||
$apiClient = $this->createMock(ApiClient::class);
|
||||
$apiClient->expects(self::once())->method('createVoucherSaleInquiry')->willReturn(new VoucherSaleResponse('möglich'));
|
||||
$apiClient->expects(self::never())->method('createVoucherSale');
|
||||
$voucherClient = $this->createMock(VoucherClient::class);
|
||||
$voucherClient->expects(self::once())->method('createVoucherSaleInquiry')->willReturn(new VoucherSaleResponse('möglich'));
|
||||
$voucherClient->expects(self::never())->method('createVoucherSale');
|
||||
|
||||
$controller = $this->createController($apiClient);
|
||||
$controller = $this->createController($voucherClient);
|
||||
$controller->index($request);
|
||||
|
||||
self::assertTrue($controller->renderParameters['purchasable']);
|
||||
@@ -61,12 +61,12 @@ class Step3ControllerTest extends TestCase
|
||||
{
|
||||
$request = $this->createRequest('GET', $this->createDto());
|
||||
|
||||
$apiClient = $this->createStub(ApiClient::class);
|
||||
$apiClient->method('createVoucherSaleInquiry')->willReturn(
|
||||
$voucherClient = $this->createStub(VoucherClient::class);
|
||||
$voucherClient->method('createVoucherSaleInquiry')->willReturn(
|
||||
new Notification(650, 'Fehlende Adress Daten. Bitte folgende Eingabefelder prüfen: Strasse')
|
||||
);
|
||||
|
||||
$controller = $this->createController($apiClient);
|
||||
$controller = $this->createController($voucherClient);
|
||||
$response = $controller->index($request);
|
||||
|
||||
self::assertInstanceOf(RedirectResponse::class, $response);
|
||||
@@ -79,12 +79,12 @@ class Step3ControllerTest extends TestCase
|
||||
{
|
||||
$request = $this->createRequest('GET', $this->createDto());
|
||||
|
||||
$apiClient = $this->createStub(ApiClient::class);
|
||||
$apiClient->method('createVoucherSaleInquiry')->willReturn(
|
||||
$voucherClient = $this->createStub(VoucherClient::class);
|
||||
$voucherClient->method('createVoucherSaleInquiry')->willReturn(
|
||||
new Notification(608, 'Gutscheinbetrag darf nicht größer als 5.000,00 Euro sein')
|
||||
);
|
||||
|
||||
$response = $this->createController($apiClient)->index($request);
|
||||
$response = $this->createController($voucherClient)->index($request);
|
||||
|
||||
self::assertInstanceOf(RedirectResponse::class, $response);
|
||||
self::assertSame('/app_voucher_step_1', $response->getTargetUrl());
|
||||
@@ -94,10 +94,10 @@ class Step3ControllerTest extends TestCase
|
||||
{
|
||||
$request = $this->createRequest('GET', $this->createDto());
|
||||
|
||||
$apiClient = $this->createStub(ApiClient::class);
|
||||
$apiClient->method('createVoucherSaleInquiry')->willReturn(new Notification(619, 'Agentur-ID fehlt'));
|
||||
$voucherClient = $this->createStub(VoucherClient::class);
|
||||
$voucherClient->method('createVoucherSaleInquiry')->willReturn(new Notification(619, 'Agentur-ID fehlt'));
|
||||
|
||||
$controller = $this->createController($apiClient);
|
||||
$controller = $this->createController($voucherClient);
|
||||
$controller->index($request);
|
||||
|
||||
self::assertFalse($controller->renderParameters['purchasable']);
|
||||
@@ -107,9 +107,9 @@ class Step3ControllerTest extends TestCase
|
||||
{
|
||||
$request = $this->createRequest('POST', $this->createDto());
|
||||
|
||||
$apiClient = $this->createMock(ApiClient::class);
|
||||
$apiClient->expects(self::never())->method('createVoucherSaleInquiry');
|
||||
$apiClient->expects(self::once())->method('createVoucherSale')->willReturn(new VoucherSaleResponse(
|
||||
$voucherClient = $this->createMock(VoucherClient::class);
|
||||
$voucherClient->expects(self::never())->method('createVoucherSaleInquiry');
|
||||
$voucherClient->expects(self::once())->method('createVoucherSale')->willReturn(new VoucherSaleResponse(
|
||||
status: 'erfolgt',
|
||||
voucherId: 4711,
|
||||
voucherNumber: 'K-001234',
|
||||
@@ -124,7 +124,7 @@ class Step3ControllerTest extends TestCase
|
||||
static fn (array $context) => !\in_array('ABCD1234', $context, true) && 'K-001234' === $context['voucher_number']
|
||||
));
|
||||
|
||||
$controller = $this->createController($apiClient, $this->createSubmittedForm(), $logger);
|
||||
$controller = $this->createController($voucherClient, $this->createSubmittedForm(), $logger);
|
||||
$response = $controller->index($request);
|
||||
|
||||
self::assertInstanceOf(RedirectResponse::class, $response);
|
||||
@@ -143,10 +143,10 @@ class Step3ControllerTest extends TestCase
|
||||
$request = Request::create('/gutschein/uebersicht', 'POST');
|
||||
$request->setSession(new Session(new MockArraySessionStorage()));
|
||||
|
||||
$apiClient = $this->createMock(ApiClient::class);
|
||||
$apiClient->expects(self::never())->method('createVoucherSale');
|
||||
$voucherClient = $this->createMock(VoucherClient::class);
|
||||
$voucherClient->expects(self::never())->method('createVoucherSale');
|
||||
|
||||
$response = $this->createController($apiClient, $this->createSubmittedForm())->index($request);
|
||||
$response = $this->createController($voucherClient, $this->createSubmittedForm())->index($request);
|
||||
|
||||
self::assertInstanceOf(RedirectResponse::class, $response);
|
||||
self::assertSame('/app_voucher_error', $response->getTargetUrl());
|
||||
@@ -159,10 +159,10 @@ class Step3ControllerTest extends TestCase
|
||||
{
|
||||
$request = $this->createRequest('POST', $this->createDto());
|
||||
|
||||
$apiClient = $this->createStub(ApiClient::class);
|
||||
$apiClient->method('createVoucherSale')->willThrowException(new TimeoutException('Stream timeout'));
|
||||
$voucherClient = $this->createStub(VoucherClient::class);
|
||||
$voucherClient->method('createVoucherSale')->willThrowException(new TimeoutException('Stream timeout'));
|
||||
|
||||
$controller = $this->createController($apiClient, $this->createSubmittedForm());
|
||||
$controller = $this->createController($voucherClient, $this->createSubmittedForm());
|
||||
$controller->index($request);
|
||||
|
||||
self::assertFalse($controller->renderParameters['purchasable']);
|
||||
@@ -205,12 +205,12 @@ class Step3ControllerTest extends TestCase
|
||||
/**
|
||||
* @param FormInterface<VoucherPurchaseDto>|null $form
|
||||
*/
|
||||
private function createController(ApiClient $apiClient, ?FormInterface $form = null, ?LoggerInterface $logger = null): TestableStep3Controller
|
||||
private function createController(VoucherClient $voucherClient, ?FormInterface $form = null, ?LoggerInterface $logger = null): TestableStep3Controller
|
||||
{
|
||||
return new TestableStep3Controller(
|
||||
$this->sessionManager,
|
||||
$this->createStub(VoucherThumbnailResolver::class),
|
||||
$apiClient,
|
||||
$voucherClient,
|
||||
new VoucherSaleRejectionMapper(),
|
||||
$logger ?? new NullLogger(),
|
||||
$form ?? $this->createStub(FormInterface::class),
|
||||
@@ -236,12 +236,12 @@ final class TestableStep3Controller extends Step3Controller
|
||||
public function __construct(
|
||||
VoucherPurchaseSessionManager $sessionManager,
|
||||
VoucherThumbnailResolver $thumbnailResolver,
|
||||
ApiClient $apiClient,
|
||||
VoucherClient $voucherClient,
|
||||
VoucherSaleRejectionMapper $rejectionMapper,
|
||||
LoggerInterface $logger,
|
||||
private readonly FormInterface $form,
|
||||
) {
|
||||
parent::__construct($sessionManager, $thumbnailResolver, $apiClient, $rejectionMapper, $logger);
|
||||
parent::__construct($sessionManager, $thumbnailResolver, $voucherClient, $rejectionMapper, $logger);
|
||||
}
|
||||
|
||||
protected function getUser(): ?UserInterface
|
||||
|
||||
Reference in new issue
Block a user