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,8 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\BusProNet\XmlParser;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Exception\ResponseParserException;
|
||||
use App\BusProNet\MessageType;
|
||||
use App\BusProNet\XmlParser\ApiResponseParser;
|
||||
use App\BusProNet\XmlParser\TravelParser;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@@ -23,7 +23,7 @@ class ApiResponseParserFailureTest extends TestCase
|
||||
$this->expectException(ResponseParserException::class);
|
||||
$this->expectExceptionMessage('empty response (0 bytes)');
|
||||
|
||||
$this->createParser()->parseXmlString(ApiClient::TYPE_NOTIFICATION, '');
|
||||
$this->createParser()->parseXmlString(MessageType::Notification, '');
|
||||
}
|
||||
|
||||
public function testTruncatedResponseNamesTheLibxmlReason(): void
|
||||
@@ -31,7 +31,7 @@ class ApiResponseParserFailureTest extends TestCase
|
||||
$xml = '<?xml version="1.0" encoding="utf-8"?><ergebnis><satz typ="HINWEIS"></satz><hinweis';
|
||||
|
||||
try {
|
||||
$this->createParser()->parseXmlString(ApiClient::TYPE_NOTIFICATION, $xml);
|
||||
$this->createParser()->parseXmlString(MessageType::Notification, $xml);
|
||||
$this->fail('Expected a ResponseParserException');
|
||||
} catch (ResponseParserException $e) {
|
||||
self::assertStringContainsString('('.strlen($xml).' bytes)', $e->getMessage());
|
||||
@@ -46,7 +46,7 @@ class ApiResponseParserFailureTest extends TestCase
|
||||
$this->expectException(ResponseParserException::class);
|
||||
$this->expectExceptionMessage('Unrecognised BusProNet response type "IRGENDWAS"');
|
||||
|
||||
$this->createParser()->parseXmlString(ApiClient::TYPE_NOTIFICATION, $xml);
|
||||
$this->createParser()->parseXmlString(MessageType::Notification, $xml);
|
||||
}
|
||||
|
||||
public function testUnknownCustomerDataSubtype(): void
|
||||
@@ -56,7 +56,7 @@ class ApiResponseParserFailureTest extends TestCase
|
||||
$this->expectException(ResponseParserException::class);
|
||||
$this->expectExceptionMessage('Unrecognised customer data subtype "Irgendwas"');
|
||||
|
||||
$this->createParser()->parseXmlString(ApiClient::TYPE_CUSTOMER_DATA, $xml);
|
||||
$this->createParser()->parseXmlString(MessageType::CustomerData, $xml);
|
||||
}
|
||||
|
||||
public function testDiagnosingDoesNotLeakLibxmlErrorState(): void
|
||||
@@ -65,7 +65,7 @@ class ApiResponseParserFailureTest extends TestCase
|
||||
|
||||
try {
|
||||
try {
|
||||
$this->createParser()->parseXmlString(ApiClient::TYPE_NOTIFICATION, '<ergebnis');
|
||||
$this->createParser()->parseXmlString(MessageType::Notification, '<ergebnis');
|
||||
} catch (ResponseParserException) {
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\BusProNet\XmlParser;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Exception\ResponseParserException;
|
||||
use App\BusProNet\MessageType;
|
||||
use App\BusProNet\Model\Notification;
|
||||
use App\BusProNet\Model\VoucherPaymentMethod;
|
||||
use App\BusProNet\Model\VoucherPreview;
|
||||
@@ -25,7 +25,7 @@ class VoucherResponseParserTest extends TestCase
|
||||
{
|
||||
$xml = '<?xml version="1.0" encoding="utf-8"?><ergebnis><satz typ="GUTSCHEINVORLAGEN"></satz><gutscheinminbetrag>10</gutscheinminbetrag><gutscheinmaxbetrag>5000</gutscheinmaxbetrag><gutscheine><gutschein idgutscheinvorlage="3"><gutscheinart>K</gutscheinart><bezeichnung>Allgemein</bezeichnung><hinweis></hinweis></gutschein><gutschein idgutscheinvorlage="4"><gutscheinart>K</gutscheinart><bezeichnung>Ski</bezeichnung><hinweis></hinweis></gutschein><gutschein idgutscheinvorlage="5"><gutscheinart>K</gutscheinart><bezeichnung>Weihnachten</bezeichnung><hinweis></hinweis></gutschein></gutscheine></ergebnis>';
|
||||
|
||||
$result = $this->parse(ApiClient::TYPE_VOUCHER_TEMPLATES, $xml);
|
||||
$result = $this->parse(MessageType::VoucherTemplates, $xml);
|
||||
|
||||
self::assertInstanceOf(VoucherTemplates::class, $result);
|
||||
self::assertSame(10, $result->minAmount);
|
||||
@@ -45,14 +45,14 @@ class VoucherResponseParserTest extends TestCase
|
||||
$this->expectException(ResponseParserException::class);
|
||||
$this->expectExceptionMessage('amount bounds');
|
||||
|
||||
$this->parse(ApiClient::TYPE_VOUCHER_TEMPLATES, $xml);
|
||||
$this->parse(MessageType::VoucherTemplates, $xml);
|
||||
}
|
||||
|
||||
public function testPaymentMethods(): void
|
||||
{
|
||||
$xml = '<?xml version="1.0" encoding="utf-8"?><ergebnis><satz typ="GUTSCHEINZAHLUNGSARTEN"></satz><zahlungsarten><zahlungsart id="2" bezeichnung="Überweisung" art="UEBERW"></zahlungsart></zahlungsarten></ergebnis>';
|
||||
|
||||
$result = $this->parse(ApiClient::TYPE_VOUCHER_PAYMENT_METHODS, $xml);
|
||||
$result = $this->parse(MessageType::VoucherPaymentMethods, $xml);
|
||||
|
||||
self::assertEquals([new VoucherPaymentMethod(2, 'Überweisung', 'UEBERW')], $result);
|
||||
self::assertTrue($result[0]->isTransfer());
|
||||
@@ -63,7 +63,7 @@ class VoucherResponseParserTest extends TestCase
|
||||
$pdf = "%PDF-1.4\nprobe";
|
||||
$xml = '<?xml version="1.0" encoding="utf-8"?><ergebnis><satz typ="GUTSCHEINVORSCHAU"/><gutscheinpdf>data:application/pdf;base64,'.base64_encode($pdf).'</gutscheinpdf></ergebnis>';
|
||||
|
||||
$result = $this->parse(ApiClient::TYPE_VOUCHER_PREVIEW, $xml);
|
||||
$result = $this->parse(MessageType::VoucherPreview, $xml);
|
||||
|
||||
self::assertInstanceOf(VoucherPreview::class, $result);
|
||||
self::assertSame($pdf, $result->pdf);
|
||||
@@ -75,14 +75,14 @@ class VoucherResponseParserTest extends TestCase
|
||||
|
||||
$this->expectException(ResponseParserException::class);
|
||||
|
||||
$this->parse(ApiClient::TYPE_VOUCHER_PREVIEW, $xml);
|
||||
$this->parse(MessageType::VoucherPreview, $xml);
|
||||
}
|
||||
|
||||
public function testTheDryRunAnswersPossibleAndIssuesNothing(): void
|
||||
{
|
||||
$xml = '<?xml version="1.0" encoding="utf-8"?><ergebnis><satz typ="GUTSCHEINBUCHUNG"></satz><buchung>möglich</buchung></ergebnis>';
|
||||
|
||||
$result = $this->parse(ApiClient::TYPE_VOUCHER_SALE, $xml);
|
||||
$result = $this->parse(MessageType::VoucherSale, $xml);
|
||||
|
||||
self::assertInstanceOf(VoucherSaleResponse::class, $result);
|
||||
self::assertTrue($result->isInquiryValid());
|
||||
@@ -95,7 +95,7 @@ class VoucherResponseParserTest extends TestCase
|
||||
{
|
||||
$xml = '<?xml version="1.0" encoding="utf-8"?><ergebnis><satz typ="GUTSCHEINBUCHUNG"/><buchung>erfolgt</buchung><idgutschein>4711</idgutschein><gutscheinnummer>K-001234</gutscheinnummer><einloesecode>ABCD1234</einloesecode><preis>111,00</preis><rechnungsnummer>R-998877</rechnungsnummer><email>[email protected]</email></ergebnis>';
|
||||
|
||||
$result = $this->parse(ApiClient::TYPE_VOUCHER_SALE, $xml);
|
||||
$result = $this->parse(MessageType::VoucherSale, $xml);
|
||||
|
||||
self::assertInstanceOf(VoucherSaleResponse::class, $result);
|
||||
self::assertTrue($result->isSaleSuccessful());
|
||||
@@ -115,13 +115,13 @@ class VoucherResponseParserTest extends TestCase
|
||||
{
|
||||
$xml = '<?xml version="1.0" encoding="utf-8"?><ergebnis><satz typ="HINWEIS"><nr>650</nr><text>Fehlende Adress Daten. Bitte folgende Eingabefelder prüfen: Strasse</text></satz></ergebnis>';
|
||||
|
||||
$result = $this->parse(ApiClient::TYPE_VOUCHER_SALE, $xml);
|
||||
$result = $this->parse(MessageType::VoucherSale, $xml);
|
||||
|
||||
self::assertInstanceOf(Notification::class, $result);
|
||||
self::assertSame(650, $result->code);
|
||||
}
|
||||
|
||||
private function parse(string $type, string $xml): mixed
|
||||
private function parse(MessageType $type, string $xml): mixed
|
||||
{
|
||||
return (new ApiResponseParser($this->createStub(TravelParser::class)))->parseXmlString($type, $xml);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -4,7 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Security;
|
||||
|
||||
use App\BusProNet\ApiClient;
|
||||
use App\BusProNet\Client\AccountClient;
|
||||
use App\BusProNet\Model\CrmAttributes;
|
||||
use App\BusProNet\Model\CrmSelectionGroup;
|
||||
use App\BusProNet\Model\PersonalData;
|
||||
@@ -380,9 +380,9 @@ class BpnAuthenticatorTest extends TestCase
|
||||
$personalData->addressId = 4711;
|
||||
$personalData->communication->email = $contactEmail;
|
||||
|
||||
$apiClient = $this->createStub(ApiClient::class);
|
||||
$apiClient->method('getPersonalData')->willReturn($personalData);
|
||||
$apiClient->method('getCrmAttributes')->willReturn($crmAttributes);
|
||||
$accountClient = $this->createStub(AccountClient::class);
|
||||
$accountClient->method('getPersonalData')->willReturn($personalData);
|
||||
$accountClient->method('getCrmAttributes')->willReturn($crmAttributes);
|
||||
|
||||
$repository = $this->createStub(EntityRepository::class);
|
||||
$repository
|
||||
@@ -424,7 +424,7 @@ class BpnAuthenticatorTest extends TestCase
|
||||
|
||||
return new BpnAuthenticator(
|
||||
$this->createStub(UrlGeneratorInterface::class),
|
||||
$apiClient,
|
||||
$accountClient,
|
||||
$entityManager,
|
||||
$crypt,
|
||||
$completenessChecker,
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user