@@ -23,35 +23,33 @@ final class PostgresLockIdTest extends AbstractUnitTestCase
2323 private const DB_INT32_VALUE_MIN = -2_147_483_648 ;
2424 private const DB_INT32_VALUE_MAX = 2_147_483_647 ;
2525
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 ,
3032 ): void {
31- $ lockId = new PostgresLockId ( $ classId , $ objectId );
33+ $ postgresLockId = PostgresLockId:: fromKeyValue ( $ key , $ value );
3234
33- $ this ->assertSame ($ classId , $ lockId ->classId );
34- $ this ->assertSame ($ objectId , $ lockId ->objectId );
35+ $ this ->assertSame ($ expectedClassId , $ postgresLockId ->classId );
36+ $ this ->assertSame ($ expectedObjectId , $ postgresLockId ->objectId );
3537 }
3638
37- public static function provideItCanCreatePostgresLockIdData (): array
39+ public static function provideItCanCreatePostgresLockIdFromKeyValueData (): array
3840 {
3941 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 ,
4946 0 ,
50- self ::DB_INT32_VALUE_MIN ,
5147 ],
52- 'max object_id ' => [
53- 0 ,
54- self ::DB_INT32_VALUE_MAX ,
48+ 'key + value ' => [
49+ 'test ' ,
50+ '1 ' ,
51+ -662733300 ,
52+ -2082672713 ,
5553 ],
5654 ];
5755 }
@@ -84,33 +82,76 @@ public static function provideItCanCreatePostgresLockIdFromLockIdData(): array
8482 ];
8583 }
8684
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 ,
9389 ): void {
94- $ postgresLockId = PostgresLockId::fromKeyValue ( $ key , $ value );
90+ $ lockId = PostgresLockId::fromIntKeys ( $ classId , $ objectId );
9591
96- $ this ->assertSame ($ expectedClassId , $ postgresLockId ->classId );
97- $ this ->assertSame ($ expectedObjectId , $ postgresLockId ->objectId );
92+ $ this ->assertSame ($ classId , $ lockId ->classId );
93+ $ this ->assertSame ($ objectId , $ lockId ->objectId );
9894 }
9995
100- public static function provideItCanCreatePostgresLockIdFromKeyValueData (): array
96+ public static function provideItCanCreatePostgresLockIdFromIntKeysData (): array
10197 {
10298 return [
103- 'key + empty value ' => [
104- 'test ' ,
105- '' ,
106- -662733300 ,
99+ 'min class_id ' => [
100+ self ::DB_INT32_VALUE_MIN ,
107101 0 ,
108102 ],
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) "
114155 ],
115156 ];
116157 }
0 commit comments