Maintain local ⭤ remote in sync with automatic AT Protocol parity for Laravel (alpha & unstable)
at main 66 lines 2.2 kB view raw
1<?php 2 3namespace SocialDept\AtpParity\Tests\Unit\Sync; 4 5use SocialDept\AtpParity\Sync\ConflictResolution; 6use SocialDept\AtpParity\Sync\PendingConflict; 7use SocialDept\AtpParity\Tests\Fixtures\TestModel; 8use SocialDept\AtpParity\Tests\TestCase; 9 10class ConflictResolutionTest extends TestCase 11{ 12 public function test_remote_wins_creates_resolved_resolution(): void 13 { 14 $model = new TestModel(); 15 16 $resolution = ConflictResolution::remoteWins($model); 17 18 $this->assertTrue($resolution->isResolved()); 19 $this->assertFalse($resolution->isPending()); 20 $this->assertSame('remote', $resolution->winner); 21 $this->assertSame($model, $resolution->model); 22 $this->assertNull($resolution->pending); 23 } 24 25 public function test_local_wins_creates_resolved_resolution(): void 26 { 27 $model = new TestModel(); 28 29 $resolution = ConflictResolution::localWins($model); 30 31 $this->assertTrue($resolution->isResolved()); 32 $this->assertFalse($resolution->isPending()); 33 $this->assertSame('local', $resolution->winner); 34 $this->assertSame($model, $resolution->model); 35 $this->assertNull($resolution->pending); 36 } 37 38 public function test_pending_creates_unresolved_resolution(): void 39 { 40 $pending = new PendingConflict(); 41 42 $resolution = ConflictResolution::pending($pending); 43 44 $this->assertFalse($resolution->isResolved()); 45 $this->assertTrue($resolution->isPending()); 46 $this->assertSame('manual', $resolution->winner); 47 $this->assertNull($resolution->model); 48 $this->assertSame($pending, $resolution->pending); 49 } 50 51 public function test_is_resolved_returns_correct_boolean(): void 52 { 53 $resolved = new ConflictResolution(resolved: true, winner: 'remote'); 54 $unresolved = new ConflictResolution(resolved: false, winner: 'manual'); 55 56 $this->assertTrue($resolved->isResolved()); 57 $this->assertFalse($unresolved->isResolved()); 58 } 59 60 public function test_is_pending_returns_false_when_no_pending_conflict(): void 61 { 62 $resolution = new ConflictResolution(resolved: false, winner: 'manual'); 63 64 $this->assertFalse($resolution->isPending()); 65 } 66}