47 lines
1.4 KiB
PHP
47 lines
1.4 KiB
PHP
<?php
|
|
/**
|
|
* Tests for sync state persistence.
|
|
*
|
|
* @package WPContentSync
|
|
*/
|
|
|
|
namespace WPContentSync\Tests\Unit\Sync;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use WPContentSync\Sync\SyncOperationState;
|
|
use WPContentSync\Sync\SyncStateRepository;
|
|
|
|
class SyncStateRepositoryTest extends TestCase {
|
|
protected function tearDown(): void {
|
|
unset( $GLOBALS['wpcs_test_transients'], $GLOBALS['wpcs_test_transient_expiration'] );
|
|
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function test_it_saves_and_reads_operation_state(): void {
|
|
$repository = new SyncStateRepository();
|
|
$state = SyncOperationState::running( 'operation-1', 'posts', 2, 10 );
|
|
|
|
$repository->save( $state );
|
|
|
|
$loaded = $repository->get( 'operation-1' );
|
|
|
|
self::assertInstanceOf( SyncOperationState::class, $loaded );
|
|
self::assertSame( 'operation-1', $loaded->operationId() );
|
|
self::assertSame( 'posts', $loaded->currentBucket() );
|
|
self::assertSame( 2, $loaded->processed() );
|
|
self::assertSame( 10, $loaded->total() );
|
|
self::assertSame( 'running', $loaded->status() );
|
|
}
|
|
|
|
public function test_it_deletes_operation_state(): void {
|
|
$repository = new SyncStateRepository();
|
|
$repository->save( SyncOperationState::completed( 'operation-1', 10, 10 ) );
|
|
|
|
$repository->delete( 'operation-1' );
|
|
|
|
self::assertNull( $repository->get( 'operation-1' ) );
|
|
self::assertArrayNotHasKey( 'wpcs_sync_state_operation-1', $GLOBALS['wpcs_test_transient_expiration'] );
|
|
}
|
|
}
|