fix: skip travels whose hotel is missing from the master data

generateFilesMap() read ->name straight off $hotels[$hotelId] with no
guard, so a travel referencing a hotel absent from hotel.xml produced an
undefined-key warning and an entry with a null label -- a hotel in
/api/travels that resolves nowhere. No row hits this in the current
snapshot, which is why it has never surfaced.

Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
frommeandClaude Opus 5 committed 2026-09-29 12:08:07 +02:00
1 parent f3745f918e
commit 0a5602fd41
2 files changed
+72

No files matched your search

@@ -0,0 +1,65 @@
<?php
declare(strict_types=1);
namespace App\Tests\BusProNet\XmlLoader;
use App\BusProNet\Model\Hotel;
use App\BusProNet\XmlLoader\HotelLoader;
use App\BusProNet\XmlLoader\TravelLoader;
use App\BusProNet\XmlParser\TravelParser;
use League\Flysystem\DirectoryListing;
use League\Flysystem\FileAttributes;
use League\Flysystem\FilesystemOperator;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Cache\Adapter\ArrayAdapter;
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
class TravelLoaderFilesMapTest extends TestCase
{
private const XML = '<?xml version="1.0" encoding="utf-8"?>
<reisen>
<reise code="SBW">
<termin idbuspro="900" code="SBW250101" termin="01.01.2025" bis="08.01.2025">
<text>Skiwoche</text>
<hotel idbuspro="1" code="KNOWN"/>
<hotel idbuspro="999" code="GHOST"/>
</termin>
</reise>
</reisen>';
/**
* A travel may reference a hotel id that hotel.xml does not carry. Before the guard the
* miss was dereferenced, which fataled the whole cached mapping rather than one entry --
* so /api/travels went down entirely, not just the affected travel.
*/
public function testGenerateFilesMapSkipsHotelsMissingFromMasterData(): void
{
$known = new Hotel();
$known->id = 1;
$known->name = 'Hotel Bekannt';
$hotelLoader = $this->createStub(HotelLoader::class);
$hotelLoader->method('loadAll')->willReturn([1 => $known]);
$filesystem = $this->createStub(FilesystemOperator::class);
$filesystem->method('listContents')->willReturn(
new DirectoryListing([new FileAttributes('Ziel_1.xml')])
);
$filesystem->method('read')->willReturn(self::XML);
$loader = new TravelLoader(
$hotelLoader,
$this->createStub(TravelParser::class),
'https://example.test',
new TagAwareAdapter(new ArrayAdapter()),
$filesystem,
);
$mapping = $loader->generateFilesMap();
$this->assertArrayHasKey(900, $mapping);
$this->assertSame([1], array_keys($mapping[900]['hotels']));
$this->assertSame('Hotel Bekannt', $mapping[900]['hotels'][1]['label']);
}
}