parser = new BookingParser(); } public function testStatusesAreKeyedLikeParticipantsForContiguousIds(): void { $booking = $this->parse('F/S/F', [1, 2, 3]); $this->assertSame([0, 1, 2], array_keys($booking->participants)); $this->assertSame([0 => 'F', 1 => 'S', 2 => 'F'], $booking->participantsStatus); } public function testStatusesFollowParticipantIdsWhenIdsAreNotContiguous(): void { $booking = $this->parse('F/S/F', [1, 4, 7]); $this->assertSame([0, 3, 6], array_keys($booking->participants)); $this->assertSame([0 => 'F', 3 => 'S', 6 => 'F'], $booking->participantsStatus); // Every participant the payload builder iterates must find its own status. foreach ($booking->participants as $index => $participant) { $this->assertArrayHasKey($index, $booking->participantsStatus); } } public function testSurplusStatusEntriesAreDroppedInsteadOfShifting(): void { $booking = $this->parse('F/S/F/F', [1, 2, 3]); $this->assertSame([0 => 'F', 1 => 'S', 2 => 'F'], $booking->participantsStatus); } public function testMissingStatusEntriesLeaveTheRemainingParticipantsAligned(): void { $booking = $this->parse('F/S', [1, 2, 3]); $this->assertSame([0 => 'F', 1 => 'S'], $booking->participantsStatus); $this->assertArrayNotHasKey(2, $booking->participantsStatus); } public function testStatusListSurroundedByWhitespaceIsParsed(): void { // BusPro pretty-prints the element, so the text node carries newlines and indentation. $booking = $this->parse("\n F/S/F\n ", [1, 2, 3]); $this->assertSame([0 => 'F', 1 => 'S', 2 => 'F'], $booking->participantsStatus); } public function testEmptyStatusListDoesNotFail(): void { $booking = $this->parse('', [1, 2]); $this->assertSame([], $booking->participantsStatus); $this->assertCount(2, $booking->participants); } /** @param list $participantIds */ private function parse(string $statusList, array $participantIds): \App\BusProNet\Model\Booking { $participants = ''; foreach ($participantIds as $id) { $participants .= sprintf( 'Teilnehmer %1$dTest', $id, ); } $xml = sprintf( ' Vorgang_Details 98787 %s %s ', $statusList, $participants, ); return $this->parser->parse(XmlCrawlerFactory::create($xml)->filterXPath('//ergebnis')); } }