refactor: delete the BusProNet base-data read path

This commit is contained in:
fromme committed 2026-09-29 13:06:12 +02:00
1 parent 0f76c5a7b6
commit aa66c50979
4 files changed
+17 -168

No files matched your search

+5 -53
View File
@@ -3,10 +3,7 @@
namespace App\Tests\BusProNet;
use App\BusProNet\ApiClient;
use App\BusProNet\Model\BaseDataResponse;
use App\BusProNet\Model\CrmAttributesResponse;
use App\BusProNet\Model\Hotel;
use App\BusProNet\Model\Pickup;
use App\BusProNet\Model\ProfileResponse;
use App\BusProNet\Model\ProfileUpdateResponse;
use App\BusProNet\Model\RegistrationResponse;
@@ -135,51 +132,6 @@ class ResponseParserTest extends TestCase
$this->assertTrue($response->isUpdated());
}
public function testParseSuccessfulPickupsResponse(): void
{
$content = '<?xml version="1.0" encoding="utf-8" ?><zustiege><zustieg id="1" idbuspro="1" code="298"><ort>Karlsruhe</ort><strasse>A5 - Autohof Bruchsal</strasse><art>BUS</art><hausabholung>False</hausabholung><crsbuchbar>True</crsbuchbar><internetbuchbar>True</internetbuchbar></zustieg><zustieg id="2" idbuspro="2" code="2"><ort>Bonn</ort><strasse>Bahnhof</strasse><art>BUS</art><hausabholung>False</hausabholung><crsbuchbar>True</crsbuchbar><internetbuchbar>True</internetbuchbar></zustieg></zustiege>';
$parser = $this->getParserInstance();
$response = $parser->parseXmlString(ApiClient::TYPE_BASE_DATA_PICKUPS, $content);
$this->assertInstanceOf(BaseDataResponse::class, $response);
$pickups = $response->getItems();
$this->assertCount(2, $pickups);
$pickup = reset($pickups);
$this->assertInstanceOf(Pickup::class, $pickup);
$this->assertEquals(1, $pickup->getId());
$this->assertEquals(1, $pickup->getBusProId());
$this->assertEquals('298', $pickup->getCode());
$this->assertEquals('Karlsruhe', $pickup->getCity());
$this->assertEquals('A5 - Autohof Bruchsal', $pickup->getStreet());
}
public function testParseSuccessfulHotelsResponse(): void
{
$content = '<?xml version="1.0" encoding="utf-8" ?><hotels><hotel id="1" idbuspro="202003" code="HÖCHST"><name>Berggasthof Höchsten</name><ort>Musterort</ort><strasse>Musterstr. 123</strasse><telefon>03444/19100</telefon><art>Gaststätte</art><internetbuchbar>True</internetbuchbar></hotel><hotel id="2" idbuspro="202004" code="Z. LÖW"><name>Brauereigasthof Zum Löwen</name><ort>Musterort</ort><strasse>Musterstr. 123</strasse><telefon>03437/11133</telefon><art>Gaststätte</art><internetbuchbar>True</internetbuchbar><selektiongruppe id="1" idbuspro="1" bezeichnung="Reisearten 1"><selektion id="1" idbuspro="2" bezeichnung="Kurz-und Clubreisen" /><selektion id="2" idbuspro="7" bezeichnung="Musik und Theater" /><selektion id="3" idbuspro="12" bezeichnung="Flugreisen" /><selektion id="4" idbuspro="13" bezeichnung="Tagesfahrten" /><selektion id="5" idbuspro="1" bezeichnung="Städtereisen" /></selektiongruppe><selektiongruppe id="2" idbuspro="2" bezeichnung="Reisearten 2"><selektion id="1" idbuspro="18" bezeichnung="Adventreisen" /></selektiongruppe><selektiongruppe id="3" idbuspro="3" bezeichnung="Statistik 1"><selektion id="1" idbuspro="31" bezeichnung="Städtreisen" /><selektion id="2" idbuspro="32" bezeichnung="Kurz-und Clubreisen" /><selektion id="3" idbuspro="37" bezeichnung="Musik und Theater" /><selektion id="4" idbuspro="42" bezeichnung="Flugreisen" /><selektion id="5" idbuspro="43" bezeichnung="Tagesfahrten" /></selektiongruppe></hotel></hotels>';
$parser = $this->getParserInstance();
$response = $parser->parseXmlString(ApiClient::TYPE_BASE_DATA_HOTELS, $content);
$this->assertInstanceOf(BaseDataResponse::class, $response);
$hotels = $response->getItems();
$this->assertCount(2, $hotels);
$hotel = reset($hotels);
$this->assertInstanceOf(Hotel::class, $hotel);
$this->assertEquals(1, $hotel->getId());
$this->assertEquals(202003, $hotel->getBusProId());
$this->assertEquals('HÖCHST', $hotel->getCode());
$this->assertEquals('Berggasthof Höchsten', $hotel->getName());
$this->assertEquals('Musterort', $hotel->getCity());
$this->assertEquals('Musterstr. 123', $hotel->getStreet());
$this->assertEquals('03444/19100', $hotel->getPhone());
$this->assertEquals('Gaststätte', $hotel->getType());
}
/**
* A broken response used to collapse into one opaque "Unable to parse XML response",
* which is what made the production import failure undiagnosable. Each shape must now
@@ -192,17 +144,17 @@ class ResponseParserTest extends TestCase
$this->expectException(ResponseParserException::class);
$this->expectExceptionMessage('empty response');
$parser->parseXmlString(ApiClient::TYPE_BASE_DATA_PICKUPS, '');
$parser->parseXmlString(ApiClient::TYPE_CUSTOMER_DATA, '');
}
public function testParseTruncatedResponse(): void
{
$content = '<?xml version="1.0" encoding="utf-8"?><ergebnis><satz typ="STAMMZUSTIEGE"></satz><zustieg id="1"';
$content = '<?xml version="1.0" encoding="utf-8"?><ergebnis><satz typ="KUNDENKONTO"></satz><art>Adressdaten</art';
$parser = $this->getParserInstance();
try {
$parser->parseXmlString(ApiClient::TYPE_BASE_DATA_PICKUPS, $content);
$parser->parseXmlString(ApiClient::TYPE_CUSTOMER_DATA, $content);
$this->fail('Expected a ResponseParserException');
} catch (ResponseParserException $e) {
$this->assertStringContainsString('('.strlen($content).' bytes)', $e->getMessage());
@@ -219,7 +171,7 @@ class ResponseParserTest extends TestCase
$this->expectException(ResponseParserException::class);
$this->expectExceptionMessage('Unrecognised BusProNet response type "STAMMIRGENDWAS"');
$parser->parseXmlString(ApiClient::TYPE_BASE_DATA_PICKUPS, $content);
$parser->parseXmlString(ApiClient::TYPE_CUSTOMER_DATA, $content);
}
public function testParsingDoesNotLeakLibxmlErrorState(): void
@@ -228,7 +180,7 @@ class ResponseParserTest extends TestCase
try {
try {
$this->getParserInstance()->parseXmlString(ApiClient::TYPE_BASE_DATA_PICKUPS, '<ergebnis');
$this->getParserInstance()->parseXmlString(ApiClient::TYPE_CUSTOMER_DATA, '<ergebnis');
} catch (ResponseParserException) {
}