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,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);
}