fix: restore room occupancy lost to case-sensitive xml attribute lookup

This commit is contained in:
Björn Fromme
2026-08-31 14:15:21 +02:00
parent 24df764efb
commit e14d29f7d4
10 changed files with 223 additions and 16 deletions
@@ -6,6 +6,7 @@ namespace App\Tests\BusProNet\XmlParser;
use App\BusProNet\XmlCrawlerFactory;
use App\BusProNet\XmlParser\TravelParser;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class TravelParserTest extends TestCase
@@ -426,4 +427,35 @@ class TravelParserTest extends TestCase
$this->assertSame('2029-12-30 18:00', $pickups[1]->time->format('Y-m-d H:i'));
$this->assertSame('2029-12-30 01:00', $pickups[2]->time->format('Y-m-d H:i'));
}
/**
* The travel export writes MinPax/MaxPax capitalized while booking responses write them lowercase.
* XmlCrawlerFactory uses addXmlContent(), which makes attribute lookups case-sensitive, so both
* spellings have to resolve.
*/
#[DataProvider('roomOccupancyAttributeProvider')]
public function testGetRoomsReadsOccupancyRegardlessOfAttributeCasing(string $attributes, ?int $expectedPax): void
{
$xml = sprintf('<?xml version="1.0" encoding="utf-8"?>
<zimmer>
<preis zimmercode="4erDW" idbuspro_zimmer="95" zimmertext="4er Zimmer Dusche/WC" %s naechte="5" idbuspro_vp="2" preis="689,00" status="Frei" verfuegbar="8" />
</zimmer>', $attributes);
$crawler = XmlCrawlerFactory::create($xml);
$rooms = $this->parser->getRooms($crawler->filterXPath('//zimmer')->first());
$this->assertArrayHasKey(95, $rooms);
$this->assertSame($expectedPax, $rooms[95]->minPax);
$this->assertSame($expectedPax, $rooms[95]->maxPax);
}
/**
* @return iterable<string, array{string, int|null}>
*/
public static function roomOccupancyAttributeProvider(): iterable
{
yield 'export casing' => ['MinPax="4" MaxPax="4"', 4];
yield 'lowercase casing' => ['minpax="4" maxpax="4"', 4];
yield 'missing stays null' => ['', null];
}
}