handler = new ParticipantLicensePlateFieldHandler(); } public function testGetFieldName(): void { $this->assertSame('licensePlate', $this->handler->getFieldName()); } public function testGetDependencies(): void { $this->assertSame(['parking'], $this->handler->getDependencies()); } public function testShouldProcessAlwaysReturnsTrue(): void { $this->assertTrue($this->handler->shouldProcess([], 0)); $this->assertTrue($this->handler->shouldProcess(['some' => 'data'], 5)); } public function testProcessFieldWithoutParticipant(): void { $travel = new Travel(); $bookingDto = new BookingCreateDto($travel, 1); $submittedData = ['licensePlate' => 'AB-CD 123']; $this->handler->processField($submittedData, $bookingDto, 0); // Should handle gracefully when participant doesn't exist $this->expectNotToPerformAssertions(); } public function testProcessFieldClearsLicensePlateWhenParkingNotSelected(): void { $participant = new ParticipantDto(); $participant->parking = false; // Parking not selected $participant->licensePlate = 'AB-CD 123'; // Should be cleared $travel = new Travel(); $bookingDto = new BookingCreateDto($travel, 1); $bookingDto->participants = [$participant]; $submittedData = ['licensePlate' => 'XY-ZZ 999']; $this->handler->processField($submittedData, $bookingDto, 0); $this->assertNull($participant->licensePlate); } public function testProcessFieldSetsLicensePlateWhenParkingSelected(): void { $participant = new ParticipantDto(); $participant->parking = true; // Parking selected $travel = new Travel(); $bookingDto = new BookingCreateDto($travel, 1); $bookingDto->participants = [$participant]; $submittedData = ['licensePlate' => 'AB-CD 123']; $this->handler->processField($submittedData, $bookingDto, 0); $this->assertSame('AB-CD 123', $participant->licensePlate); } public function testProcessFieldHandlesEmptyLicensePlate(): void { $participant = new ParticipantDto(); $participant->parking = true; // Parking selected $travel = new Travel(); $bookingDto = new BookingCreateDto($travel, 1); $bookingDto->participants = [$participant]; $submittedData = ['licensePlate' => '']; $this->handler->processField($submittedData, $bookingDto, 0); $this->assertNull($participant->licensePlate); } public function testProcessFieldHandlesNullLicensePlate(): void { $participant = new ParticipantDto(); $participant->parking = true; // Parking selected $travel = new Travel(); $bookingDto = new BookingCreateDto($travel, 1); $bookingDto->participants = [$participant]; $submittedData = ['licensePlate' => null]; $this->handler->processField($submittedData, $bookingDto, 0); $this->assertNull($participant->licensePlate); } public function testProcessFieldTrimsWhitespace(): void { $participant = new ParticipantDto(); $participant->parking = true; // Parking selected $travel = new Travel(); $bookingDto = new BookingCreateDto($travel, 1); $bookingDto->participants = [$participant]; $submittedData = ['licensePlate' => ' AB-CD 123 ']; $this->handler->processField($submittedData, $bookingDto, 0); $this->assertSame('AB-CD 123', $participant->licensePlate); } public function testProcessFieldHandlesWhitespaceOnlyAsEmpty(): void { $participant = new ParticipantDto(); $participant->parking = true; // Parking selected $travel = new Travel(); $bookingDto = new BookingCreateDto($travel, 1); $bookingDto->participants = [$participant]; $submittedData = ['licensePlate' => ' ']; $this->handler->processField($submittedData, $bookingDto, 0); $this->assertNull($participant->licensePlate); } public function testProcessFieldHandlesNonStringValues(): void { $participant = new ParticipantDto(); $participant->parking = true; // Parking selected $travel = new Travel(); $bookingDto = new BookingCreateDto($travel, 1); $bookingDto->participants = [$participant]; // Test with integer value $submittedData = ['licensePlate' => 123]; $this->handler->processField($submittedData, $bookingDto, 0); $this->assertNull($participant->licensePlate); // Test with array value $submittedData = ['licensePlate' => ['invalid']]; $this->handler->processField($submittedData, $bookingDto, 0); $this->assertNull($participant->licensePlate); } public function testProcessFieldHandlesMissingLicensePlateField(): void { $participant = new ParticipantDto(); $participant->parking = true; // Parking selected $travel = new Travel(); $bookingDto = new BookingCreateDto($travel, 1); $bookingDto->participants = [$participant]; $submittedData = []; // No licensePlate field $this->handler->processField($submittedData, $bookingDto, 0); $this->assertNull($participant->licensePlate); } public function testProcessFieldWithDifferentParticipantIndex(): void { $participant1 = new ParticipantDto(); $participant1->parking = false; $participant2 = new ParticipantDto(); $participant2->parking = true; $travel = new Travel(); $bookingDto = new BookingCreateDto($travel, 1); $bookingDto->participants = [$participant1, $participant2]; $submittedData = ['licensePlate' => 'AB-CD 123']; // Process for participant at index 1 $this->handler->processField($submittedData, $bookingDto, 1); $this->assertNull($participant1->licensePlate); // Should not be affected $this->assertSame('AB-CD 123', $participant2->licensePlate); // Should be set } }