@@ -23,35 +23,33 @@ final class PostgresLockIdTest extends AbstractUnitTestCase
23
23
private const DB_INT32_VALUE_MIN = -2_147_483_648 ;
24
24
private const DB_INT32_VALUE_MAX = 2_147_483_647 ;
25
25
26
- #[DataProvider('provideItCanCreatePostgresLockIdData ' )]
27
- public function testItCanCreatePostgresLockId (
28
- int $ classId ,
29
- int $ objectId ,
26
+ #[DataProvider('provideItCanCreatePostgresLockIdFromKeyValueData ' )]
27
+ public function testItCanCreatePostgresLockIdFromKeyValue (
28
+ string $ key ,
29
+ string $ value ,
30
+ int $ expectedClassId ,
31
+ int $ expectedObjectId ,
30
32
): void {
31
- $ lockId = new PostgresLockId ( $ classId , $ objectId );
33
+ $ postgresLockId = PostgresLockId:: fromKeyValue ( $ key , $ value );
32
34
33
- $ this ->assertSame ($ classId , $ lockId ->classId );
34
- $ this ->assertSame ($ objectId , $ lockId ->objectId );
35
+ $ this ->assertSame ($ expectedClassId , $ postgresLockId ->classId );
36
+ $ this ->assertSame ($ expectedObjectId , $ postgresLockId ->objectId );
35
37
}
36
38
37
- public static function provideItCanCreatePostgresLockIdData (): array
39
+ public static function provideItCanCreatePostgresLockIdFromKeyValueData (): array
38
40
{
39
41
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 ' => [
42
+ 'key + empty value ' => [
43
+ 'test ' ,
44
+ '' ,
45
+ -662733300 ,
49
46
0 ,
50
- self ::DB_INT32_VALUE_MIN ,
51
47
],
52
- 'max object_id ' => [
53
- 0 ,
54
- self ::DB_INT32_VALUE_MAX ,
48
+ 'key + value ' => [
49
+ 'test ' ,
50
+ '1 ' ,
51
+ -662733300 ,
52
+ -2082672713 ,
55
53
],
56
54
];
57
55
}
@@ -84,33 +82,76 @@ public static function provideItCanCreatePostgresLockIdFromLockIdData(): array
84
82
];
85
83
}
86
84
87
- #[DataProvider('provideItCanCreatePostgresLockIdFromKeyValueData ' )]
88
- public function testItCanCreatePostgresLockIdFromKeyValue (
89
- string $ key ,
90
- string $ value ,
91
- int $ expectedClassId ,
92
- int $ expectedObjectId ,
85
+ #[DataProvider('provideItCanCreatePostgresLockIdFromIntKeysData ' )]
86
+ public function testItCanCreatePostgresLockIdFromIntKeys (
87
+ int $ classId ,
88
+ int $ objectId ,
93
89
): void {
94
- $ postgresLockId = PostgresLockId::fromKeyValue ( $ key , $ value );
90
+ $ lockId = PostgresLockId::fromIntKeys ( $ classId , $ objectId );
95
91
96
- $ this ->assertSame ($ expectedClassId , $ postgresLockId ->classId );
97
- $ this ->assertSame ($ expectedObjectId , $ postgresLockId ->objectId );
92
+ $ this ->assertSame ($ classId , $ lockId ->classId );
93
+ $ this ->assertSame ($ objectId , $ lockId ->objectId );
98
94
}
99
95
100
- public static function provideItCanCreatePostgresLockIdFromKeyValueData (): array
96
+ public static function provideItCanCreatePostgresLockIdFromIntKeysData (): array
101
97
{
102
98
return [
103
- 'key + empty value ' => [
104
- 'test ' ,
105
- '' ,
106
- -662733300 ,
99
+ 'min class_id ' => [
100
+ self ::DB_INT32_VALUE_MIN ,
107
101
0 ,
108
102
],
109
- 'key + value ' => [
110
- 'test ' ,
111
- '1 ' ,
112
- -662733300 ,
113
- -2082672713 ,
103
+ 'max class_id ' => [
104
+ self ::DB_INT32_VALUE_MAX ,
105
+ 0 ,
106
+ ],
107
+ 'min object_id ' => [
108
+ 0 ,
109
+ self ::DB_INT32_VALUE_MIN ,
110
+ ],
111
+ 'max object_id ' => [
112
+ 0 ,
113
+ self ::DB_INT32_VALUE_MAX ,
114
+ ],
115
+ ];
116
+ }
117
+
118
+ #[DataProvider('provideItCanCreatePostgresLockIdFromOutOfRangeIntKeysData ' )]
119
+ public function testItCanNotCreatePostgresLockIdFromOutOfRangeIntKeys (
120
+ int $ classId ,
121
+ int $ objectId ,
122
+ string $ expectedExceptionMessage ,
123
+ ): void {
124
+ $ this ->expectException (\InvalidArgumentException::class);
125
+ $ this ->expectExceptionMessage ($ expectedExceptionMessage );
126
+
127
+ $ lockId = PostgresLockId::fromIntKeys ($ classId , $ objectId );
128
+
129
+ $ this ->assertSame ($ classId , $ lockId ->classId );
130
+ $ this ->assertSame ($ objectId , $ lockId ->objectId );
131
+ }
132
+
133
+ public static function provideItCanCreatePostgresLockIdFromOutOfRangeIntKeysData (): array
134
+ {
135
+ return [
136
+ 'min class_id ' => [
137
+ self ::DB_INT32_VALUE_MIN - 1 ,
138
+ 0 ,
139
+ "Out of bound exception (classId=-2147483649 is too small) "
140
+ ],
141
+ 'max class_id ' => [
142
+ self ::DB_INT32_VALUE_MAX + 1 ,
143
+ 0 ,
144
+ "Out of bound exception (classId=2147483648 is too big) "
145
+ ],
146
+ 'min object_id ' => [
147
+ 0 ,
148
+ self ::DB_INT32_VALUE_MIN - 1 ,
149
+ "Out of bound exception (objectId=-2147483649 is too small) "
150
+ ],
151
+ 'max object_id ' => [
152
+ 0 ,
153
+ self ::DB_INT32_VALUE_MAX + 1 ,
154
+ "Out of bound exception (objectId=2147483648 is too big) "
114
155
],
115
156
];
116
157
}
0 commit comments