Skip to content

Commit 478bab1

Browse files
committed
minor improvements
1 parent 86dc331 commit 478bab1

File tree

7 files changed

+25
-25
lines changed

7 files changed

+25
-25
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ extension if possible or busy waiting if not.
194194
#### MemcachedMutex
195195

196196
The **MemcachedMutex** is a spinlock implementation which uses the
197-
[`Memcached` API](http://php.net/manual/en/book.memcached.php).
197+
[`Memcached` extension](http://php.net/manual/en/book.memcached.php).
198198

199199
Example:
200200
```php

src/Mutex/RedisMutex.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use Predis\PredisException;
1111

1212
/**
13-
* Mutex based on the Redlock algorithm supporting the phpredis extension and Predis API.
13+
* Distributed mutex based on the Redlock algorithm supporting the phpredis extension and Predis API.
1414
*
1515
* @phpstan-type TClient \Redis|\RedisCluster|PredisClientInterface
1616
*

tests/Mutex/AbstractRedlockMutexTest.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ protected function setUp(): void
4545
}
4646

4747
/**
48-
* @param int $count The amount of redis apis
48+
* @param int $count The amount of redis APIs
4949
*
5050
* @return AbstractRedlockMutex<object>&MockObject
5151
*/
52-
private function createAbstractRedlockMutexMock(int $count, float $timeout = 1): AbstractRedlockMutex
52+
private function createRedlockMutexMock(int $count, float $timeout = 1): AbstractRedlockMutex
5353
{
5454
$clients = array_map(
5555
static fn ($id) => ['id' => $id],
@@ -76,7 +76,7 @@ public function testTooFewServerToAcquire(int $count, int $available): void
7676
$this->expectException(LockAcquireException::class);
7777
$this->expectExceptionCode(MutexException::REDIS_NOT_ENOUGH_SERVERS);
7878

79-
$mutex = $this->createAbstractRedlockMutexMock($count);
79+
$mutex = $this->createRedlockMutexMock($count);
8080

8181
$i = 0;
8282
$mutex->expects(self::exactly($count))
@@ -109,7 +109,7 @@ static function () use (&$i, $available): bool {
109109
#[DataProvider('provideMajorityCases')]
110110
public function testFaultTolerance(int $count, int $available): void
111111
{
112-
$mutex = $this->createAbstractRedlockMutexMock($count);
112+
$mutex = $this->createRedlockMutexMock($count);
113113
$mutex->expects(self::exactly($count))
114114
->method('evalScript')
115115
->willReturn(true);
@@ -146,7 +146,7 @@ public function testAcquireTooFewKeys(int $count, int $available): void
146146
$this->expectException(TimeoutException::class);
147147
$this->expectExceptionMessage('Timeout of 1.0 seconds exceeded');
148148

149-
$mutex = $this->createAbstractRedlockMutexMock($count);
149+
$mutex = $this->createRedlockMutexMock($count);
150150

151151
$i = 0;
152152
$mutex->expects(self::any())
@@ -184,7 +184,7 @@ public function testTimingOut(int $count, float $timeout, float $delay): void
184184
$this->expectException(TimeoutException::class);
185185
$this->expectExceptionMessage('Timeout of ' . $timeoutStr . ' seconds exceeded');
186186

187-
$mutex = $this->createAbstractRedlockMutexMock($count, $timeout);
187+
$mutex = $this->createRedlockMutexMock($count, $timeout);
188188

189189
$mutex->expects(self::exactly($count))
190190
->method('add')
@@ -219,7 +219,7 @@ public static function provideTimingOutCases(): iterable
219219
#[DataProvider('provideMajorityCases')]
220220
public function testAcquireWithMajority(int $count, int $available): void
221221
{
222-
$mutex = $this->createAbstractRedlockMutexMock($count);
222+
$mutex = $this->createRedlockMutexMock($count);
223223
$mutex->expects(self::exactly($count))
224224
->method('evalScript')
225225
->willReturn(true);
@@ -249,7 +249,7 @@ static function () use (&$i, $available): bool {
249249
#[DataProvider('provideMinorityCases')]
250250
public function testTooFewServersToRelease(int $count, int $available): void
251251
{
252-
$mutex = $this->createAbstractRedlockMutexMock($count);
252+
$mutex = $this->createRedlockMutexMock($count);
253253
$mutex->expects(self::exactly($count))
254254
->method('add')
255255
->willReturn(true);
@@ -285,7 +285,7 @@ static function () use (&$i, $available): bool {
285285
#[DataProvider('provideMinorityCases')]
286286
public function testReleaseTooFewKeys(int $count, int $available): void
287287
{
288-
$mutex = $this->createAbstractRedlockMutexMock($count);
288+
$mutex = $this->createRedlockMutexMock($count);
289289
$mutex->expects(self::exactly($count))
290290
->method('add')
291291
->willReturn(true);

tests/Mutex/AbstractSpinlockMutexTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected function setUp(): void
4141
/**
4242
* @return AbstractSpinlockMutex&MockObject
4343
*/
44-
private function createAbstractSpinlockMutexMock(float $timeout = 3): AbstractSpinlockMutex
44+
private function createSpinlockMutexMock(float $timeout = 3): AbstractSpinlockMutex
4545
{
4646
return $this->getMockBuilder(AbstractSpinlockMutex::class)
4747
->setConstructorArgs(['test', $timeout])
@@ -56,7 +56,7 @@ public function testFailAcquireLock(): void
5656
{
5757
$this->expectException(LockAcquireException::class);
5858

59-
$mutex = $this->createAbstractSpinlockMutexMock();
59+
$mutex = $this->createSpinlockMutexMock();
6060
$mutex->expects(self::any())
6161
->method('acquire')
6262
->willThrowException(new LockAcquireException());
@@ -74,7 +74,7 @@ public function testAcquireTimesOut(): void
7474
$this->expectException(TimeoutException::class);
7575
$this->expectExceptionMessage('Timeout of 3.0 seconds exceeded');
7676

77-
$mutex = $this->createAbstractSpinlockMutexMock();
77+
$mutex = $this->createSpinlockMutexMock();
7878
$mutex->expects(self::atLeastOnce())
7979
->method('acquire')
8080
->willReturn(false);
@@ -89,7 +89,7 @@ public function testAcquireTimesOut(): void
8989
*/
9090
public function testExecuteTooLong(): void
9191
{
92-
$mutex = $this->createAbstractSpinlockMutexMock(0.5);
92+
$mutex = $this->createSpinlockMutexMock(0.5);
9393
$mutex->expects(self::any())
9494
->method('acquire')
9595
->willReturn(true);
@@ -114,7 +114,7 @@ public function testExecuteTooLong(): void
114114
*/
115115
public function testExecuteBarelySucceeds(): void
116116
{
117-
$mutex = $this->createAbstractSpinlockMutexMock(0.5);
117+
$mutex = $this->createSpinlockMutexMock(0.5);
118118
$mutex->expects(self::any())->method('acquire')->willReturn(true);
119119
$mutex->expects(self::once())->method('release')->willReturn(true);
120120

@@ -130,7 +130,7 @@ public function testFailReleasingLock(): void
130130
{
131131
$this->expectException(LockReleaseException::class);
132132

133-
$mutex = $this->createAbstractSpinlockMutexMock();
133+
$mutex = $this->createSpinlockMutexMock();
134134
$mutex->expects(self::any())->method('acquire')->willReturn(true);
135135
$mutex->expects(self::any())->method('release')->willReturn(false);
136136

@@ -142,7 +142,7 @@ public function testFailReleasingLock(): void
142142
*/
143143
public function testExecuteTimeoutLeavesOneSecondForKeyToExpire(): void
144144
{
145-
$mutex = $this->createAbstractSpinlockMutexMock(0.2);
145+
$mutex = $this->createSpinlockMutexMock(0.2);
146146
$mutex->expects(self::once())
147147
->method('acquire')
148148
->with(self::anything(), 1.2)

tests/Mutex/MutexConcurrencyTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public static function provideExecutionIsSerializedWhenLockedCases(): iterable
289289
if (class_exists(\Redis::class)) {
290290
yield 'RedisMutex /w PHPRedis' => [
291291
static function ($timeout) use ($uris): Mutex {
292-
$apis = array_map(
292+
$clients = array_map(
293293
static function (string $uri): \Redis {
294294
$redis = new \Redis();
295295

@@ -308,7 +308,7 @@ static function (string $uri): \Redis {
308308
$uris
309309
);
310310

311-
return new RedisMutex($apis, 'test', $timeout);
311+
return new RedisMutex($clients, 'test', $timeout);
312312
},
313313
];
314314
}

tests/Mutex/MutexTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ protected function unlock(): void {}
140140
if (class_exists(\Redis::class)) {
141141
yield 'RedisMutex /w PHPRedis' => [
142142
static function () use ($uris): Mutex {
143-
$apis = array_map(
143+
$clients = array_map(
144144
static function ($uri) {
145145
$redis = new \Redis();
146146

@@ -159,7 +159,7 @@ static function ($uri) {
159159
$uris
160160
);
161161

162-
return new RedisMutex($apis, 'test', self::TIMEOUT);
162+
return new RedisMutex($clients, 'test', self::TIMEOUT);
163163
},
164164
];
165165
}

tests/Mutex/RedisMutexTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
use PHPUnit\Framework\TestCase;
1515

1616
if (\PHP_MAJOR_VERSION >= 8) {
17-
trait RedisTestTrait
17+
trait RedisCompatibilityTrait
1818
{
1919
/**
2020
* @param list<mixed> $args
@@ -35,7 +35,7 @@ public function set($key, $value, $options = null): /* \Redis|string| */ bool
3535
}
3636
}
3737
} else {
38-
trait RedisTestTrait
38+
trait RedisCompatibilityTrait
3939
{
4040
/**
4141
* @return mixed
@@ -92,7 +92,7 @@ protected function setUp(): void
9292

9393
// original Redis::set and Redis::eval calls will reopen the connection
9494
$connection = new class extends \Redis {
95-
use RedisTestTrait;
95+
use RedisCompatibilityTrait;
9696

9797
/** @var bool */
9898
private $is_closed = false;

0 commit comments

Comments
 (0)