feat: upgrade phpunit to 12.5

This commit is contained in:
Björn Fromme
2026-08-31 09:31:00 +02:00
parent 010cfe56b2
commit bfad61f1dd
95 changed files with 1436 additions and 1224 deletions
+42 -21
View File
@@ -13,7 +13,7 @@ use Psr\Log\LoggerInterface;
class TravelIndexTest extends TestCase
{
private TravelIndex $service;
private ?TravelIndex $service = null;
private TravelLoader $travelLoader;
private HotelLoader $hotelLoader;
private TravelSnapshotManager $travelSnapshotService;
@@ -21,12 +21,15 @@ class TravelIndexTest extends TestCase
protected function setUp(): void
{
$this->travelLoader = $this->createMock(TravelLoader::class);
$this->hotelLoader = $this->createMock(HotelLoader::class);
$this->travelSnapshotService = $this->createMock(TravelSnapshotManager::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->travelLoader = $this->createStub(TravelLoader::class);
$this->hotelLoader = $this->createStub(HotelLoader::class);
$this->travelSnapshotService = $this->createStub(TravelSnapshotManager::class);
$this->logger = $this->createStub(LoggerInterface::class);
}
$this->service = new TravelIndex(
private function service(): TravelIndex
{
return $this->service ??= new TravelIndex(
$this->travelLoader,
$this->hotelLoader,
$this->travelSnapshotService,
@@ -59,7 +62,7 @@ class TravelIndexTest extends TestCase
$this->travelLoader->method('generateFilesMap')->willReturn($xmlMapping);
$this->travelSnapshotService->method('generateMapping')->willReturn($snapshotMapping);
$result = $this->service->generateFilesMap();
$result = $this->service()->generateFilesMap();
// XML entry is preserved
$this->assertArrayHasKey($dateId, $result);
@@ -73,6 +76,9 @@ class TravelIndexTest extends TestCase
public function testGenerateFilesMapIsMemoizedWithinRequest(): void
{
$this->travelLoader = $this->createMock(TravelLoader::class);
$this->travelSnapshotService = $this->createMock(TravelSnapshotManager::class);
$mapping = [100 => ['id' => 100, 'code' => 'A', 'hotels' => []]];
$this->travelLoader
@@ -86,14 +92,16 @@ class TravelIndexTest extends TestCase
->willReturn([]);
// Two calls — loaders invoked only once
$this->service->generateFilesMap();
$result = $this->service->generateFilesMap();
$this->service()->generateFilesMap();
$result = $this->service()->generateFilesMap();
$this->assertSame($mapping, $result);
}
public function testGenerateFilesMapFallsBackToSnapshotsOnXmlFailure(): void
{
$this->logger = $this->createMock(LoggerInterface::class);
$snapshotMapping = [100 => ['id' => 100, 'code' => 'A', 'hotels' => []]];
$this->travelLoader
@@ -109,7 +117,7 @@ class TravelIndexTest extends TestCase
->method('warning')
->with('Failed to generate XML files mapping, fallback to snapshots only', $this->arrayHasKey('error'));
$result = $this->service->generateFilesMap();
$result = $this->service()->generateFilesMap();
$this->assertSame($snapshotMapping, $result);
}
@@ -125,7 +133,7 @@ class TravelIndexTest extends TestCase
]);
$this->travelSnapshotService->method('generateMapping')->willReturn([]);
$result = $this->service->mapDateCodeToId('WI25');
$result = $this->service()->mapDateCodeToId('WI25');
$this->assertSame(42, $result);
}
@@ -135,7 +143,7 @@ class TravelIndexTest extends TestCase
$this->travelLoader->method('generateFilesMap')->willReturn([]);
$this->travelSnapshotService->method('generateMapping')->willReturn([]);
$result = $this->service->mapDateCodeToId('UNKNOWN');
$result = $this->service()->mapDateCodeToId('UNKNOWN');
$this->assertNull($result);
}
@@ -146,13 +154,15 @@ class TravelIndexTest extends TestCase
public function testMapHotelCodeToIdDelegatesToHotelLoader(): void
{
$this->hotelLoader = $this->createMock(HotelLoader::class);
$this->hotelLoader
->expects($this->once())
->method('mapCodeToId')
->with('HTL001')
->willReturn(77);
$result = $this->service->mapHotelCodeToId('HTL001');
$result = $this->service()->mapHotelCodeToId('HTL001');
$this->assertSame(77, $result);
}
@@ -163,7 +173,7 @@ class TravelIndexTest extends TestCase
->method('mapCodeToId')
->willThrowException(new \RuntimeException('Not found'));
$result = $this->service->mapHotelCodeToId('MISSING');
$result = $this->service()->mapHotelCodeToId('MISSING');
$this->assertNull($result);
}
@@ -174,6 +184,9 @@ class TravelIndexTest extends TestCase
public function testMapDateIdToProductIdPrefersSnapshot(): void
{
$this->travelLoader = $this->createMock(TravelLoader::class);
$this->travelSnapshotService = $this->createMock(TravelSnapshotManager::class);
$this->travelSnapshotService
->expects($this->once())
->method('findProductIdByDateId')
@@ -184,13 +197,16 @@ class TravelIndexTest extends TestCase
->expects($this->never())
->method('mapDateIdToProductId');
$result = $this->service->mapDateIdToProductId(100);
$result = $this->service()->mapDateIdToProductId(100);
$this->assertSame(999, $result);
}
public function testMapDateIdToProductIdFallsBackToLoaderWhenSnapshotReturnsNull(): void
{
$this->travelLoader = $this->createMock(TravelLoader::class);
$this->travelSnapshotService = $this->createMock(TravelSnapshotManager::class);
$this->travelSnapshotService
->expects($this->once())
->method('findProductIdByDateId')
@@ -203,7 +219,7 @@ class TravelIndexTest extends TestCase
->with(100)
->willReturn(42);
$result = $this->service->mapDateIdToProductId(100);
$result = $this->service()->mapDateIdToProductId(100);
$this->assertSame(42, $result);
}
@@ -214,6 +230,9 @@ class TravelIndexTest extends TestCase
public function testExistsLocallyTrueFromSnapshot(): void
{
$this->travelLoader = $this->createMock(TravelLoader::class);
$this->travelSnapshotService = $this->createMock(TravelSnapshotManager::class);
$dateId = 12345;
$hotelId = 67890;
@@ -227,7 +246,7 @@ class TravelIndexTest extends TestCase
->expects($this->never())
->method('generateFilesMap');
$this->assertTrue($this->service->existsLocally($dateId, $hotelId));
$this->assertTrue($this->service()->existsLocally($dateId, $hotelId));
}
public function testExistsLocallyTrueFromXmlMap(): void
@@ -245,7 +264,7 @@ class TravelIndexTest extends TestCase
$this->travelLoader->method('generateFilesMap')->willReturn($mapping);
$this->travelSnapshotService->method('generateMapping')->willReturn([]);
$this->assertTrue($this->service->existsLocally($dateId, $hotelId));
$this->assertTrue($this->service()->existsLocally($dateId, $hotelId));
}
public function testExistsLocallyFalseNoTravel(): void
@@ -254,7 +273,7 @@ class TravelIndexTest extends TestCase
$this->travelLoader->method('generateFilesMap')->willReturn([]);
$this->travelSnapshotService->method('generateMapping')->willReturn([]);
$this->assertFalse($this->service->existsLocally(12345, 67890));
$this->assertFalse($this->service()->existsLocally(12345, 67890));
}
public function testExistsLocallyFalseNoHotel(): void
@@ -269,7 +288,7 @@ class TravelIndexTest extends TestCase
$this->travelLoader->method('generateFilesMap')->willReturn($mapping);
$this->travelSnapshotService->method('generateMapping')->willReturn([]);
$this->assertFalse($this->service->existsLocally($dateId, $hotelId));
$this->assertFalse($this->service()->existsLocally($dateId, $hotelId));
}
// -------------------------------------------------------------------------
@@ -278,6 +297,8 @@ class TravelIndexTest extends TestCase
public function testGetAvailableSourcesReturnsBothFlags(): void
{
$this->travelLoader = $this->createMock(TravelLoader::class);
$dateId = 12345;
$hotelId = 67890;
$mapping = [
@@ -290,7 +311,7 @@ class TravelIndexTest extends TestCase
$this->travelLoader->method('generateFilesMap')->willReturn($mapping);
$this->travelLoader->method('mapDateIdToProductId')->with($dateId)->willReturn(555);
$result = $this->service->getAvailableSources($dateId, $hotelId);
$result = $this->service()->getAvailableSources($dateId, $hotelId);
$this->assertEquals(['local' => true, 'remote' => true], $result);
}