Skip to content

Commit 6d6ef31

Browse files
committed
Rewrite locker API
1 parent 35ec747 commit 6d6ef31

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/LockId/PostgresLockId.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public static function fromKeyValue(
4646
return new self(
4747
classId: self::convertStringToSignedInt32($key),
4848
objectId: self::convertStringToSignedInt32($value),
49+
// TODO: Do we need to sanitize it?
50+
// TODO: Do we need to omit ":" on end if no value is passed
4951
humanReadableValue: "$key:$value",
5052
);
5153
}

test/Integration/Locker/PostgresAdvisoryLockerTest.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ final class PostgresAdvisoryLockerTest extends AbstractIntegrationTestCase
2727

2828
#[DataProvider('provideItCanTryAcquireLockWithinSessionData')]
2929
public function testItCanTryAcquireLockWithinSession(
30-
PostgresLockAccessModeEnum $mode,
30+
PostgresLockAccessModeEnum $accessMode,
3131
): void {
3232
$locker = $this->initLocker();
3333
$dbConnection = $this->initPostgresPdoConnection();
@@ -36,12 +36,12 @@ public function testItCanTryAcquireLockWithinSession(
3636
$isLockAcquired = $locker->acquireSessionLevelLock(
3737
$dbConnection,
3838
$postgresLockId,
39-
accessMode: $mode,
39+
accessMode: $accessMode,
4040
);
4141

4242
$this->assertTrue($isLockAcquired);
4343
$this->assertPgAdvisoryLocksCount(1);
44-
$this->assertPgAdvisoryLockExistsInConnection($dbConnection, $postgresLockId, $mode);
44+
$this->assertPgAdvisoryLockExistsInConnection($dbConnection, $postgresLockId, $accessMode);
4545
}
4646

4747
public static function provideItCanTryAcquireLockWithinSessionData(): array
@@ -58,7 +58,7 @@ public static function provideItCanTryAcquireLockWithinSessionData(): array
5858

5959
#[DataProvider('provideItCanTryAcquireLockWithinTransactionData')]
6060
public function testItCanTryAcquireLockWithinTransaction(
61-
PostgresLockAccessModeEnum $mode,
61+
PostgresLockAccessModeEnum $accessMode,
6262
): void {
6363
$locker = $this->initLocker();
6464
$dbConnection = $this->initPostgresPdoConnection();
@@ -68,12 +68,12 @@ public function testItCanTryAcquireLockWithinTransaction(
6868
$isLockAcquired = $locker->acquireTransactionLevelLock(
6969
$dbConnection,
7070
$postgresLockId,
71-
accessMode: $mode,
71+
accessMode: $accessMode,
7272
);
7373

7474
$this->assertTrue($isLockAcquired);
7575
$this->assertPgAdvisoryLocksCount(1);
76-
$this->assertPgAdvisoryLockExistsInConnection($dbConnection, $postgresLockId, $mode);
76+
$this->assertPgAdvisoryLockExistsInConnection($dbConnection, $postgresLockId, $accessMode);
7777
}
7878

7979
public static function provideItCanTryAcquireLockWithinTransactionData(): array
@@ -194,21 +194,21 @@ public function testItCannotAcquireSameLockInTwoConnections(): void
194194

195195
#[DataProvider('provideItCanReleaseLockData')]
196196
public function testItCanReleaseLock(
197-
PostgresLockAccessModeEnum $mode,
197+
PostgresLockAccessModeEnum $accessMode,
198198
): void {
199199
$locker = $this->initLocker();
200200
$dbConnection = $this->initPostgresPdoConnection();
201201
$postgresLockId = PostgresLockId::fromKeyValue('test');
202202
$locker->acquireSessionLevelLock(
203203
$dbConnection,
204204
$postgresLockId,
205-
accessMode: $mode,
205+
accessMode: $accessMode,
206206
);
207207

208208
$isLockReleased = $locker->releaseSessionLevelLock(
209209
$dbConnection,
210210
$postgresLockId,
211-
accessMode: $mode,
211+
accessMode: $accessMode,
212212
);
213213

214214
$this->assertTrue($isLockReleased);
@@ -256,12 +256,12 @@ public static function provideItCanNotReleaseLockOfDifferentModesData(): array
256256
{
257257
return [
258258
'release exclusive lock as share' => [
259-
'acquireMode' => PostgresLockAccessModeEnum::Exclusive,
260-
'releaseMode' => PostgresLockAccessModeEnum::Share,
259+
'acquireAccessMode' => PostgresLockAccessModeEnum::Exclusive,
260+
'releaseAccessMode' => PostgresLockAccessModeEnum::Share,
261261
],
262262
'release share lock as exclusive' => [
263-
'acquireMode' => PostgresLockAccessModeEnum::Share,
264-
'releaseMode' => PostgresLockAccessModeEnum::Exclusive,
263+
'acquireAccessMode' => PostgresLockAccessModeEnum::Share,
264+
'releaseAccessMode' => PostgresLockAccessModeEnum::Exclusive,
265265
],
266266
];
267267
}

0 commit comments

Comments
 (0)