chore: major code cleanup and type safety using phpstan

This commit is contained in:
Björn Fromme committed 2026-04-16 17:11:16 +02:00
1 parent 060cbea9da
commit 3da73d626b
103 files changed
+976 -1192

No files matched your search

+3
View File
@@ -65,6 +65,9 @@ class ApiClientReceiveTest extends TestCase
self::assertSame('0000000005Hello', $result);
}
/**
* @param resource $socket
*/
private function invokeReceive($socket): string
{
$method = new \ReflectionMethod(ApiClient::class, 'receive');
@@ -27,7 +27,7 @@ class HotelDataLoaderTest extends TestCase
</hotels>';
$filesystem = $this->createMock(FilesystemOperator::class);
$filesystem->expects($this->once())
$filesystem->expects(self::once())
->method('read')
->with('hotel.xml')
->willReturn($xmlContent);
@@ -37,17 +37,17 @@ class HotelDataLoaderTest extends TestCase
$hotels = $loader->loadAll();
$this->assertIsArray($hotels);
$this->assertArrayHasKey(163113, $hotels);
self::assertIsArray($hotels);
self::assertArrayHasKey(163113, $hotels);
$hotel = $hotels[163113];
$this->assertInstanceOf(Hotel::class, $hotel);
$this->assertEquals(163113, $hotel->id);
$this->assertEquals('L\'Oxalys', $hotel->name);
$this->assertEquals('SBWOXA', $hotel->code);
$this->assertEquals('Val Thorens', $hotel->city);
$this->assertEquals('F', $hotel->country);
$this->assertEquals('Rue des Lacs', $hotel->street);
$this->assertEquals('', $hotel->phone);
self::assertInstanceOf(Hotel::class, $hotel);
self::assertEquals(163113, $hotel->id);
self::assertEquals('L\'Oxalys', $hotel->name);
self::assertEquals('SBWOXA', $hotel->code);
self::assertEquals('Val Thorens', $hotel->city);
self::assertEquals('F', $hotel->country);
self::assertEquals('Rue des Lacs', $hotel->street);
self::assertEquals('', $hotel->phone);
}
}
@@ -27,7 +27,7 @@ class PickupDataLoaderTest extends TestCase
</zustiege>';
$filesystem = $this->createMock(FilesystemOperator::class);
$filesystem->expects($this->once())
$filesystem->expects(self::once())
->method('read')
->with('zustiege.xml')
->willReturn($xmlContent);
@@ -37,11 +37,11 @@ class PickupDataLoaderTest extends TestCase
$pickup = $loader->loadById(1);
$this->assertInstanceOf(Pickup::class, $pickup);
$this->assertEquals(1, $pickup->id);
$this->assertEquals('MS-Hbf', $pickup->code);
$this->assertEquals('Münster', $pickup->city);
$this->assertEquals('48143', $pickup->postalCode);
$this->assertEquals('Hafenstr/Ecke Friedrich-Ebert-Str', $pickup->street);
self::assertInstanceOf(Pickup::class, $pickup);
self::assertEquals(1, $pickup->id);
self::assertEquals('MS-Hbf', $pickup->code);
self::assertEquals('Münster', $pickup->city);
self::assertEquals('48143', $pickup->postalCode);
self::assertEquals('Hafenstr/Ecke Friedrich-Ebert-Str', $pickup->street);
}
}
@@ -29,7 +29,7 @@ class TravelDataLoaderTest extends TestCase
</reisen>';
$filesystem = $this->createMock(FilesystemOperator::class);
$filesystem->expects($this->once())
$filesystem->expects(self::once())
->method('read')
->with('test_file.xml')
->willReturn($xmlContent);
@@ -45,7 +45,7 @@ class TravelDataLoaderTest extends TestCase
$expectedTravel->label = 'Davos - Sportclub Waldschlössli';
$expectedTravel->priceFrom = 534.2;
$travelParser->expects($this->once())
$travelParser->expects(self::once())
->method('parse')
->willReturn($expectedTravel);
@@ -54,12 +54,12 @@ class TravelDataLoaderTest extends TestCase
$travel = $loader->loadById(11478, null, 'test_file.xml');
$this->assertInstanceOf(Travel::class, $travel);
$this->assertEquals('DPWMP060125', $travel->code);
$this->assertEquals('F', $travel->type);
$this->assertInstanceOf(\DateTimeImmutable::class, $travel->dateFrom);
$this->assertInstanceOf(\DateTimeImmutable::class, $travel->dateTo);
$this->assertEquals('Davos - Sportclub Waldschlössli', $travel->label);
$this->assertEquals(534.2, $travel->priceFrom);
self::assertInstanceOf(Travel::class, $travel);
self::assertEquals('DPWMP060125', $travel->code);
self::assertEquals('F', $travel->type);
self::assertInstanceOf(\DateTimeImmutable::class, $travel->dateFrom);
self::assertInstanceOf(\DateTimeImmutable::class, $travel->dateTo);
self::assertEquals('Davos - Sportclub Waldschlössli', $travel->label);
self::assertEquals(534.2, $travel->priceFrom);
}
}
@@ -71,16 +71,16 @@ class BookingDataProcessorTest extends TestCase
$result = $this->processor->createUpdateRequestPayload($formData);
$this->assertIsArray($result);
$this->assertArrayHasKey('idbuchung', $result);
$this->assertArrayHasKey('teilnehmerliste', $result);
$this->assertArrayHasKey('zusatzleistungen', $result);
$this->assertArrayHasKey('beförderungen', $result);
$this->assertArrayHasKey('ferienzielunterbringungen', $result);
self::assertIsArray($result);
self::assertArrayHasKey('idbuchung', $result);
self::assertArrayHasKey('teilnehmerliste', $result);
self::assertArrayHasKey('zusatzleistungen', $result);
self::assertArrayHasKey('beförderungen', $result);
self::assertArrayHasKey('ferienzielunterbringungen', $result);
$this->assertEquals(123, $result['idbuchung']);
$this->assertEquals('ACTIVE', $result['status']);
$this->assertCount(2, $result['teilnehmerliste']['teilnehmer']);
self::assertEquals(123, $result['idbuchung']);
self::assertEquals('ACTIVE', $result['status']);
self::assertCount(2, $result['teilnehmerliste']['teilnehmer']);
}
public function testCanceledParticipantsAreSkipped(): void
@@ -89,9 +89,9 @@ class BookingDataProcessorTest extends TestCase
$result = $this->processor->createUpdateRequestPayload($formData);
$this->assertCount(2, $result['teilnehmerliste']['teilnehmer']);
$this->assertEquals(1, $result['teilnehmerliste']['teilnehmer'][0]['@id']);
$this->assertEquals(2, $result['teilnehmerliste']['teilnehmer'][1]['@id']);
self::assertCount(2, $result['teilnehmerliste']['teilnehmer']);
self::assertEquals(1, $result['teilnehmerliste']['teilnehmer'][0]['@id']);
self::assertEquals(2, $result['teilnehmerliste']['teilnehmer'][1]['@id']);
}
public function testAdditionalServicesProcessing(): void
@@ -100,13 +100,13 @@ class BookingDataProcessorTest extends TestCase
$result = $this->processor->createUpdateRequestPayload($formData);
$this->assertNotEmpty($result['zusatzleistungen']['zusatzleistung']);
$this->assertCount(2, $result['zusatzleistungen']['zusatzleistung']);
self::assertNotEmpty($result['zusatzleistungen']['zusatzleistung']);
self::assertCount(2, $result['zusatzleistungen']['zusatzleistung']);
$service = $result['zusatzleistungen']['zusatzleistung'][0];
$this->assertEquals(1, $service['@idleistung']);
$this->assertEquals(1, $service['@anzahl']);
$this->assertEquals('1', $service['@zuordnung']);
self::assertEquals(1, $service['@idleistung']);
self::assertEquals(1, $service['@anzahl']);
self::assertEquals('1', $service['@zuordnung']);
}
public function testTransportationServicesProcessing(): void
@@ -115,8 +115,8 @@ class BookingDataProcessorTest extends TestCase
$result = $this->processor->createUpdateRequestPayload($formData);
$this->assertNotEmpty($result['beförderungen']['beförderung']);
$this->assertCount(2, $result['beförderungen']['beförderung']);
self::assertNotEmpty($result['beförderungen']['beförderung']);
self::assertCount(2, $result['beförderungen']['beförderung']);
}
public function testBusPickupLocationsProcessing(): void
@@ -125,9 +125,9 @@ class BookingDataProcessorTest extends TestCase
$result = $this->processor->createUpdateRequestPayload($formData);
$this->assertArrayHasKey('zustiege', $result);
$this->assertNotEmpty($result['zustiege']['zustieg']);
$this->assertEquals(1, $result['zustiege']['zustieg'][0]['@idzustieg']);
self::assertArrayHasKey('zustiege', $result);
self::assertNotEmpty($result['zustiege']['zustieg']);
self::assertEquals(1, $result['zustiege']['zustieg'][0]['@idzustieg']);
}
public function testNonBusTransportationSkipsPickup(): void
@@ -136,8 +136,8 @@ class BookingDataProcessorTest extends TestCase
$result = $this->processor->createUpdateRequestPayload($formData);
$this->assertArrayHasKey('zustiege', $result);
$this->assertSame([], $result['zustiege']);
self::assertArrayHasKey('zustiege', $result);
self::assertSame([], $result['zustiege']);
}
public function testUnusedServicesAreRemoved(): void
@@ -146,8 +146,8 @@ class BookingDataProcessorTest extends TestCase
$result = $this->processor->createUpdateRequestPayload($formData);
$this->assertEmpty($result['zusatzleistungen']['zusatzleistung']);
$this->assertEmpty($result['beförderungen']['beförderung']);
self::assertEmpty($result['zusatzleistungen']['zusatzleistung']);
self::assertEmpty($result['beförderungen']['beförderung']);
}
public function testParticipantPersonalDataUpdate(): void
@@ -157,10 +157,10 @@ class BookingDataProcessorTest extends TestCase
$this->processor->createUpdateRequestPayload($formData);
$participant = $formData->booking->participants[0];
$this->assertEquals('Updated', $participant->firstName);
$this->assertEquals('Participant', $participant->name);
$this->assertEquals('[email protected]', $participant->communication->email);
$this->assertEquals('+49123456789', $participant->communication->mobile);
self::assertEquals('Updated', $participant->firstName);
self::assertEquals('Participant', $participant->name);
self::assertEquals('[email protected]', $participant->communication->email);
self::assertEquals('+49123456789', $participant->communication->mobile);
}
public function testCanceledParticipantsPersonalDataIsUpdated(): void
@@ -170,8 +170,8 @@ class BookingDataProcessorTest extends TestCase
$this->processor->createUpdateRequestPayload($formData);
$participant = $formData->booking->participants[0];
$this->assertEquals('Updated', $participant->firstName);
$this->assertEquals('Participant', $participant->name);
self::assertEquals('Updated', $participant->firstName);
self::assertEquals('Participant', $participant->name);
}
public function testApplicantDataSyncWithFirstParticipant(): void
@@ -183,9 +183,9 @@ class BookingDataProcessorTest extends TestCase
$applicant = $formData->booking->applicant;
$firstParticipant = $formData->booking->participants[0];
$this->assertEquals($firstParticipant->height, $applicant->height);
$this->assertEquals($firstParticipant->weight, $applicant->weight);
$this->assertEquals($firstParticipant->shoeSize, $applicant->shoeSize);
self::assertEquals($firstParticipant->height, $applicant->height);
self::assertEquals($firstParticipant->weight, $applicant->weight);
self::assertEquals($firstParticipant->shoeSize, $applicant->shoeSize);
}
public function testBankAccountIncludedInPayload(): void
@@ -194,9 +194,9 @@ class BookingDataProcessorTest extends TestCase
$result = $this->processor->createUpdateRequestPayload($formData);
$this->assertArrayHasKey('bankverbindung', $result['zahlung']);
$this->assertEquals('Test Bank', $result['zahlung']['bankverbindung']['@kreditinstitut']);
$this->assertEquals('DE89370400440532013000', $result['zahlung']['bankverbindung']['@iban']);
self::assertArrayHasKey('bankverbindung', $result['zahlung']);
self::assertEquals('Test Bank', $result['zahlung']['bankverbindung']['@kreditinstitut']);
self::assertEquals('DE89370400440532013000', $result['zahlung']['bankverbindung']['@iban']);
}
public function testBankAccountNotIncludedWhenNull(): void
@@ -205,7 +205,7 @@ class BookingDataProcessorTest extends TestCase
$result = $this->processor->createUpdateRequestPayload($formData);
$this->assertArrayNotHasKey('bankverbindung', $result['zahlung']);
self::assertArrayNotHasKey('bankverbindung', $result['zahlung']);
}
public function testAccommodationRoomsProcessing(): void
@@ -214,13 +214,13 @@ class BookingDataProcessorTest extends TestCase
$result = $this->processor->createUpdateRequestPayload($formData);
$this->assertNotEmpty($result['ferienzielunterbringungen']['ferienzielunterbringung']);
self::assertNotEmpty($result['ferienzielunterbringungen']['ferienzielunterbringung']);
$room = $result['ferienzielunterbringungen']['ferienzielunterbringung'][0];
$this->assertEquals(1, $room['@idzimmer']);
$this->assertEquals('DOUBLE', $room['@kategorie']);
$this->assertEquals('01.01.2024', $room['@anreise']);
$this->assertEquals('07.01.2024', $room['@abreise']);
self::assertEquals(1, $room['@idzimmer']);
self::assertEquals('DOUBLE', $room['@kategorie']);
self::assertEquals('01.01.2024', $room['@anreise']);
self::assertEquals('07.01.2024', $room['@abreise']);
}
public function testCommunicationObjectCreation(): void
@@ -230,8 +230,8 @@ class BookingDataProcessorTest extends TestCase
$this->processor->createUpdateRequestPayload($formData);
$participant = $formData->booking->participants[0];
$this->assertInstanceOf(Communication::class, $participant->communication);
$this->assertEquals('[email protected]', $participant->communication->email);
self::assertInstanceOf(Communication::class, $participant->communication);
self::assertEquals('[email protected]', $participant->communication->email);
}
public function testEmptyPickupsToDoesNotCreateZustiegeSection(): void
@@ -240,8 +240,8 @@ class BookingDataProcessorTest extends TestCase
$result = $this->processor->createUpdateRequestPayload($formData);
$this->assertArrayHasKey('zustiege', $result);
$this->assertSame([], $result['zustiege']);
self::assertArrayHasKey('zustiege', $result);
self::assertSame([], $result['zustiege']);
}
private function createCompleteFormData(): BookingDto
@@ -543,13 +543,13 @@ class BookingDataProcessorTest extends TestCase
// Canceled participant (index 1) should have default names filled
$canceledParticipant = $formData->booking->participants[1];
$this->assertEquals('Teilnehmer:in 2', $canceledParticipant->firstName);
$this->assertEquals('Teilnehmer:in 2', $canceledParticipant->name);
self::assertEquals('Teilnehmer:in 2', $canceledParticipant->firstName);
self::assertEquals('Teilnehmer:in 2', $canceledParticipant->name);
// Active participant (index 0) should retain original names from form
$activeParticipant = $formData->booking->participants[0];
$this->assertEquals('Participant0', $activeParticipant->firstName);
$this->assertEquals('LastName', $activeParticipant->name);
self::assertEquals('Participant0', $activeParticipant->firstName);
self::assertEquals('LastName', $activeParticipant->name);
}
public function testCanceledParticipantNamesNotFilledForNonAgencyBooking(): void
@@ -560,8 +560,8 @@ class BookingDataProcessorTest extends TestCase
// Canceled participant should retain empty names (non-agency booking)
$canceledParticipant = $formData->booking->participants[1];
$this->assertEquals('', $canceledParticipant->firstName);
$this->assertEquals('', $canceledParticipant->name);
self::assertEquals('', $canceledParticipant->firstName);
self::assertEquals('', $canceledParticipant->name);
}
public function testConfirmedParticipantEmptyNamesFilledForAgencyBooking(): void
@@ -572,13 +572,13 @@ class BookingDataProcessorTest extends TestCase
// Confirmed participant (index 1) with empty names should have default names filled
$participant = $formData->booking->participants[1];
$this->assertEquals('Teilnehmer:in 2', $participant->firstName);
$this->assertEquals('Teilnehmer:in 2', $participant->name);
self::assertEquals('Teilnehmer:in 2', $participant->firstName);
self::assertEquals('Teilnehmer:in 2', $participant->name);
// Active participant (index 0) should retain original names from form
$activeParticipant = $formData->booking->participants[0];
$this->assertEquals('Participant0', $activeParticipant->firstName);
$this->assertEquals('LastName', $activeParticipant->name);
self::assertEquals('Participant0', $activeParticipant->firstName);
self::assertEquals('LastName', $activeParticipant->name);
}
public function testConfirmedParticipantPartialEmptyNameFilledForAgencyBooking(): void
@@ -589,8 +589,8 @@ class BookingDataProcessorTest extends TestCase
// Participant with lastName but empty firstName should get default firstName only
$participant = $formData->booking->participants[1];
$this->assertEquals('Teilnehmer:in 2', $participant->firstName);
$this->assertEquals('Schnekenburger', $participant->name);
self::assertEquals('Teilnehmer:in 2', $participant->firstName);
self::assertEquals('Schnekenburger', $participant->name);
}
private function createFormDataWithConfirmedParticipantEmptyNames(): BookingDto
+14 -14
View File
@@ -34,16 +34,16 @@ class BookingTest extends TestCase
// Test: participant 0 should get the ski pass
$result = $booking->getSkiPassForParticipant(0);
$this->assertSame($skiPassService, $result);
$this->assertEquals(123, $result->id);
self::assertSame($skiPassService, $result);
self::assertEquals(123, $result->id);
// Test: participant 1 should get null (no ski pass assigned)
$result = $booking->getSkiPassForParticipant(1);
$this->assertNull($result);
self::assertNull($result);
// Test: participant 2 should get the ski pass
$result = $booking->getSkiPassForParticipant(2);
$this->assertSame($skiPassService, $result);
self::assertSame($skiPassService, $result);
}
public function testGetSkiPassForParticipantReturnsNullWhenNoSkiPasses(): void
@@ -59,7 +59,7 @@ class BookingTest extends TestCase
$booking->additionalServices = [456 => $otherService];
$result = $booking->getSkiPassForParticipant(0);
$this->assertNull($result);
self::assertNull($result);
}
public function testGetSkiPassForParticipantReturnsNullWhenNoServices(): void
@@ -68,7 +68,7 @@ class BookingTest extends TestCase
$booking->additionalServices = [];
$result = $booking->getSkiPassForParticipant(0);
$this->assertNull($result);
self::assertNull($result);
}
public function testGetInsuranceForParticipantReturnsCorrectInsurance(): void
@@ -94,21 +94,21 @@ class BookingTest extends TestCase
// Test: participant 0 should get insurance1
$result = $booking->getInsuranceForParticipant(0);
$this->assertSame($insurance1, $result);
$this->assertEquals(100, $result->id);
self::assertSame($insurance1, $result);
self::assertEquals(100, $result->id);
// Test: participant 1 should get insurance2
$result = $booking->getInsuranceForParticipant(1);
$this->assertSame($insurance2, $result);
$this->assertEquals(200, $result->id);
self::assertSame($insurance2, $result);
self::assertEquals(200, $result->id);
// Test: participant 2 should get insurance1
$result = $booking->getInsuranceForParticipant(2);
$this->assertSame($insurance1, $result);
self::assertSame($insurance1, $result);
// Test: participant 3 should get null (no insurance assigned)
$result = $booking->getInsuranceForParticipant(3);
$this->assertNull($result);
self::assertNull($result);
}
public function testGetInsuranceForParticipantReturnsNullWhenNoInsurances(): void
@@ -117,7 +117,7 @@ class BookingTest extends TestCase
$booking->insurances = [];
$result = $booking->getInsuranceForParticipant(0);
$this->assertNull($result);
self::assertNull($result);
}
public function testGetInsuranceForParticipantHandlesEmptyMapping(): void
@@ -133,6 +133,6 @@ class BookingTest extends TestCase
$booking->insurances = [100 => $insurance];
$result = $booking->getInsuranceForParticipant(0);
$this->assertNull($result, 'Should return null when mapping is empty');
self::assertNull($result, 'Should return null when mapping is empty');
}
}
+8 -8
View File
@@ -41,12 +41,12 @@ class TravelTest extends TestCase
$travel->transportationServices = [$outboundPkw, $inboundPkw];
$outboundResult = $travel->getTransportationServicesByDirection('HIN');
$this->assertCount(1, $outboundResult);
$this->assertSame($outboundPkw, $outboundResult[0]);
self::assertCount(1, $outboundResult);
self::assertSame($outboundPkw, $outboundResult[0]);
$inboundResult = $travel->getTransportationServicesByDirection('RUECK');
$this->assertCount(1, $inboundResult);
$this->assertSame($inboundPkw, $inboundResult[0]);
self::assertCount(1, $inboundResult);
self::assertSame($inboundPkw, $inboundResult[0]);
}
/**
@@ -77,7 +77,7 @@ class TravelTest extends TestCase
$result = $travel->getTransportationServicesByDirection('HIN');
// Both PKW services should be returned (filtering happens at field options provider level)
$this->assertCount(2, $result);
self::assertCount(2, $result);
}
/**
@@ -104,9 +104,9 @@ class TravelTest extends TestCase
$result = $travel->getTransportationServicesByDirection('HIN');
$this->assertCount(2, $result);
self::assertCount(2, $result);
// BUS comes before PKW alphabetically
$this->assertSame('BUS', $result[0]->subType);
$this->assertSame('PKW', $result[1]->subType);
self::assertSame('BUS', $result[0]->subType);
self::assertSame('PKW', $result[1]->subType);
}
}
@@ -15,9 +15,12 @@ class DayTimeUtilityTest extends TestCase
$utility = new DayTimeUtility();
$result = $utility->mapTime($time);
$this->assertEquals($dayTime, $result);
self::assertEquals($dayTime, $result);
}
/**
* @return array<int, array{0: ?string, 1: ?string}>
*/
public function dayTimeProvider(): array
{
return [
@@ -13,15 +13,15 @@ class TravelCodeUtilityTest extends TestCase
$travelCode = 'ABCDEF/010125';
$sanitized = $utility->sanitize($travelCode);
$this->assertEquals('ABCDEF010125', $sanitized);
self::assertEquals('ABCDEF010125', $sanitized);
$travelCode = 'ABCDEF-010125';
$sanitized = $utility->sanitize($travelCode);
$this->assertEquals('ABCDEF010125', $sanitized);
self::assertEquals('ABCDEF010125', $sanitized);
$travelCode = 'abcdef/010125';
$sanitized = $utility->sanitize($travelCode);
$this->assertEquals('ABCDEF010125', $sanitized);
self::assertEquals('ABCDEF010125', $sanitized);
}
public function testGetBaseCode(): void
@@ -30,11 +30,11 @@ class TravelCodeUtilityTest extends TestCase
$travelCode = 'ABCDEF010125';
$baseCode = $utility->getBaseCode($travelCode);
$this->assertEquals('ABCDEF', $baseCode);
self::assertEquals('ABCDEF', $baseCode);
$travelCode = 'abcdef010125';
$baseCode = $utility->getBaseCode($travelCode);
$this->assertEquals('ABCDEF', $baseCode);
self::assertEquals('ABCDEF', $baseCode);
}
public function testGetDate(): void
@@ -43,6 +43,6 @@ class TravelCodeUtilityTest extends TestCase
$travelCode = 'ABCDEF010125';
$date = $utility->getDate($travelCode);
$this->assertEquals('2025-01-01', $date->format('Y-m-d'));
self::assertEquals('2025-01-01', $date->format('Y-m-d'));
}
}
@@ -61,10 +61,10 @@ class PickupLoaderTest extends TestCase
$this->loader->patchPickupsDetails($travel);
// Pickups should be sorted chronologically: 10, 20, 30
$this->assertSame([10, 20, 30], array_keys($travel->pickups));
self::assertSame([10, 20, 30], array_keys($travel->pickups));
// Drop-offs should be in reverse order: 30, 20, 10
$this->assertSame([30, 20, 10], array_keys($travel->dropOffs));
self::assertSame([30, 20, 10], array_keys($travel->dropOffs));
}
public function testDropOffsNotInPickupsAreAppendedAtEnd(): void
@@ -94,7 +94,7 @@ class PickupLoaderTest extends TestCase
$this->loader->patchPickupsDetails($travel);
// Drop-offs: reversed pickups (20, 10), then unmatched (99)
$this->assertSame([20, 10, 99], array_keys($travel->dropOffs));
self::assertSame([20, 10, 99], array_keys($travel->dropOffs));
}
public function testDropOffsWithTimeDataAreSortedChronologically(): void
@@ -133,6 +133,6 @@ class PickupLoaderTest extends TestCase
$this->loader->patchPickupsDetails($travel);
// Drop-offs should be sorted by time, not by reversed pickup order
$this->assertSame([30, 20, 10], array_keys($travel->dropOffs));
self::assertSame([30, 20, 10], array_keys($travel->dropOffs));
}
}
+24 -24
View File
@@ -45,25 +45,25 @@ class AgencyParserTest extends TestCase
$resultNode = $crawler->filterXPath('//ergebnis');
$agencies = $this->parser->parse($resultNode);
$this->assertCount(2, $agencies);
self::assertCount(2, $agencies);
// Test first agency (complete data)
$this->assertEquals(124487, $agencies[0]->id);
$this->assertEquals('ADAC Hansa e.V.', $agencies[0]->name);
$this->assertEquals('295', $agencies[0]->code);
$this->assertEquals('Musterstr. 123', $agencies[0]->street);
$this->assertEquals('99999', $agencies[0]->postCode);
$this->assertEquals('Musterort', $agencies[0]->city);
$this->assertEquals('0361-442930', $agencies[0]->phone);
self::assertEquals(124487, $agencies[0]->id);
self::assertEquals('ADAC Hansa e.V.', $agencies[0]->name);
self::assertEquals('295', $agencies[0]->code);
self::assertEquals('Musterstr. 123', $agencies[0]->street);
self::assertEquals('99999', $agencies[0]->postCode);
self::assertEquals('Musterort', $agencies[0]->city);
self::assertEquals('0361-442930', $agencies[0]->phone);
// Test second agency (missing phone)
$this->assertEquals(75861, $agencies[1]->id);
$this->assertEquals('ADAC im Fördepark', $agencies[1]->name);
$this->assertEquals('103', $agencies[1]->code);
$this->assertEquals('Sebastianusstr. 24', $agencies[1]->street);
$this->assertEquals('41468', $agencies[1]->postCode);
$this->assertEquals('Neuss', $agencies[1]->city);
$this->assertNull($agencies[1]->phone);
self::assertEquals(75861, $agencies[1]->id);
self::assertEquals('ADAC im Fördepark', $agencies[1]->name);
self::assertEquals('103', $agencies[1]->code);
self::assertEquals('Sebastianusstr. 24', $agencies[1]->street);
self::assertEquals('41468', $agencies[1]->postCode);
self::assertEquals('Neuss', $agencies[1]->city);
self::assertNull($agencies[1]->phone);
}
public function testParseMinimalAgency(): void
@@ -83,14 +83,14 @@ class AgencyParserTest extends TestCase
$resultNode = $crawler->filterXPath('//ergebnis');
$agencies = $this->parser->parse($resultNode);
$this->assertCount(1, $agencies);
$this->assertEquals(12345, $agencies[0]->id);
$this->assertEquals('Test Agency', $agencies[0]->name);
$this->assertEquals('001', $agencies[0]->code);
$this->assertNull($agencies[0]->street);
$this->assertNull($agencies[0]->postCode);
$this->assertNull($agencies[0]->city);
$this->assertNull($agencies[0]->phone);
self::assertCount(1, $agencies);
self::assertEquals(12345, $agencies[0]->id);
self::assertEquals('Test Agency', $agencies[0]->name);
self::assertEquals('001', $agencies[0]->code);
self::assertNull($agencies[0]->street);
self::assertNull($agencies[0]->postCode);
self::assertNull($agencies[0]->city);
self::assertNull($agencies[0]->phone);
}
public function testParseEmptyAgenciesList(): void
@@ -106,6 +106,6 @@ class AgencyParserTest extends TestCase
$resultNode = $crawler->filterXPath('//ergebnis');
$agencies = $this->parser->parse($resultNode);
$this->assertCount(0, $agencies);
self::assertCount(0, $agencies);
}
}
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\Tests\BusProNet\XmlParser;
use App\BusProNet\Model\Insurance;
use App\BusProNet\XmlParser\BookingInsurancesParser;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DomCrawler\Crawler;
@@ -28,15 +29,15 @@ XML;
$parser = new BookingInsurancesParser();
$insurances = $parser->parse($insurancesData);
$this->assertCount(1, $insurances);
$this->assertArrayHasKey(177240, $insurances);
$insurance = $insurances[177240];
$this->assertEquals(177240, $insurance->id);
$this->assertEquals('Reiseschutz Platin Auto/Bahn/Bus (Europa)', $insurance->label);
$this->assertEquals(45.0, $insurance->price);
$this->assertEquals([0], $insurance->mapping); // zuordnung="1" maps to participant index 0
$this->assertEquals([0 => 45.0], $insurance->individualPrice);
self::assertCount(1, $insurances);
$insuranceValues = array_values($insurances);
$insurance = $insuranceValues[0] ?? null;
self::assertInstanceOf(Insurance::class, $insurance);
self::assertEquals(177240, $insurance->id);
self::assertEquals('Reiseschutz Platin Auto/Bahn/Bus (Europa)', $insurance->label);
self::assertEquals(45.0, $insurance->price);
self::assertEquals([0], $insurance->mapping); // zuordnung="1" maps to participant index 0
self::assertEquals([0 => 45.0], $insurance->individualPrice);
}
public function testParseMultipleInsurances(): void
@@ -59,23 +60,36 @@ XML;
$parser = new BookingInsurancesParser();
$insurances = $parser->parse($insurancesData);
$this->assertCount(2, $insurances);
self::assertCount(2, $insurances);
/** @var Insurance|null $insurance1 */
$insurance1 = null;
/** @var Insurance|null $insurance2 */
$insurance2 = null;
foreach ($insurances as $insurance) {
if ('100' === (string) $insurance->id) {
$insurance1 = $insurance;
}
if ('200' === (string) $insurance->id) {
$insurance2 = $insurance;
}
}
// First insurance
$insurance1 = $insurances[100];
$this->assertEquals(100, $insurance1->id);
$this->assertEquals('Insurance A', $insurance1->label);
$this->assertEquals(45.0, $insurance1->price);
$this->assertEquals([0], $insurance1->mapping); // zuordnung="1" maps to index 0
$this->assertEquals([0 => 45.0], $insurance1->individualPrice);
self::assertInstanceOf(Insurance::class, $insurance1);
self::assertEquals(100, $insurance1->id);
self::assertEquals('Insurance A', $insurance1->label);
self::assertEquals(45.0, $insurance1->price);
self::assertEquals([0], $insurance1->mapping); // zuordnung="1" maps to index 0
self::assertEquals([0 => 45.0], $insurance1->individualPrice);
// Second insurance
$insurance2 = $insurances[200];
$this->assertEquals(200, $insurance2->id);
$this->assertEquals('Insurance B', $insurance2->label);
$this->assertEquals(30.0, $insurance2->price);
$this->assertEquals([1], $insurance2->mapping); // zuordnung="2" maps to index 1
$this->assertEquals([1 => 30.0], $insurance2->individualPrice);
self::assertInstanceOf(Insurance::class, $insurance2);
self::assertEquals(200, $insurance2->id);
self::assertEquals('Insurance B', $insurance2->label);
self::assertEquals(30.0, $insurance2->price);
self::assertEquals([1], $insurance2->mapping); // zuordnung="2" maps to index 1
self::assertEquals([1 => 30.0], $insurance2->individualPrice);
}
public function testParseEmptyInsurancesReturnsEmptyArray(): void
@@ -94,7 +108,7 @@ XML;
$parser = new BookingInsurancesParser();
$insurances = $parser->parse($insurancesData);
$this->assertCount(0, $insurances);
$this->assertIsArray($insurances);
self::assertCount(0, $insurances);
self::assertIsArray($insurances);
}
}
@@ -37,17 +37,17 @@ class BookingResponseParserTest extends TestCase
$crawler = new Crawler($xmlContent);
$response = $this->parser->parse($crawler->filter('ergebnis'));
$this->assertTrue($response->isInquiryValid());
$this->assertEquals(321530, $response->bookingNumber);
$this->assertEquals(755.0, $response->totalPrice);
self::assertTrue($response->isInquiryValid());
self::assertEquals(321530, $response->bookingNumber);
self::assertEquals(755.0, $response->totalPrice);
// Verify purchase voucher is parsed
$this->assertNotNull($response->paymentTerms);
$this->assertCount(1, $response->paymentTerms->appliedPurchaseVouchers);
$this->assertEquals('G1263', $response->paymentTerms->appliedPurchaseVouchers[0]['nummer']);
$this->assertEquals(100.0, $response->paymentTerms->appliedPurchaseVouchers[0]['betrag']);
$this->assertEquals(100.0, $response->paymentTerms->getPurchaseVoucherDiscount());
$this->assertEquals(655.0, $response->paymentTerms->finalPaymentAmount);
self::assertNotNull($response->paymentTerms);
self::assertCount(1, $response->paymentTerms->appliedPurchaseVouchers);
self::assertEquals('G1263', $response->paymentTerms->appliedPurchaseVouchers[0]['nummer']);
self::assertEquals(100.0, $response->paymentTerms->appliedPurchaseVouchers[0]['betrag']);
self::assertEquals(100.0, $response->paymentTerms->getPurchaseVoucherDiscount());
self::assertEquals(655.0, $response->paymentTerms->finalPaymentAmount);
}
public function testParseBookingResponseWithPromotionalVoucher(): void
@@ -70,21 +70,21 @@ class BookingResponseParserTest extends TestCase
$crawler = new Crawler($xmlContent);
$response = $this->parser->parse($crawler->filter('ergebnis'));
$this->assertTrue($response->isInquiryValid());
$this->assertEquals(615.2, $response->totalPrice);
self::assertTrue($response->isInquiryValid());
self::assertEquals(615.2, $response->totalPrice);
// Verify price items include promotional voucher
$this->assertCount(2, $response->priceItems);
self::assertCount(2, $response->priceItems);
$voucherItem = $response->priceItems[1];
$this->assertEquals('AKTION', $voucherItem->type);
$this->assertEquals('TESTERINO1', $voucherItem->label);
$this->assertEquals(-100.0, $voucherItem->totalPrice);
self::assertEquals('AKTION', $voucherItem->type);
self::assertEquals('TESTERINO1', $voucherItem->label);
self::assertEquals(-100.0, $voucherItem->totalPrice);
// Verify voucher discount extraction
$voucherDiscounts = $response->getVoucherDiscountsFromPrices();
$this->assertCount(1, $voucherDiscounts);
$this->assertEquals(100.0, $response->getVoucherDiscountFromPrices());
$this->assertEquals(100.0, $response->getTotalVoucherDiscount());
self::assertCount(1, $voucherDiscounts);
self::assertEquals(100.0, $response->getVoucherDiscountFromPrices());
self::assertEquals(100.0, $response->getTotalVoucherDiscount());
}
public function testParseBookingResponseWithGoodwillVoucher(): void
@@ -105,20 +105,20 @@ class BookingResponseParserTest extends TestCase
$crawler = new Crawler($xmlContent);
$response = $this->parser->parse($crawler->filter('ergebnis'));
$this->assertTrue($response->isInquiryValid());
$this->assertEquals(0.0, $response->totalPrice);
self::assertTrue($response->isInquiryValid());
self::assertEquals(0.0, $response->totalPrice);
// Verify goodwill voucher is parsed
$voucherDiscounts = $response->getVoucherDiscountsFromPrices();
$this->assertCount(1, $voucherDiscounts);
self::assertCount(1, $voucherDiscounts);
$goodwillVoucher = array_values($voucherDiscounts)[0];
$this->assertEquals('KULANZGUTSCHEIN', $goodwillVoucher->type);
$this->assertEquals('Kulanzgutschein K1904', $goodwillVoucher->label);
$this->assertEquals(-679.0, $goodwillVoucher->totalPrice);
self::assertEquals('KULANZGUTSCHEIN', $goodwillVoucher->type);
self::assertEquals('Kulanzgutschein K1904', $goodwillVoucher->label);
self::assertEquals(-679.0, $goodwillVoucher->totalPrice);
$this->assertEquals(679.0, $response->getVoucherDiscountFromPrices());
$this->assertEquals(679.0, $response->getTotalVoucherDiscount());
self::assertEquals(679.0, $response->getVoucherDiscountFromPrices());
self::assertEquals(679.0, $response->getTotalVoucherDiscount());
}
public function testParseBookingResponseWithMultipleVouchers(): void
@@ -144,13 +144,13 @@ class BookingResponseParserTest extends TestCase
$response = $this->parser->parse($crawler->filter('ergebnis'));
// Verify all voucher types are parsed
$this->assertEquals(80.0, $response->getVoucherDiscountFromPrices()); // 50 + 30
$this->assertEquals(100.0, $response->getPurchaseVoucherDiscount());
$this->assertEquals(180.0, $response->getTotalVoucherDiscount()); // 50 + 30 + 100
self::assertEquals(80.0, $response->getVoucherDiscountFromPrices()); // 50 + 30
self::assertEquals(100.0, $response->getPurchaseVoucherDiscount());
self::assertEquals(180.0, $response->getTotalVoucherDiscount()); // 50 + 30 + 100
// Verify price item vouchers
$voucherDiscounts = $response->getVoucherDiscountsFromPrices();
$this->assertCount(2, $voucherDiscounts);
self::assertCount(2, $voucherDiscounts);
}
public function testParseBookingResponseWithNoVouchers(): void
@@ -172,14 +172,14 @@ class BookingResponseParserTest extends TestCase
$crawler = new Crawler($xmlContent);
$response = $this->parser->parse($crawler->filter('ergebnis'));
$this->assertTrue($response->isInquiryValid());
$this->assertEquals(679.0, $response->totalPrice);
self::assertTrue($response->isInquiryValid());
self::assertEquals(679.0, $response->totalPrice);
// Verify no voucher discounts
$this->assertCount(0, $response->getVoucherDiscountsFromPrices());
$this->assertEquals(0.0, $response->getVoucherDiscountFromPrices());
$this->assertEquals(0.0, $response->getPurchaseVoucherDiscount());
$this->assertEquals(0.0, $response->getTotalVoucherDiscount());
self::assertCount(0, $response->getVoucherDiscountsFromPrices());
self::assertEquals(0.0, $response->getVoucherDiscountFromPrices());
self::assertEquals(0.0, $response->getPurchaseVoucherDiscount());
self::assertEquals(0.0, $response->getTotalVoucherDiscount());
}
public function testParseBookingResponseWithMultiplePurchaseVouchers(): void
@@ -204,10 +204,10 @@ class BookingResponseParserTest extends TestCase
$response = $this->parser->parse($crawler->filter('ergebnis'));
// Verify multiple purchase vouchers are parsed
$this->assertNotNull($response->paymentTerms);
$this->assertCount(2, $response->paymentTerms->appliedPurchaseVouchers);
$this->assertEquals(125.0, $response->paymentTerms->getPurchaseVoucherDiscount()); // 50 + 75
$this->assertEquals(125.0, $response->getTotalVoucherDiscount());
self::assertNotNull($response->paymentTerms);
self::assertCount(2, $response->paymentTerms->appliedPurchaseVouchers);
self::assertEquals(125.0, $response->paymentTerms->getPurchaseVoucherDiscount()); // 50 + 75
self::assertEquals(125.0, $response->getTotalVoucherDiscount());
}
public function testParseBookingResponseWithGruppenrabatt(): void
@@ -231,24 +231,24 @@ class BookingResponseParserTest extends TestCase
$crawler = new Crawler($xmlContent);
$response = $this->parser->parse($crawler->filter('ergebnis'));
$this->assertTrue($response->isInquiryValid());
$this->assertEquals(3972.0, $response->totalPrice);
self::assertTrue($response->isInquiryValid());
self::assertEquals(3972.0, $response->totalPrice);
// Verify Gruppenrabatt is NOT counted as voucher discount
$this->assertCount(0, $response->getVoucherDiscountsFromPrices());
$this->assertEquals(0.0, $response->getVoucherDiscountFromPrices());
self::assertCount(0, $response->getVoucherDiscountsFromPrices());
self::assertEquals(0.0, $response->getVoucherDiscountFromPrices());
// Verify Gruppenrabatt IS counted as API-applied discount
$apiAppliedDiscounts = $response->getApiAppliedDiscounts();
$this->assertCount(1, $apiAppliedDiscounts);
self::assertCount(1, $apiAppliedDiscounts);
$gruppenrabatt = array_values($apiAppliedDiscounts)[0];
$this->assertEquals('ERM', $gruppenrabatt->type);
$this->assertEquals('GRU', $gruppenrabatt->subType);
$this->assertEquals('Gruppenrabatt', $gruppenrabatt->label);
$this->assertEquals(-90.0, $gruppenrabatt->totalPrice);
self::assertEquals('ERM', $gruppenrabatt->type);
self::assertEquals('GRU', $gruppenrabatt->subType);
self::assertEquals('Gruppenrabatt', $gruppenrabatt->label);
self::assertEquals(-90.0, $gruppenrabatt->totalPrice);
$this->assertEquals(90.0, $response->getApiAppliedDiscountTotal());
self::assertEquals(90.0, $response->getApiAppliedDiscountTotal());
}
public function testParseBookingResponseWithGruppenrabattAndVouchers(): void
@@ -273,20 +273,20 @@ class BookingResponseParserTest extends TestCase
$response = $this->parser->parse($crawler->filter('ergebnis'));
// Voucher discount should only include AKTION
$this->assertEquals(20.0, $response->getVoucherDiscountFromPrices());
self::assertEquals(20.0, $response->getVoucherDiscountFromPrices());
// API-applied discount should only include ERM (Gruppenrabatt)
$this->assertEquals(50.0, $response->getApiAppliedDiscountTotal());
self::assertEquals(50.0, $response->getApiAppliedDiscountTotal());
// Verify they are separate and don't overlap
$voucherDiscounts = $response->getVoucherDiscountsFromPrices();
$apiDiscounts = $response->getApiAppliedDiscounts();
$this->assertCount(1, $voucherDiscounts);
$this->assertCount(1, $apiDiscounts);
self::assertCount(1, $voucherDiscounts);
self::assertCount(1, $apiDiscounts);
$this->assertEquals('AKTION', array_values($voucherDiscounts)[0]->type);
$this->assertEquals('ERM', array_values($apiDiscounts)[0]->type);
self::assertEquals('AKTION', array_values($voucherDiscounts)[0]->type);
self::assertEquals('ERM', array_values($apiDiscounts)[0]->type);
}
public function testParseBookingResponseWithNoApiAppliedDiscounts(): void
@@ -309,8 +309,8 @@ class BookingResponseParserTest extends TestCase
$response = $this->parser->parse($crawler->filter('ergebnis'));
// Verify no API-applied discounts
$this->assertCount(0, $response->getApiAppliedDiscounts());
$this->assertEquals(0.0, $response->getApiAppliedDiscountTotal());
self::assertCount(0, $response->getApiAppliedDiscounts());
self::assertEquals(0.0, $response->getApiAppliedDiscountTotal());
}
public function testParseBookingResponseWithTransportationDiscountNotCountedAsApiApplied(): void
@@ -336,16 +336,16 @@ class BookingResponseParserTest extends TestCase
$crawler = new Crawler($xmlContent);
$response = $this->parser->parse($crawler->filter('ergebnis'));
$this->assertTrue($response->isInquiryValid());
$this->assertEquals(1682.0, $response->totalPrice);
self::assertTrue($response->isInquiryValid());
self::assertEquals(1682.0, $response->totalPrice);
// Transportation discount (BEF with negative price) should NOT be counted as API-applied discount
// because it's already handled by the local price calculator
$this->assertCount(0, $response->getApiAppliedDiscounts());
$this->assertEquals(0.0, $response->getApiAppliedDiscountTotal());
self::assertCount(0, $response->getApiAppliedDiscounts());
self::assertEquals(0.0, $response->getApiAppliedDiscountTotal());
// Verify no voucher discounts either
$this->assertEquals(0.0, $response->getVoucherDiscountFromPrices());
self::assertEquals(0.0, $response->getVoucherDiscountFromPrices());
}
public function testParseBookingResponseWithBothTransportationAndGruppenrabatt(): void
@@ -372,13 +372,13 @@ class BookingResponseParserTest extends TestCase
// Only ERM (Gruppenrabatt) should be counted as API-applied discount
// BEF transportation discount should NOT be counted
$apiAppliedDiscounts = $response->getApiAppliedDiscounts();
$this->assertCount(1, $apiAppliedDiscounts);
self::assertCount(1, $apiAppliedDiscounts);
$gruppenrabatt = array_values($apiAppliedDiscounts)[0];
$this->assertEquals('ERM', $gruppenrabatt->type);
$this->assertEquals(-100.0, $gruppenrabatt->totalPrice);
self::assertEquals('ERM', $gruppenrabatt->type);
self::assertEquals(-100.0, $gruppenrabatt->totalPrice);
// Total API-applied discount should only include Gruppenrabatt (100), not transportation (300)
$this->assertEquals(100.0, $response->getApiAppliedDiscountTotal());
self::assertEquals(100.0, $response->getApiAppliedDiscountTotal());
}
}
@@ -40,60 +40,60 @@ class InsuranceParserTest extends TestCase
$insurances = $this->parser->parse($crawler);
// Test all insurances are included (2 regular + 1 complementary + 1 package = 4 total)
$this->assertCount(4, $insurances);
self::assertCount(4, $insurances);
// Test travel cancellation insurance (RRV)
$cancellationInsurance = $insurances[178917];
$this->assertEquals(178917, $cancellationInsurance->id);
$this->assertEquals('903100', $cancellationInsurance->code);
$this->assertEquals('Reise-Rücktritt', $cancellationInsurance->label);
$this->assertEquals('RRV', $cancellationInsurance->subType);
$this->assertEquals(5.0, $cancellationInsurance->price);
$this->assertFalse($cancellationInsurance->familyInsurance);
$this->assertFalse($cancellationInsurance->package);
$this->assertFalse($cancellationInsurance->complementary);
$cancellationInsurance = $insurances['178917'];
self::assertEquals(178917, $cancellationInsurance->id);
self::assertEquals('903100', $cancellationInsurance->code);
self::assertEquals('Reise-Rücktritt', $cancellationInsurance->label);
self::assertEquals('RRV', $cancellationInsurance->subType);
self::assertEquals(5.0, $cancellationInsurance->price);
self::assertFalse($cancellationInsurance->familyInsurance);
self::assertFalse($cancellationInsurance->package);
self::assertFalse($cancellationInsurance->complementary);
// Test travel protection insurance (PAK) with family flag
$protectionInsurance = $insurances[177236];
$this->assertEquals(177236, $protectionInsurance->id);
$this->assertEquals('913320', $protectionInsurance->code);
$this->assertEquals('Reiseschutz Platin', $protectionInsurance->label); // "Auto/Bahn/Bus (Europa)" is normalized away
$this->assertEquals('PAK', $protectionInsurance->subType);
$this->assertEquals(9.0, $protectionInsurance->price);
$this->assertTrue($protectionInsurance->familyInsurance);
$this->assertFalse($protectionInsurance->package);
$this->assertFalse($protectionInsurance->complementary);
$protectionInsurance = $insurances['177236'];
self::assertEquals(177236, $protectionInsurance->id);
self::assertEquals('913320', $protectionInsurance->code);
self::assertEquals('Reiseschutz Platin', $protectionInsurance->label); // "Auto/Bahn/Bus (Europa)" is normalized away
self::assertEquals('PAK', $protectionInsurance->subType);
self::assertEquals(9.0, $protectionInsurance->price);
self::assertTrue($protectionInsurance->familyInsurance);
self::assertFalse($protectionInsurance->package);
self::assertFalse($protectionInsurance->complementary);
// Test deductible insurance (OHN) - IS included but marked as complementary
$deductibleInsurance = $insurances[177270];
$this->assertEquals(177270, $deductibleInsurance->id);
$this->assertEquals('903551', $deductibleInsurance->code);
$this->assertEquals('Selbstbehaltübernahme', $deductibleInsurance->label);
$this->assertEquals('OHN', $deductibleInsurance->subType);
$this->assertEquals(5.0, $deductibleInsurance->price);
$this->assertFalse($deductibleInsurance->familyInsurance);
$this->assertFalse($deductibleInsurance->package);
$this->assertTrue($deductibleInsurance->complementary); // Marked as complementary
$deductibleInsurance = $insurances['177270'];
self::assertEquals(177270, $deductibleInsurance->id);
self::assertEquals('903551', $deductibleInsurance->code);
self::assertEquals('Selbstbehaltübernahme', $deductibleInsurance->label);
self::assertEquals('OHN', $deductibleInsurance->subType);
self::assertEquals(5.0, $deductibleInsurance->price);
self::assertFalse($deductibleInsurance->familyInsurance);
self::assertFalse($deductibleInsurance->package);
self::assertTrue($deductibleInsurance->complementary); // Marked as complementary
// Test package - should be family insurance because it contains a family insurance (177236)
$package = $insurances['P1000320'];
$this->assertEquals('P1000320', $package->id);
$this->assertEquals('Reiseschutz Platin + Selbstbehaltübernahme', $package->label); // "Auto/Bahn/Bus (Europa)" is normalized away
$this->assertNull($package->subType); // Packages don't have subtypes
$this->assertEquals(14.0, $package->price);
$this->assertTrue($package->familyInsurance); // Should be true because it contains family insurance 177236
$this->assertTrue($package->package);
$this->assertEquals([177236, 177270], $package->containedInsuranceIds);
self::assertEquals('P1000320', $package->id);
self::assertEquals('Reiseschutz Platin + Selbstbehaltübernahme', $package->label); // "Auto/Bahn/Bus (Europa)" is normalized away
self::assertNull($package->subType); // Packages don't have subtypes
self::assertEquals(14.0, $package->price);
self::assertTrue($package->familyInsurance); // Should be true because it contains family insurance 177236
self::assertTrue($package->package);
self::assertEquals(['177236', '177270'], $package->containedInsuranceIds);
// Test containedInsurances array is populated with actual Insurance objects
$this->assertCount(2, $package->containedInsurances);
$this->assertEquals(177236, $package->containedInsurances[0]->id);
$this->assertEquals(177270, $package->containedInsurances[1]->id);
self::assertCount(2, $package->containedInsurances);
self::assertEquals(177236, $package->containedInsurances[0]->id);
self::assertEquals(177270, $package->containedInsurances[1]->id);
// Test URL aggregation from contained insurances
$this->assertEquals(['https://example.com/info2', 'https://example.com/info3'], $package->getAllUrlsInfo());
$this->assertEquals(['https://example.com/product2', 'https://example.com/product3'], $package->getAllUrlsProductInfo());
$this->assertEquals(['https://example.com/terms2', 'https://example.com/terms3'], $package->getAllUrlsTerms());
self::assertEquals(['https://example.com/info2', 'https://example.com/info3'], $package->getAllUrlsInfo());
self::assertEquals(['https://example.com/product2', 'https://example.com/product3'], $package->getAllUrlsProductInfo());
self::assertEquals(['https://example.com/terms2', 'https://example.com/terms3'], $package->getAllUrlsTerms());
}
public function testParsePackageWithoutSubtype(): void
@@ -115,14 +115,14 @@ class InsuranceParserTest extends TestCase
$crawler = new Crawler($xmlContent);
$insurances = $this->parser->parse($crawler);
$this->assertCount(2, $insurances);
self::assertCount(2, $insurances);
// Test package has no subType but has familyInsurance flag
$package = $insurances['P1000320'];
$this->assertEquals('P1000320', $package->id);
$this->assertNull($package->subType);
$this->assertTrue($package->familyInsurance);
$this->assertTrue($package->package);
self::assertEquals('P1000320', $package->id);
self::assertNull($package->subType);
self::assertTrue($package->familyInsurance);
self::assertTrue($package->package);
}
public function testParseInsuranceWithNullSubtype(): void
@@ -137,12 +137,12 @@ class InsuranceParserTest extends TestCase
$crawler = new Crawler($xmlContent);
$insurances = $this->parser->parse($crawler);
$this->assertCount(1, $insurances);
self::assertCount(1, $insurances);
$insurance = $insurances[178917];
$this->assertEquals(178917, $insurance->id);
$this->assertNull($insurance->subType); // Missing unterart attribute should result in null
$this->assertFalse($insurance->package);
$insurance = $insurances['178917'];
self::assertEquals(178917, $insurance->id);
self::assertNull($insurance->subType); // Missing unterart attribute should result in null
self::assertFalse($insurance->package);
}
public function testParseEmptyXml(): void
@@ -158,7 +158,7 @@ class InsuranceParserTest extends TestCase
$crawler = new Crawler($xmlContent);
$insurances = $this->parser->parse($crawler);
$this->assertEmpty($insurances);
self::assertEmpty($insurances);
}
public function testParseZusatzversicherungFiltering(): void
@@ -183,15 +183,15 @@ class InsuranceParserTest extends TestCase
$insurances = $this->parser->parse($crawler);
// Should include: normal insurance (178917), both complementary insurances (177270, 999999), and package (P1000320)
$this->assertCount(4, $insurances);
$this->assertArrayHasKey(178917, $insurances);
$this->assertArrayHasKey(177270, $insurances);
$this->assertArrayHasKey(999999, $insurances);
$this->assertArrayHasKey('P1000320', $insurances);
self::assertCount(4, $insurances);
self::assertArrayHasKey('178917', $insurances);
self::assertArrayHasKey('177270', $insurances);
self::assertArrayHasKey('999999', $insurances);
self::assertArrayHasKey('P1000320', $insurances);
// Verify complementary flags
$this->assertFalse($insurances[178917]->complementary); // Normal insurance
$this->assertTrue($insurances[177270]->complementary); // Complementary insurance
$this->assertTrue($insurances[999999]->complementary); // Complementary insurance
self::assertFalse($insurances['178917']->complementary); // Normal insurance
self::assertTrue($insurances['177270']->complementary); // Complementary insurance
self::assertTrue($insurances['999999']->complementary); // Complementary insurance
}
}