|
16 | 16 | use Cog\DbLocker\LockId\LockId;
|
17 | 17 | use Cog\DbLocker\LockId\PostgresLockId;
|
18 | 18 | use Cog\Test\DbLocker\Unit\AbstractUnitTestCase;
|
| 19 | +use PHPUnit\Framework\Attributes\DataProvider; |
19 | 20 |
|
20 | 21 | final class PostgresLockIdTest extends AbstractUnitTestCase
|
21 | 22 | {
|
22 | 23 | private const DB_INT32_VALUE_MIN = -2_147_483_648;
|
23 | 24 | private const DB_INT32_VALUE_MAX = 2_147_483_647;
|
24 | 25 |
|
25 |
| - public function test_it_can_create_postgres_lock_id_with_min_class_id(): void |
26 |
| - { |
27 |
| - $lockId = new PostgresLockId(self::DB_INT32_VALUE_MIN, 0); |
| 26 | + #[DataProvider('provideItCanCreatePostgresLockIdData')] |
| 27 | + public function testItCanCreatePostgresLockId( |
| 28 | + int $classId, |
| 29 | + int $objectId, |
| 30 | + ): void { |
| 31 | + $lockId = new PostgresLockId($classId, $objectId); |
28 | 32 |
|
29 |
| - $this->assertSame(self::DB_INT32_VALUE_MIN, $lockId->classId); |
| 33 | + $this->assertSame($classId, $lockId->classId); |
| 34 | + $this->assertSame($objectId, $lockId->objectId); |
30 | 35 | }
|
31 | 36 |
|
32 |
| - public function test_it_can_create_postgres_lock_id_with_max_class_id(): void |
| 37 | + public static function provideItCanCreatePostgresLockIdData(): array |
33 | 38 | {
|
34 |
| - $lockId = new PostgresLockId(self::DB_INT32_VALUE_MAX, 0); |
35 |
| - |
36 |
| - $this->assertSame(self::DB_INT32_VALUE_MAX, $lockId->classId); |
| 39 | + return [ |
| 40 | + 'min class_id' => [ |
| 41 | + self::DB_INT32_VALUE_MIN, |
| 42 | + 0, |
| 43 | + ], |
| 44 | + 'max class_id' => [ |
| 45 | + self::DB_INT32_VALUE_MAX, |
| 46 | + 0, |
| 47 | + ], |
| 48 | + 'min object_id' => [ |
| 49 | + 0, |
| 50 | + self::DB_INT32_VALUE_MIN, |
| 51 | + ], |
| 52 | + 'max object_id' => [ |
| 53 | + 0, |
| 54 | + self::DB_INT32_VALUE_MAX, |
| 55 | + ], |
| 56 | + ]; |
37 | 57 | }
|
38 | 58 |
|
39 |
| - public function test_it_can_create_postgres_lock_id_with_min_object_id(): void |
40 |
| - { |
41 |
| - $lockId = new PostgresLockId(0, self::DB_INT32_VALUE_MIN); |
| 59 | + #[DataProvider('provideItCanCreatePostgresLockIdFromLockIdData')] |
| 60 | + public function testItCanCreatePostgresLockIdFromLockId( |
| 61 | + LockId $lockId, |
| 62 | + int $expectedClassId, |
| 63 | + int $expectedObjectId, |
| 64 | + ): void { |
| 65 | + $postgresLockId = PostgresLockId::fromLockId($lockId); |
42 | 66 |
|
43 |
| - $this->assertSame(self::DB_INT32_VALUE_MIN, $lockId->objectId); |
| 67 | + $this->assertSame($expectedClassId, $postgresLockId->classId); |
| 68 | + $this->assertSame($expectedObjectId, $postgresLockId->objectId); |
44 | 69 | }
|
45 | 70 |
|
46 |
| - public function test_it_can_create_postgres_lock_id_with_max_object_id(): void |
| 71 | + public static function provideItCanCreatePostgresLockIdFromLockIdData(): array |
47 | 72 | {
|
48 |
| - $lockId = new PostgresLockId(0, self::DB_INT32_VALUE_MAX); |
49 |
| - |
50 |
| - $this->assertSame(self::DB_INT32_VALUE_MAX, $lockId->objectId); |
| 73 | + return [ |
| 74 | + 'key only' => [ |
| 75 | + new LockId('test'), |
| 76 | + -662733300, |
| 77 | + 0, |
| 78 | + ], |
| 79 | + 'key + value' => [ |
| 80 | + new LockId('test', '1'), |
| 81 | + -662733300, |
| 82 | + -2082672713, |
| 83 | + ], |
| 84 | + ]; |
51 | 85 | }
|
52 | 86 |
|
53 |
| - public function test_it_can_create_postgres_lock_id_from_lock_id(): void |
54 |
| - { |
55 |
| - $lockId = new LockId('test'); |
56 |
| - |
57 |
| - $postgresLockId = PostgresLockId::fromLockId($lockId); |
58 |
| - |
59 |
| - $this->assertSame(-662733300, $postgresLockId->classId); |
| 87 | + #[DataProvider('provideItCanCreatePostgresLockIdFromKeyValueData')] |
| 88 | + public function testItCanCreatePostgresLockIdFromKeyValue( |
| 89 | + string $key, |
| 90 | + string $value, |
| 91 | + int $expectedClassId, |
| 92 | + int $expectedObjectId, |
| 93 | + ): void { |
| 94 | + $postgresLockId = PostgresLockId::fromKeyValue($key, $value); |
| 95 | + |
| 96 | + $this->assertSame($expectedClassId, $postgresLockId->classId); |
| 97 | + $this->assertSame($expectedObjectId, $postgresLockId->objectId); |
60 | 98 | }
|
61 | 99 |
|
62 |
| - public function test_it_can_create_postgres_lock_id_from_lock_id_with_value(): void |
| 100 | + public static function provideItCanCreatePostgresLockIdFromKeyValueData(): array |
63 | 101 | {
|
64 |
| - $lockId = new LockId('test', '1'); |
65 |
| - |
66 |
| - $postgresLockId = PostgresLockId::fromLockId($lockId); |
67 |
| - |
68 |
| - $this->assertSame(-662733300, $postgresLockId->classId); |
| 102 | + return [ |
| 103 | + 'key + empty value' => [ |
| 104 | + 'test', |
| 105 | + '', |
| 106 | + -662733300, |
| 107 | + 0, |
| 108 | + ], |
| 109 | + 'key + value' => [ |
| 110 | + 'test', |
| 111 | + '1', |
| 112 | + -662733300, |
| 113 | + -2082672713, |
| 114 | + ], |
| 115 | + ]; |
69 | 116 | }
|
70 | 117 | }
|
0 commit comments