feat: upgrade phpunit to 12.5
This commit is contained in:
@@ -18,7 +18,7 @@ use Symfony\Contracts\Cache\CacheInterface;
|
||||
|
||||
class TravelDataProviderTest extends TestCase
|
||||
{
|
||||
private TravelDataProvider $service;
|
||||
private ?TravelDataProvider $service = null;
|
||||
private TravelLoader $travelLoader;
|
||||
private ApiClient $apiClient;
|
||||
private CacheInterface $cache;
|
||||
@@ -29,15 +29,18 @@ class TravelDataProviderTest extends TestCase
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->travelLoader = $this->createMock(TravelLoader::class);
|
||||
$this->apiClient = $this->createMock(ApiClient::class);
|
||||
$this->cache = $this->createMock(CacheInterface::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
$this->travelSnapshotService = $this->createMock(TravelSnapshotManager::class);
|
||||
$this->travelLookupService = $this->createMock(TravelIndex::class);
|
||||
$this->travelEnrichmentService = $this->createMock(TravelEnricher::class);
|
||||
$this->travelLoader = $this->createStub(TravelLoader::class);
|
||||
$this->apiClient = $this->createStub(ApiClient::class);
|
||||
$this->cache = $this->createStub(CacheInterface::class);
|
||||
$this->logger = $this->createStub(LoggerInterface::class);
|
||||
$this->travelSnapshotService = $this->createStub(TravelSnapshotManager::class);
|
||||
$this->travelLookupService = $this->createStub(TravelIndex::class);
|
||||
$this->travelEnrichmentService = $this->createStub(TravelEnricher::class);
|
||||
}
|
||||
|
||||
$this->service = new TravelDataProvider(
|
||||
private function service(): TravelDataProvider
|
||||
{
|
||||
return $this->service ??= new TravelDataProvider(
|
||||
$this->travelLoader,
|
||||
$this->apiClient,
|
||||
$this->cache,
|
||||
@@ -52,6 +55,10 @@ class TravelDataProviderTest extends TestCase
|
||||
|
||||
public function testGetTravelDataFromXmlSuccess(): void
|
||||
{
|
||||
$this->travelLoader = $this->createMock(TravelLoader::class);
|
||||
$this->travelSnapshotService = $this->createMock(TravelSnapshotManager::class);
|
||||
$this->travelEnrichmentService = $this->createMock(TravelEnricher::class);
|
||||
|
||||
$dateId = 12345;
|
||||
$hotelId = 67890;
|
||||
$travel = new Travel();
|
||||
@@ -75,13 +82,17 @@ class TravelDataProviderTest extends TestCase
|
||||
->method('upsertFromTravel')
|
||||
->with($travel);
|
||||
|
||||
$result = $this->service->getTravelDataFromXml($dateId, $hotelId);
|
||||
$result = $this->service()->getTravelDataFromXml($dateId, $hotelId);
|
||||
|
||||
$this->assertSame($travel, $result);
|
||||
}
|
||||
|
||||
public function testGetTravelDataFromXmlSkipsSnapshotWhenEnrichmentFails(): void
|
||||
{
|
||||
$this->travelLoader = $this->createMock(TravelLoader::class);
|
||||
$this->travelSnapshotService = $this->createMock(TravelSnapshotManager::class);
|
||||
$this->travelEnrichmentService = $this->createMock(TravelEnricher::class);
|
||||
|
||||
$dateId = 12345;
|
||||
$hotelId = 67890;
|
||||
$travel = new Travel();
|
||||
@@ -104,13 +115,16 @@ class TravelDataProviderTest extends TestCase
|
||||
->expects($this->never())
|
||||
->method('upsertFromTravel');
|
||||
|
||||
$result = $this->service->getTravelDataFromXml($dateId, $hotelId);
|
||||
$result = $this->service()->getTravelDataFromXml($dateId, $hotelId);
|
||||
|
||||
$this->assertSame($travel, $result);
|
||||
}
|
||||
|
||||
public function testGetTravelDataFromXmlNotFound(): void
|
||||
{
|
||||
$this->travelLoader = $this->createMock(TravelLoader::class);
|
||||
$this->travelEnrichmentService = $this->createMock(TravelEnricher::class);
|
||||
|
||||
$dateId = 12345;
|
||||
$hotelId = 67890;
|
||||
|
||||
@@ -125,11 +139,16 @@ class TravelDataProviderTest extends TestCase
|
||||
->method('enrichFromXml');
|
||||
|
||||
$this->expectException(TravelNotFoundException::class);
|
||||
$this->service->getTravelDataFromXml($dateId, $hotelId);
|
||||
$this->service()->getTravelDataFromXml($dateId, $hotelId);
|
||||
}
|
||||
|
||||
public function testGetTravelDataFromApiSuccess(): void
|
||||
{
|
||||
$this->apiClient = $this->createMock(ApiClient::class);
|
||||
$this->travelSnapshotService = $this->createMock(TravelSnapshotManager::class);
|
||||
$this->travelLookupService = $this->createMock(TravelIndex::class);
|
||||
$this->travelEnrichmentService = $this->createMock(TravelEnricher::class);
|
||||
|
||||
$dateId = 12345;
|
||||
$hotelId = 67890;
|
||||
$productId = 555;
|
||||
@@ -159,13 +178,16 @@ class TravelDataProviderTest extends TestCase
|
||||
->method('upsertFromTravel')
|
||||
->with($travel);
|
||||
|
||||
$result = $this->service->getTravelDataFromApi($dateId, $hotelId);
|
||||
$result = $this->service()->getTravelDataFromApi($dateId, $hotelId);
|
||||
|
||||
$this->assertSame($travel, $result);
|
||||
}
|
||||
|
||||
public function testGetTravelDataFromApiSnapshotFailureDoesNotDiscardApiTravel(): void
|
||||
{
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
$this->travelSnapshotService = $this->createMock(TravelSnapshotManager::class);
|
||||
|
||||
$dateId = 12345;
|
||||
$hotelId = 67890;
|
||||
$productId = 555;
|
||||
@@ -191,7 +213,7 @@ class TravelDataProviderTest extends TestCase
|
||||
->method('warning')
|
||||
->with('Failed to persist travel snapshot after API load', $this->arrayHasKey('dateId'));
|
||||
|
||||
$result = $this->service->getTravelDataFromApi($dateId, $hotelId);
|
||||
$result = $this->service()->getTravelDataFromApi($dateId, $hotelId);
|
||||
|
||||
$this->assertNotNull($result);
|
||||
$this->assertSame($travel, $result);
|
||||
@@ -199,6 +221,9 @@ class TravelDataProviderTest extends TestCase
|
||||
|
||||
public function testGetTravelDataFromApiCannotMapDateId(): void
|
||||
{
|
||||
$this->apiClient = $this->createMock(ApiClient::class);
|
||||
$this->travelLookupService = $this->createMock(TravelIndex::class);
|
||||
|
||||
$dateId = 12345;
|
||||
$hotelId = 67890;
|
||||
|
||||
@@ -212,13 +237,15 @@ class TravelDataProviderTest extends TestCase
|
||||
->expects($this->never())
|
||||
->method('getTravelData');
|
||||
|
||||
$result = $this->service->getTravelDataFromApi($dateId, $hotelId);
|
||||
$result = $this->service()->getTravelDataFromApi($dateId, $hotelId);
|
||||
|
||||
$this->assertNull($result);
|
||||
}
|
||||
|
||||
public function testExistsLocallyDelegatesToLookupService(): void
|
||||
{
|
||||
$this->travelLookupService = $this->createMock(TravelIndex::class);
|
||||
|
||||
$dateId = 12345;
|
||||
$hotelId = 67890;
|
||||
|
||||
@@ -228,11 +255,13 @@ class TravelDataProviderTest extends TestCase
|
||||
->with($dateId, $hotelId)
|
||||
->willReturn(true);
|
||||
|
||||
$this->assertTrue($this->service->existsLocally($dateId, $hotelId));
|
||||
$this->assertTrue($this->service()->existsLocally($dateId, $hotelId));
|
||||
}
|
||||
|
||||
public function testGetAvailableSourcesDelegatesToLookupService(): void
|
||||
{
|
||||
$this->travelLookupService = $this->createMock(TravelIndex::class);
|
||||
|
||||
$dateId = 12345;
|
||||
$hotelId = 67890;
|
||||
$expected = ['local' => true, 'remote' => true];
|
||||
@@ -243,11 +272,13 @@ class TravelDataProviderTest extends TestCase
|
||||
->with($dateId, $hotelId)
|
||||
->willReturn($expected);
|
||||
|
||||
$this->assertSame($expected, $this->service->getAvailableSources($dateId, $hotelId));
|
||||
$this->assertSame($expected, $this->service()->getAvailableSources($dateId, $hotelId));
|
||||
}
|
||||
|
||||
public function testGenerateFilesMapDelegatesToLookupService(): void
|
||||
{
|
||||
$this->travelLookupService = $this->createMock(TravelIndex::class);
|
||||
|
||||
$mapping = [12345 => ['id' => 12345, 'hotels' => []]];
|
||||
|
||||
$this->travelLookupService
|
||||
@@ -255,11 +286,15 @@ class TravelDataProviderTest extends TestCase
|
||||
->method('generateFilesMap')
|
||||
->willReturn($mapping);
|
||||
|
||||
$this->assertSame($mapping, $this->service->generateFilesMap());
|
||||
$this->assertSame($mapping, $this->service()->generateFilesMap());
|
||||
}
|
||||
|
||||
public function testGetTravelDataFromLocalPrefersSnapshot(): void
|
||||
{
|
||||
$this->travelLoader = $this->createMock(TravelLoader::class);
|
||||
$this->travelSnapshotService = $this->createMock(TravelSnapshotManager::class);
|
||||
$this->travelEnrichmentService = $this->createMock(TravelEnricher::class);
|
||||
|
||||
$dateId = 12345;
|
||||
$hotelId = 67890;
|
||||
$travel = new Travel();
|
||||
@@ -281,13 +316,17 @@ class TravelDataProviderTest extends TestCase
|
||||
->method('patchInsurances')
|
||||
->with($travel);
|
||||
|
||||
$result = $this->service->getTravelDataFromLocal($dateId, $hotelId);
|
||||
$result = $this->service()->getTravelDataFromLocal($dateId, $hotelId);
|
||||
|
||||
$this->assertSame($travel, $result);
|
||||
}
|
||||
|
||||
public function testGetTravelDataFromLocalFallsBackToXmlWhenSnapshotMissing(): void
|
||||
{
|
||||
$this->travelLoader = $this->createMock(TravelLoader::class);
|
||||
$this->travelSnapshotService = $this->createMock(TravelSnapshotManager::class);
|
||||
$this->travelEnrichmentService = $this->createMock(TravelEnricher::class);
|
||||
|
||||
$dateId = 12345;
|
||||
$hotelId = 67890;
|
||||
$travel = new Travel();
|
||||
@@ -322,13 +361,16 @@ class TravelDataProviderTest extends TestCase
|
||||
->method('patchInsurances')
|
||||
->with($travel);
|
||||
|
||||
$result = $this->service->getTravelDataFromLocal($dateId, $hotelId);
|
||||
$result = $this->service()->getTravelDataFromLocal($dateId, $hotelId);
|
||||
|
||||
$this->assertSame($travel, $result);
|
||||
}
|
||||
|
||||
public function testGetTravelDataFromLocalPropagatesTravelNotFoundFromXmlFallback(): void
|
||||
{
|
||||
$this->travelLoader = $this->createMock(TravelLoader::class);
|
||||
$this->travelSnapshotService = $this->createMock(TravelSnapshotManager::class);
|
||||
|
||||
$dateId = 12345;
|
||||
$hotelId = 67890;
|
||||
|
||||
@@ -345,11 +387,15 @@ class TravelDataProviderTest extends TestCase
|
||||
->willThrowException(new TravelNotFoundException($dateId));
|
||||
|
||||
$this->expectException(TravelNotFoundException::class);
|
||||
$this->service->getTravelDataFromLocal($dateId, $hotelId);
|
||||
$this->service()->getTravelDataFromLocal($dateId, $hotelId);
|
||||
}
|
||||
|
||||
public function testSnapshotLoadFailureFallsBackToXml(): void
|
||||
{
|
||||
$this->travelLoader = $this->createMock(TravelLoader::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
$this->travelSnapshotService = $this->createMock(TravelSnapshotManager::class);
|
||||
|
||||
$dateId = 12345;
|
||||
$hotelId = 67890;
|
||||
$travel = new Travel();
|
||||
@@ -373,13 +419,17 @@ class TravelDataProviderTest extends TestCase
|
||||
->with($dateId, $hotelId)
|
||||
->willReturn($travel);
|
||||
|
||||
$result = $this->service->getTravelDataFromLocal($dateId, $hotelId);
|
||||
$result = $this->service()->getTravelDataFromLocal($dateId, $hotelId);
|
||||
|
||||
$this->assertSame($travel, $result);
|
||||
}
|
||||
|
||||
public function testSnapshotPersistenceFailureDoesNotDiscardXmlTravel(): void
|
||||
{
|
||||
$this->travelLoader = $this->createMock(TravelLoader::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
$this->travelSnapshotService = $this->createMock(TravelSnapshotManager::class);
|
||||
|
||||
$dateId = 12345;
|
||||
$hotelId = 67890;
|
||||
$travel = new Travel();
|
||||
@@ -406,7 +456,7 @@ class TravelDataProviderTest extends TestCase
|
||||
->method('warning')
|
||||
->with('Failed to persist travel snapshot after XML load', $this->arrayHasKey('dateId'));
|
||||
|
||||
$result = $this->service->getTravelDataFromXml($dateId, $hotelId);
|
||||
$result = $this->service()->getTravelDataFromXml($dateId, $hotelId);
|
||||
|
||||
$this->assertNotNull($result);
|
||||
$this->assertSame($travel, $result);
|
||||
@@ -414,6 +464,10 @@ class TravelDataProviderTest extends TestCase
|
||||
|
||||
public function testGetTravelDataDelegatesToLoadUncached(): void
|
||||
{
|
||||
$this->travelLoader = $this->createMock(TravelLoader::class);
|
||||
$this->cache = $this->createMock(CacheInterface::class);
|
||||
$this->travelSnapshotService = $this->createMock(TravelSnapshotManager::class);
|
||||
|
||||
$dateId = 12345;
|
||||
$hotelId = 67890;
|
||||
$travel = new Travel();
|
||||
@@ -436,7 +490,7 @@ class TravelDataProviderTest extends TestCase
|
||||
->with($dateId, $hotelId)
|
||||
->willReturn($travel);
|
||||
|
||||
$result = $this->service->getTravelData($dateId, $hotelId, false);
|
||||
$result = $this->service()->getTravelData($dateId, $hotelId, false);
|
||||
|
||||
$this->assertSame($travel, $result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user