wip: major refactoring

This commit is contained in:
Björn Fromme
2025-07-25 11:54:07 +02:00
parent ae2ed306b9
commit e7f0c09b36
32 changed files with 692 additions and 466 deletions
@@ -36,16 +36,16 @@ class BookingDataProcessorTest extends TestCase
public function testCreateUpdateRequestPayloadWithCompleteData(): void
{
$formData = $this->createCompleteFormData();
$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);
$this->assertEquals(123, $result['idbuchung']);
$this->assertEquals('ACTIVE', $result['status']);
$this->assertCount(2, $result['teilnehmerliste']['teilnehmer']);
@@ -54,9 +54,9 @@ class BookingDataProcessorTest extends TestCase
public function testCanceledParticipantsAreSkipped(): void
{
$formData = $this->createFormDataWithCanceledParticipant();
$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']);
@@ -65,12 +65,12 @@ class BookingDataProcessorTest extends TestCase
public function testAdditionalServicesProcessing(): void
{
$formData = $this->createFormDataWithAdditionalServices();
$result = $this->processor->createUpdateRequestPayload($formData);
$this->assertNotEmpty($result['zusatzleistungen']['zusatzleistung']);
$this->assertCount(2, $result['zusatzleistungen']['zusatzleistung']);
$service = $result['zusatzleistungen']['zusatzleistung'][0];
$this->assertEquals(1, $service['@idleistung']);
$this->assertEquals(1, $service['@anzahl']);
@@ -80,9 +80,9 @@ class BookingDataProcessorTest extends TestCase
public function testTransportationServicesProcessing(): void
{
$formData = $this->createFormDataWithTransportation();
$result = $this->processor->createUpdateRequestPayload($formData);
$this->assertNotEmpty($result['beförderungen']['beförderung']);
$this->assertCount(2, $result['beförderungen']['beförderung']);
}
@@ -90,9 +90,9 @@ class BookingDataProcessorTest extends TestCase
public function testBusPickupLocationsProcessing(): void
{
$formData = $this->createFormDataWithBusPickup();
$result = $this->processor->createUpdateRequestPayload($formData);
$this->assertArrayHasKey('zustiege', $result);
$this->assertNotEmpty($result['zustiege']['zustieg']);
$this->assertEquals(1, $result['zustiege']['zustieg'][0]['@idzustieg']);
@@ -101,18 +101,18 @@ class BookingDataProcessorTest extends TestCase
public function testNonBusTransportationSkipsPickup(): void
{
$formData = $this->createFormDataWithNonBusTransportation();
$result = $this->processor->createUpdateRequestPayload($formData);
$this->assertArrayNotHasKey('zustiege', $result);
}
public function testUnusedServicesAreRemoved(): void
{
$formData = $this->createFormDataWithUnusedServices();
$result = $this->processor->createUpdateRequestPayload($formData);
$this->assertEmpty($result['zusatzleistungen']['zusatzleistung']);
$this->assertEmpty($result['beförderungen']['beförderung']);
}
@@ -120,9 +120,9 @@ class BookingDataProcessorTest extends TestCase
public function testParticipantPersonalDataUpdate(): void
{
$formData = $this->createFormDataWithUpdatedPersonalData();
$this->processor->createUpdateRequestPayload($formData);
$participant = $formData->booking->participants[0];
$this->assertEquals('Updated', $participant->firstName);
$this->assertEquals('Participant', $participant->name);
@@ -133,9 +133,9 @@ class BookingDataProcessorTest extends TestCase
public function testInactiveParticipantsPersonalDataNotUpdated(): void
{
$formData = $this->createFormDataWithInactiveParticipant();
$this->processor->createUpdateRequestPayload($formData);
$participant = $formData->booking->participants[0];
$this->assertEquals('Original', $participant->firstName);
$this->assertEquals('Name', $participant->name);
@@ -144,12 +144,12 @@ class BookingDataProcessorTest extends TestCase
public function testApplicantDataSyncWithFirstParticipant(): void
{
$formData = $this->createFormDataForApplicantSync();
$this->processor->createUpdateRequestPayload($formData);
$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);
@@ -158,9 +158,9 @@ class BookingDataProcessorTest extends TestCase
public function testBankAccountIncludedInPayload(): void
{
$formData = $this->createFormDataWithBankAccount();
$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']);
@@ -169,20 +169,20 @@ class BookingDataProcessorTest extends TestCase
public function testBankAccountNotIncludedWhenNull(): void
{
$formData = $this->createFormDataWithoutBankAccount();
$result = $this->processor->createUpdateRequestPayload($formData);
$this->assertArrayNotHasKey('bankverbindung', $result['zahlung']);
}
public function testAccommodationRoomsProcessing(): void
{
$formData = $this->createFormDataWithRooms();
$result = $this->processor->createUpdateRequestPayload($formData);
$this->assertNotEmpty($result['ferienzielunterbringungen']['ferienzielunterbringung']);
$room = $result['ferienzielunterbringungen']['ferienzielunterbringung'][0];
$this->assertEquals(1, $room['@idzimmer']);
$this->assertEquals('DOUBLE', $room['@kategorie']);
@@ -193,9 +193,9 @@ class BookingDataProcessorTest extends TestCase
public function testCommunicationObjectCreation(): void
{
$formData = $this->createFormDataWithoutExistingCommunication();
$this->processor->createUpdateRequestPayload($formData);
$participant = $formData->booking->participants[0];
$this->assertInstanceOf(Communication::class, $participant->communication);
$this->assertEquals('[email protected]', $participant->communication->email);
@@ -204,150 +204,144 @@ class BookingDataProcessorTest extends TestCase
public function testEmptyPickupsToDoesNotCreateZustiegeSection(): void
{
$formData = $this->createFormDataWithoutPickups();
$result = $this->processor->createUpdateRequestPayload($formData);
$this->assertArrayNotHasKey('zustiege', $result);
}
private function createCompleteFormData(): BookingEditDto
{
$formData = new BookingEditDto();
$formData->booking = $this->createMockBooking();
$formData->travel = $this->createMockTravel();
$formData = new BookingEditDto($this->createMockBooking(), $this->createMockTravel());
$formData->participants = [
$this->createMockParticipantDto(0, 'F'),
$this->createMockParticipantDto(1, 'F'),
];
return $formData;
}
private function createFormDataWithCanceledParticipant(): BookingEditDto
{
$formData = new BookingEditDto();
$formData->booking = $this->createMockBooking();
$formData->travel = $this->createMockTravel();
$formData = new BookingEditDto($this->createMockBooking(), $this->createMockTravel());
$formData->participants = [
$this->createMockParticipantDto(0, 'F'),
$this->createMockParticipantDto(1, 'S'), // Canceled
];
return $formData;
}
private function createFormDataWithAdditionalServices(): BookingEditDto
{
$formData = $this->createCompleteFormData();
$participant = $formData->participants[0];
$participant->courses = [$this->createMockService(1)];
$participant->additionalServices = [$this->createMockService(2)];
return $formData;
}
private function createFormDataWithTransportation(): BookingEditDto
{
$formData = $this->createCompleteFormData();
$participant = $formData->participants[0];
$participant->transportationServiceTo = $this->createMockService(1);
$participant->transportationServiceFro = $this->createMockService(2);
return $formData;
}
private function createFormDataWithBusPickup(): BookingEditDto
{
$formData = $this->createCompleteFormData();
$participant = $formData->participants[0];
$busService = $this->createMockService(1);
$busService->subType = 'BUS';
$participant->transportationServiceTo = $busService;
$participant->pickup = $this->createMockPickup(1);
return $formData;
}
private function createFormDataWithNonBusTransportation(): BookingEditDto
{
$formData = $this->createCompleteFormData();
$participant = $formData->participants[0];
$trainService = $this->createMockService(1);
$trainService->subType = 'TRAIN';
$participant->transportationServiceTo = $trainService;
return $formData;
}
private function createFormDataWithUnusedServices(): BookingEditDto
{
$formData = $this->createCompleteFormData();
// Remove all participants so services become unused
$formData->participants = [];
return $formData;
}
private function createFormDataWithUpdatedPersonalData(): BookingEditDto
{
$formData = $this->createCompleteFormData();
$participant = $formData->participants[0];
$participant->firstName = 'Updated';
$participant->lastName = 'Participant';
$participant->email = '[email protected]';
$participant->mobile = '+49123456789';
return $formData;
}
private function createFormDataWithInactiveParticipant(): BookingEditDto
{
$formData = $this->createCompleteFormData();
$participant = $formData->participants[0];
$participant->status = 'C'; // Inactive status
$participant->firstName = 'Updated';
$participant->lastName = 'Participant';
// Ensure original data remains unchanged
$formData->booking->participants[0]->firstName = 'Original';
$formData->booking->participants[0]->name = 'Name';
return $formData;
}
private function createFormDataForApplicantSync(): BookingEditDto
{
$formData = $this->createCompleteFormData();
$firstParticipant = $formData->booking->participants[0];
$firstParticipant->height = '180';
$firstParticipant->weight = '75';
$firstParticipant->shoeSize = '42';
return $formData;
}
private function createFormDataWithBankAccount(): BookingEditDto
{
$formData = $this->createCompleteFormData();
$bankAccount = new BankAccount();
$bankAccount->bankName = 'Test Bank';
$bankAccount->iban = 'DE89370400440532013000';
$bankAccount->bic = 'COBADEFFXXX';
$bankAccount->holder = 'Test Holder';
$formData->booking->bankAccount = $bankAccount;
return $formData;
}
@@ -355,14 +349,14 @@ class BookingDataProcessorTest extends TestCase
{
$formData = $this->createCompleteFormData();
$formData->booking->bankAccount = null;
return $formData;
}
private function createFormDataWithRooms(): BookingEditDto
{
$formData = $this->createCompleteFormData();
$room = new Room();
$room->id = 1;
$room->category = 'DOUBLE';
@@ -371,22 +365,22 @@ class BookingDataProcessorTest extends TestCase
$room->dateTo = new \DateTimeImmutable('2024-01-07');
$room->totalCount = 2;
$room->mapping = [0, 1];
$formData->booking->rooms = [$room];
return $formData;
}
private function createFormDataWithoutExistingCommunication(): BookingEditDto
{
$formData = $this->createCompleteFormData();
$participant = $formData->participants[0];
$participant->email = '[email protected]';
$participant->mobile = '+49987654321';
$formData->booking->participants[0]->communication = new Communication();
return $formData;
}
@@ -394,7 +388,7 @@ class BookingDataProcessorTest extends TestCase
{
$formData = $this->createCompleteFormData();
$formData->booking->pickupsTo = [];
return $formData;
}
@@ -421,7 +415,7 @@ class BookingDataProcessorTest extends TestCase
$booking->applicant = $this->createMockPersonalData('Applicant');
$booking->bankAccount = null;
$booking->rooms = [];
return $booking;
}
@@ -436,7 +430,7 @@ class BookingDataProcessorTest extends TestCase
1 => $this->createMockService(1),
2 => $this->createMockService(2),
];
return $travel;
}
@@ -463,7 +457,7 @@ class BookingDataProcessorTest extends TestCase
$participant->transportationServiceTo = $this->createMockService(1);
$participant->transportationServiceFro = $this->createMockService(2);
$participant->pickup = null;
return $participant;
}
@@ -480,7 +474,7 @@ class BookingDataProcessorTest extends TestCase
$personalData->shoeSize = '40';
$personalData->address = new Address();
$personalData->communication = new Communication();
return $personalData;
}
@@ -492,7 +486,7 @@ class BookingDataProcessorTest extends TestCase
$service->mapping = [];
$service->individualPrice = [];
$service->subType = 'STANDARD';
return $service;
}
@@ -501,7 +495,7 @@ class BookingDataProcessorTest extends TestCase
$pickup = new Pickup();
$pickup->id = $id;
$pickup->mapping = [];
return $pickup;
}
}
}