chore: remote obsolete contingents-related plumbing
This commit is contained in:
@@ -6,13 +6,12 @@ namespace App\Tests\Command;
|
||||
|
||||
use App\BusProNet\XmlLoader\TravelLoader;
|
||||
use App\Command\BpnXmlSyncCommand;
|
||||
use App\Service\BpnXmlSyncManager;
|
||||
use App\Service\BpnXmlSnapshotRefreshManager;
|
||||
use App\Service\BpnXmlSyncManager;
|
||||
use App\Service\TravelDataProvider;
|
||||
use App\Service\TravelSnapshotManager;
|
||||
use League\Flysystem\DirectoryListing;
|
||||
use League\Flysystem\FilesystemOperator;
|
||||
use League\Flysystem\UnableToListContents;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
@@ -23,8 +22,6 @@ class BpnXmlSyncCommandTest extends TestCase
|
||||
{
|
||||
private FilesystemOperator $xmlSource;
|
||||
private FilesystemOperator $xmlExport;
|
||||
private FilesystemOperator $xmlSourceContingents;
|
||||
private FilesystemOperator $xmlExportContingents;
|
||||
private TagAwareCacheInterface $cache;
|
||||
private LoggerInterface $logger;
|
||||
private TravelLoader $travelLoader;
|
||||
@@ -36,7 +33,6 @@ class BpnXmlSyncCommandTest extends TestCase
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
// Release the filesystem lock held by LockableTrait so subsequent tests can acquire it.
|
||||
$release = new \ReflectionMethod($this->command, 'release');
|
||||
$release->setAccessible(true);
|
||||
$release->invoke($this->command);
|
||||
@@ -46,8 +42,6 @@ class BpnXmlSyncCommandTest extends TestCase
|
||||
{
|
||||
$this->xmlSource = $this->createMock(FilesystemOperator::class);
|
||||
$this->xmlExport = $this->createMock(FilesystemOperator::class);
|
||||
$this->xmlSourceContingents = $this->createMock(FilesystemOperator::class);
|
||||
$this->xmlExportContingents = $this->createMock(FilesystemOperator::class);
|
||||
$this->cache = $this->createMock(TagAwareCacheInterface::class);
|
||||
$this->logger = $this->createMock(LoggerInterface::class);
|
||||
$this->travelLoader = $this->createMock(TravelLoader::class);
|
||||
@@ -63,8 +57,6 @@ class BpnXmlSyncCommandTest extends TestCase
|
||||
$this->syncManager = new BpnXmlSyncManager(
|
||||
$this->xmlSource,
|
||||
$this->xmlExport,
|
||||
$this->xmlSourceContingents,
|
||||
$this->xmlExportContingents,
|
||||
$this->cache,
|
||||
$this->logger,
|
||||
);
|
||||
@@ -76,9 +68,6 @@ class BpnXmlSyncCommandTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remote newer than local -> files downloaded -> syncSnapshotsFromXml() called once.
|
||||
*/
|
||||
public function testSnapshotSyncIsTriggeredAfterSuccessfulFileDownload(): void
|
||||
{
|
||||
$newerTimestamp = "24.03.2026 12:00:00\nExport\n3 Dateien\n";
|
||||
@@ -90,12 +79,6 @@ class BpnXmlSyncCommandTest extends TestCase
|
||||
$this->xmlSource->method('listContents')->willReturn(new DirectoryListing([]));
|
||||
$this->xmlExport->method('listContents')->willReturn(new DirectoryListing([]));
|
||||
|
||||
$this->xmlSourceContingents->method('read')->willReturn($olderTimestamp);
|
||||
$this->xmlExportContingents->method('fileExists')->willReturn(true);
|
||||
$this->xmlExportContingents->method('read')->willReturn($olderTimestamp);
|
||||
$this->xmlSourceContingents->method('listContents')->willReturn(new DirectoryListing([]));
|
||||
$this->xmlExportContingents->method('listContents')->willReturn(new DirectoryListing([]));
|
||||
|
||||
$fileMap = [
|
||||
101 => ['hotels' => ['H1' => null, 'H2' => null]],
|
||||
102 => ['hotels' => ['H3' => null]],
|
||||
@@ -124,9 +107,6 @@ class BpnXmlSyncCommandTest extends TestCase
|
||||
$this->assertSame(Command::SUCCESS, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* Local already up to date -> early return before snapshot code is reached.
|
||||
*/
|
||||
public function testSnapshotSyncIsSkippedWhenLocalDataIsUpToDate(): void
|
||||
{
|
||||
$sameTimestamp = "24.03.2026 10:00:00\nExport\n3 Dateien\n";
|
||||
@@ -136,12 +116,6 @@ class BpnXmlSyncCommandTest extends TestCase
|
||||
$this->xmlSource->method('listContents')->willReturn(new DirectoryListing([]));
|
||||
$this->xmlExport->method('listContents')->willReturn(new DirectoryListing([]));
|
||||
|
||||
$this->xmlSourceContingents->method('read')->willReturn($sameTimestamp);
|
||||
$this->xmlExportContingents->method('fileExists')->willReturn(true);
|
||||
$this->xmlExportContingents->method('read')->willReturn($sameTimestamp);
|
||||
$this->xmlSourceContingents->method('listContents')->willReturn(new DirectoryListing([]));
|
||||
$this->xmlExportContingents->method('listContents')->willReturn(new DirectoryListing([]));
|
||||
|
||||
$this->travelLoader->expects($this->never())->method('generateFilesMap');
|
||||
$this->travelDataService->expects($this->never())->method('syncSnapshotsFromXml');
|
||||
$this->travelSnapshotService->expects($this->never())->method('purgeOrphanedFutureSnapshots');
|
||||
@@ -153,10 +127,6 @@ class BpnXmlSyncCommandTest extends TestCase
|
||||
$this->assertSame(Command::SUCCESS, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
/**
|
||||
* generateFilesMap() throws -> warning logged, syncSnapshotsFromXml() never called,
|
||||
* command still returns SUCCESS.
|
||||
*/
|
||||
public function testSnapshotSyncIsSkippedAndWarningLoggedWhenFileMapGenerationFails(): void
|
||||
{
|
||||
$newerTimestamp = "24.03.2026 12:00:00\nExport\n3 Dateien\n";
|
||||
@@ -168,12 +138,6 @@ class BpnXmlSyncCommandTest extends TestCase
|
||||
$this->xmlSource->method('listContents')->willReturn(new DirectoryListing([]));
|
||||
$this->xmlExport->method('listContents')->willReturn(new DirectoryListing([]));
|
||||
|
||||
$this->xmlSourceContingents->method('read')->willReturn($olderTimestamp);
|
||||
$this->xmlExportContingents->method('fileExists')->willReturn(true);
|
||||
$this->xmlExportContingents->method('read')->willReturn($olderTimestamp);
|
||||
$this->xmlSourceContingents->method('listContents')->willReturn(new DirectoryListing([]));
|
||||
$this->xmlExportContingents->method('listContents')->willReturn(new DirectoryListing([]));
|
||||
|
||||
$this->travelLoader->expects($this->once())
|
||||
->method('generateFilesMap')
|
||||
->willThrowException(new \RuntimeException('Storage unavailable'));
|
||||
@@ -194,84 +158,4 @@ class BpnXmlSyncCommandTest extends TestCase
|
||||
|
||||
$this->assertSame(Command::SUCCESS, $tester->getStatusCode());
|
||||
}
|
||||
|
||||
public function testContingentTransferFailureDoesNotFailSuccessfulTravelSync(): void
|
||||
{
|
||||
$newerTimestamp = "24.03.2026 12:00:00\nExport\n3 Dateien\n";
|
||||
$olderTimestamp = "24.03.2026 10:00:00\nExport\n3 Dateien\n";
|
||||
|
||||
$this->xmlSource->method('read')->willReturn($newerTimestamp);
|
||||
$this->xmlExport->method('fileExists')->willReturn(true);
|
||||
$this->xmlExport->method('read')->willReturn($olderTimestamp);
|
||||
$this->xmlSource->method('listContents')->willReturn(new DirectoryListing([]));
|
||||
$this->xmlExport->method('listContents')->willReturn(new DirectoryListing([]));
|
||||
|
||||
$this->xmlSourceContingents->method('read')->willReturn($newerTimestamp);
|
||||
$this->xmlExportContingents->method('fileExists')->willReturn(true);
|
||||
$this->xmlExportContingents->method('read')->willReturn($olderTimestamp);
|
||||
$this->xmlSourceContingents->method('listContents')
|
||||
->willThrowException(UnableToListContents::atLocation('.', false, new \RuntimeException('SFTP unavailable')));
|
||||
|
||||
$fileMap = [
|
||||
101 => ['hotels' => ['H1' => null]],
|
||||
];
|
||||
$this->travelLoader->expects($this->once())
|
||||
->method('generateFilesMap')
|
||||
->willReturn($fileMap);
|
||||
|
||||
$this->travelDataService->expects($this->once())
|
||||
->method('syncSnapshotsFromXml')
|
||||
->with($fileMap, $this->isInstanceOf(\Closure::class))
|
||||
->willReturn(['processed' => 1, 'failed' => 0]);
|
||||
|
||||
$this->travelSnapshotService->expects($this->once())
|
||||
->method('purgeOrphanedFutureSnapshots')
|
||||
->with([101])
|
||||
->willReturn(0);
|
||||
|
||||
$this->cache->expects($this->once())
|
||||
->method('invalidateTags')
|
||||
->with(['xml-sync']);
|
||||
|
||||
$tester = new CommandTester($this->command);
|
||||
$tester->execute([]);
|
||||
|
||||
$this->assertSame(Command::SUCCESS, $tester->getStatusCode());
|
||||
$this->assertStringContainsString('[contingents] Sync failed', $tester->getDisplay());
|
||||
$this->assertMatchesRegularExpression('/failed datasets:\s+contingents/', $tester->getDisplay());
|
||||
}
|
||||
|
||||
public function testTravelTransferFailureDoesNotPreventContingentsSync(): void
|
||||
{
|
||||
$newerTimestamp = "24.03.2026 12:00:00\nExport\n3 Dateien\n";
|
||||
$olderTimestamp = "24.03.2026 10:00:00\nExport\n3 Dateien\n";
|
||||
|
||||
$this->xmlSource->method('read')->willReturn($newerTimestamp);
|
||||
$this->xmlExport->method('fileExists')->willReturn(true);
|
||||
$this->xmlExport->method('read')->willReturn($olderTimestamp);
|
||||
$this->xmlSource->method('listContents')
|
||||
->willThrowException(UnableToListContents::atLocation('.', false, new \RuntimeException('SFTP unavailable')));
|
||||
|
||||
$this->xmlSourceContingents->method('read')->willReturn($newerTimestamp);
|
||||
$this->xmlExportContingents->method('fileExists')->willReturn(true);
|
||||
$this->xmlExportContingents->method('read')->willReturn($olderTimestamp);
|
||||
$this->xmlSourceContingents->method('listContents')->willReturn(new DirectoryListing([]));
|
||||
$this->xmlExportContingents->method('listContents')->willReturn(new DirectoryListing([]));
|
||||
|
||||
$this->travelLoader->expects($this->never())->method('generateFilesMap');
|
||||
$this->travelDataService->expects($this->never())->method('syncSnapshotsFromXml');
|
||||
$this->travelSnapshotService->expects($this->never())->method('purgeOrphanedFutureSnapshots');
|
||||
|
||||
$this->cache->expects($this->once())
|
||||
->method('invalidateTags')
|
||||
->with(['xml-sync']);
|
||||
|
||||
$tester = new CommandTester($this->command);
|
||||
$tester->execute([]);
|
||||
|
||||
$this->assertSame(Command::SUCCESS, $tester->getStatusCode());
|
||||
$this->assertStringContainsString('[travel] Sync failed', $tester->getDisplay());
|
||||
$this->assertStringContainsString('[contingents] Synced 0 files, deleted 0', $tester->getDisplay());
|
||||
$this->assertStringContainsString('datasets: travel', $tester->getDisplay());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user