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
+91 -27
View File
@@ -24,17 +24,20 @@ class TravelSnapshotManagerTest extends TestCase
private ApiClient $apiClient;
private LoggerInterface $logger;
private SerializerInterface $serializer;
private TravelSnapshotManager $service;
private ?TravelSnapshotManager $service = null;
protected function setUp(): void
{
$this->snapshotRepository = $this->createMock(TravelSnapshotRepository::class);
$this->entityManager = $this->createMock(EntityManagerInterface::class);
$this->apiClient = $this->createMock(ApiClient::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->serializer = $this->createMock(SerializerInterface::class);
$this->snapshotRepository = $this->createStub(TravelSnapshotRepository::class);
$this->entityManager = $this->createStub(EntityManagerInterface::class);
$this->apiClient = $this->createStub(ApiClient::class);
$this->logger = $this->createStub(LoggerInterface::class);
$this->serializer = $this->createStub(SerializerInterface::class);
}
$this->service = new TravelSnapshotManager(
private function service(): TravelSnapshotManager
{
return $this->service ??= new TravelSnapshotManager(
$this->snapshotRepository,
$this->entityManager,
$this->apiClient,
@@ -46,6 +49,10 @@ class TravelSnapshotManagerTest extends TestCase
public function testUpsertCreatesNewSnapshot(): void
{
$this->snapshotRepository = $this->createMock(TravelSnapshotRepository::class);
$this->entityManager = $this->createMock(EntityManagerInterface::class);
$this->serializer = $this->createMock(SerializerInterface::class);
$travel = new Travel();
$travel->id = 100;
$travel->hotelId = 200;
@@ -71,11 +78,15 @@ class TravelSnapshotManagerTest extends TestCase
->expects($this->once())
->method('flush');
$this->service->upsertFromTravel($travel);
$this->service()->upsertFromTravel($travel);
}
public function testUpsertSkipsWhenHashUnchanged(): void
{
$this->snapshotRepository = $this->createMock(TravelSnapshotRepository::class);
$this->entityManager = $this->createMock(EntityManagerInterface::class);
$this->serializer = $this->createMock(SerializerInterface::class);
$travel = new Travel();
$travel->id = 100;
$travel->hotelId = 200;
@@ -100,11 +111,15 @@ class TravelSnapshotManagerTest extends TestCase
->expects($this->never())
->method('flush');
$this->service->upsertFromTravel($travel);
$this->service()->upsertFromTravel($travel);
}
public function testUpsertUpdatesWhenHashChanged(): void
{
$this->snapshotRepository = $this->createMock(TravelSnapshotRepository::class);
$this->entityManager = $this->createMock(EntityManagerInterface::class);
$this->serializer = $this->createMock(SerializerInterface::class);
$travel = new Travel();
$travel->id = 100;
$travel->hotelId = 200;
@@ -131,24 +146,30 @@ class TravelSnapshotManagerTest extends TestCase
->expects($this->once())
->method('flush');
$this->service->upsertFromTravel($travel);
$this->service()->upsertFromTravel($travel);
}
public function testLoadTravelReturnsNullWhenNoSnapshot(): void
{
$this->snapshotRepository = $this->createMock(TravelSnapshotRepository::class);
$this->snapshotRepository
->expects($this->once())
->method('findByDateAndHotel')
->with(100, 200)
->willReturn(null);
$result = $this->service->loadTravel(100, 200);
$result = $this->service()->loadTravel(100, 200);
$this->assertNull($result);
}
public function testLoadTravelReturnsNullOnDeserializationError(): void
{
$this->snapshotRepository = $this->createMock(TravelSnapshotRepository::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->serializer = $this->createMock(SerializerInterface::class);
$snapshot = new TravelSnapshot(100, 200, 'invalid-json', hash('sha256', 'invalid-json'));
$this->snapshotRepository
@@ -167,13 +188,15 @@ class TravelSnapshotManagerTest extends TestCase
->method('warning')
->with('Snapshot payload cannot be deserialized to Travel', $this->arrayHasKey('snapshotId'));
$result = $this->service->loadTravel(100, 200);
$result = $this->service()->loadTravel(100, 200);
$this->assertNull($result);
}
public function testExistsReturnsTrueWhenSnapshotFound(): void
{
$this->snapshotRepository = $this->createMock(TravelSnapshotRepository::class);
$snapshot = new TravelSnapshot(100, 200, '{}', hash('sha256', '{}'));
$this->snapshotRepository
@@ -182,22 +205,27 @@ class TravelSnapshotManagerTest extends TestCase
->with(100, 200)
->willReturn($snapshot);
$this->assertTrue($this->service->exists(100, 200));
$this->assertTrue($this->service()->exists(100, 200));
}
public function testExistsReturnsFalseWhenNoSnapshot(): void
{
$this->snapshotRepository = $this->createMock(TravelSnapshotRepository::class);
$this->snapshotRepository
->expects($this->once())
->method('findByDateAndHotel')
->with(100, 200)
->willReturn(null);
$this->assertFalse($this->service->exists(100, 200));
$this->assertFalse($this->service()->exists(100, 200));
}
public function testLoadTravelReturnsDeserializedTravel(): void
{
$this->snapshotRepository = $this->createMock(TravelSnapshotRepository::class);
$this->serializer = $this->createMock(SerializerInterface::class);
$travel = new Travel();
$travel->id = 100;
$travel->hotelId = 200;
@@ -217,7 +245,7 @@ class TravelSnapshotManagerTest extends TestCase
->with($payload, Travel::class, 'json')
->willReturn($travel);
$result = $this->service->loadTravel(100, 200);
$result = $this->service()->loadTravel(100, 200);
$this->assertInstanceOf(Travel::class, $result);
$this->assertSame($travel, $result);
@@ -225,6 +253,9 @@ class TravelSnapshotManagerTest extends TestCase
public function testUpsertFromTravelSkipsWhenTravelIsIncomplete(): void
{
$this->entityManager = $this->createMock(EntityManagerInterface::class);
$this->serializer = $this->createMock(SerializerInterface::class);
$travelNoId = new Travel();
$travelNoId->id = null;
$travelNoId->hotelId = 200;
@@ -236,25 +267,29 @@ class TravelSnapshotManagerTest extends TestCase
$this->serializer->expects($this->never())->method('serialize');
$this->entityManager->expects($this->never())->method('flush');
$this->service->upsertFromTravel($travelNoId);
$this->service->upsertFromTravel($travelNoHotel);
$this->service()->upsertFromTravel($travelNoId);
$this->service()->upsertFromTravel($travelNoHotel);
}
public function testFindProductIdByDateIdDelegatesToRepository(): void
{
$this->snapshotRepository = $this->createMock(TravelSnapshotRepository::class);
$this->snapshotRepository
->expects($this->once())
->method('findProductIdByDateId')
->with(42)
->willReturn(365);
$result = $this->service->findProductIdByDateId(42);
$result = $this->service()->findProductIdByDateId(42);
$this->assertSame(365, $result);
}
public function testPurgeExpiredSnapshotsDelegatesWithCorrectDate(): void
{
$this->snapshotRepository = $this->createMock(TravelSnapshotRepository::class);
$this->snapshotRepository
->expects($this->once())
->method('deleteExpiredSnapshots')
@@ -265,13 +300,18 @@ class TravelSnapshotManagerTest extends TestCase
}))
->willReturn(7);
$result = $this->service->purgeExpiredSnapshots();
$result = $this->service()->purgeExpiredSnapshots();
$this->assertSame(7, $result);
}
public function testRefreshExtendedSnapshotsSuccessPath(): void
{
$this->snapshotRepository = $this->createMock(TravelSnapshotRepository::class);
$this->entityManager = $this->createMock(EntityManagerInterface::class);
$this->apiClient = $this->createMock(ApiClient::class);
$this->serializer = $this->createMock(SerializerInterface::class);
$travel = new Travel();
$travel->id = 100;
$travel->hotelId = 200;
@@ -310,13 +350,19 @@ class TravelSnapshotManagerTest extends TestCase
->expects($this->once())
->method('flush');
$result = $this->service->refreshExtendedSnapshots(500, false, 360, []);
$result = $this->service()->refreshExtendedSnapshots(500, false, 360, []);
$this->assertSame(['processed' => 1, 'updated' => 1, 'failed' => 0], $result);
}
public function testRefreshExtendedSnapshotsApiFailureIncrementsFailedCount(): void
{
$this->snapshotRepository = $this->createMock(TravelSnapshotRepository::class);
$this->entityManager = $this->createMock(EntityManagerInterface::class);
$this->apiClient = $this->createMock(ApiClient::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->serializer = $this->createMock(SerializerInterface::class);
$travel = new Travel();
$travel->id = 100;
$travel->hotelId = 200;
@@ -348,13 +394,18 @@ class TravelSnapshotManagerTest extends TestCase
->expects($this->never())
->method('flush');
$result = $this->service->refreshExtendedSnapshots(500, false, 360, []);
$result = $this->service()->refreshExtendedSnapshots(500, false, 360, []);
$this->assertSame(['processed' => 1, 'updated' => 0, 'failed' => 1], $result);
}
public function testRefreshExtendedSnapshotsDeserializationFailureIncrementsFailedCount(): void
{
$this->snapshotRepository = $this->createMock(TravelSnapshotRepository::class);
$this->entityManager = $this->createMock(EntityManagerInterface::class);
$this->logger = $this->createMock(LoggerInterface::class);
$this->serializer = $this->createMock(SerializerInterface::class);
$payload = '{"id":100}';
$snapshot = new TravelSnapshot(100, 200, $payload, hash('sha256', $payload));
@@ -377,13 +428,17 @@ class TravelSnapshotManagerTest extends TestCase
->expects($this->never())
->method('flush');
$result = $this->service->refreshExtendedSnapshots(500, false, 360, []);
$result = $this->service()->refreshExtendedSnapshots(500, false, 360, []);
$this->assertSame(['processed' => 1, 'updated' => 0, 'failed' => 1], $result);
}
public function testRefreshSkipsAllCandidatesWhenXmlDateIdsIsNull(): void
{
$this->snapshotRepository = $this->createMock(TravelSnapshotRepository::class);
$this->entityManager = $this->createMock(EntityManagerInterface::class);
$this->apiClient = $this->createMock(ApiClient::class);
$payload = '{"id":100}';
$snapshot = new TravelSnapshot(100, 200, $payload, hash('sha256', $payload));
@@ -400,13 +455,16 @@ class TravelSnapshotManagerTest extends TestCase
->expects($this->never())
->method('flush');
$result = $this->service->refreshExtendedSnapshots(500, false, 360, null);
$result = $this->service()->refreshExtendedSnapshots(500, false, 360, null);
$this->assertSame(['processed' => 0, 'updated' => 0, 'failed' => 0], $result);
}
public function testRefreshSkipsSnapshotsWithXmlAvailable(): void
{
$this->snapshotRepository = $this->createMock(TravelSnapshotRepository::class);
$this->apiClient = $this->createMock(ApiClient::class);
$payload = '{"id":100}';
$snapshot = new TravelSnapshot(100, 200, $payload, hash('sha256', $payload));
@@ -419,26 +477,30 @@ class TravelSnapshotManagerTest extends TestCase
->expects($this->never())
->method('getAvailabilitiesExtended');
$result = $this->service->refreshExtendedSnapshots(500, false, 360, [100]);
$result = $this->service()->refreshExtendedSnapshots(500, false, 360, [100]);
$this->assertSame(['processed' => 0, 'updated' => 0, 'failed' => 0], $result);
}
public function testPurgeOrphanedFutureSnapshotsReturnsZeroForEmptyList(): void
{
$this->snapshotRepository = $this->createMock(TravelSnapshotRepository::class);
$this->snapshotRepository
->expects($this->once())
->method('deleteOrphanedFutureSnapshots')
->with([], $this->isInstanceOf(\DateTimeImmutable::class))
->willReturn(0);
$result = $this->service->purgeOrphanedFutureSnapshots([]);
$result = $this->service()->purgeOrphanedFutureSnapshots([]);
$this->assertSame(0, $result);
}
public function testPurgeOrphanedFutureSnapshotsDelegatesWithCorrectArguments(): void
{
$this->snapshotRepository = $this->createMock(TravelSnapshotRepository::class);
$activeIds = [100, 200, 300];
$this->snapshotRepository
@@ -454,13 +516,15 @@ class TravelSnapshotManagerTest extends TestCase
)
->willReturn(3);
$result = $this->service->purgeOrphanedFutureSnapshots($activeIds);
$result = $this->service()->purgeOrphanedFutureSnapshots($activeIds);
$this->assertSame(3, $result);
}
public function testGenerateMappingBuildsCorrectStructure(): void
{
$this->snapshotRepository = $this->createMock(TravelSnapshotRepository::class);
$hotel = new Hotel();
$hotel->code = 'HTL1';
$hotel->name = 'Hotel One';
@@ -498,7 +562,7 @@ class TravelSnapshotManagerTest extends TestCase
->method('findAllForMapping')
->willReturn([$snapshot1, $snapshot2]);
$mapping = $this->service->generateMapping();
$mapping = $this->service()->generateMapping();
$this->assertArrayHasKey(10, $mapping);
$this->assertSame('TRIP1', $mapping[10]['code']);