Files
breadcrumb-the-shire/tests/Service/Import/ImportStateStoreServiceTest.php

47 lines
1.4 KiB
PHP
Raw Normal View History

2026-02-23 12:58:19 +01:00
<?php
namespace MintyPHP\Tests\Service\Import;
use MintyPHP\Service\Import\ImportStateStoreService;
use MintyPHP\Service\Import\ImportTempFileService;
use PHPUnit\Framework\TestCase;
class ImportStateStoreServiceTest extends TestCase
{
protected function setUp(): void
{
$_SESSION = [];
}
public function testSetGetAndClearState(): void
{
$tempFileService = $this->createMock(ImportTempFileService::class);
$stateStore = new ImportStateStoreService($tempFileService);
$stateStore->setState('token_a', ['token' => 'token_a', 'created_at' => time(), 'path' => '/tmp/a.csv']);
$loaded = $stateStore->getState('token_a');
$this->assertIsArray($loaded);
$this->assertSame('token_a', $loaded['token']);
$stateStore->clearState('token_a');
$this->assertNull($stateStore->getState('token_a'));
}
public function testExpiredStateGetsDeletedAndReturnsNull(): void
{
$tempFileService = $this->createMock(ImportTempFileService::class);
$tempFileService->expects($this->once())
->method('delete')
->with('/tmp/expired.csv');
$stateStore = new ImportStateStoreService($tempFileService);
$stateStore->setState('token_b', [
'token' => 'token_b',
'created_at' => time() - 7201,
'path' => '/tmp/expired.csv',
]);
$this->assertNull($stateStore->getState('token_b'));
}
}