Skip to content

Commit 3b61fac

Browse files
committed
move redis limit test
1 parent 0ff60e0 commit 3b61fac

File tree

2 files changed

+35
-19
lines changed

2 files changed

+35
-19
lines changed

tests/Mutex/RedisMutexTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Malkusch\Lock\Mutex\RedisMutex;
1212
use PHPUnit\Framework\Attributes\DataProvider;
1313
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
14+
use PHPUnit\Framework\Constraint\IsType;
1415
use PHPUnit\Framework\TestCase;
1516

1617
if (\PHP_MAJOR_VERSION >= 8) {
@@ -57,6 +58,19 @@ public function set($key, $value, $options = null)
5758
}
5859
}
5960

61+
interface PredisClientInterfaceWithSetAndEvalMethods extends PredisClientInterface
62+
{
63+
/**
64+
* @return mixed
65+
*/
66+
public function eval();
67+
68+
/**
69+
* @return mixed
70+
*/
71+
public function set();
72+
}
73+
6074
/**
6175
* These tests require the environment variable:
6276
*
@@ -207,6 +221,25 @@ public function testEvalScriptFails(): void
207221
});
208222
}
209223

224+
public function testAcquireExpireTimeoutLimit(): void
225+
{
226+
$client = $this->createMock(PredisClientInterfaceWithSetAndEvalMethods::class);
227+
228+
$this->mutex = new RedisMutex($client, 'test');
229+
230+
$client->expects(self::once())
231+
->method('set')
232+
->with('php-malkusch-lock:test', new IsType(IsType::TYPE_STRING), 'PX', 31_557_600_000_000, 'NX')
233+
->willReturnSelf();
234+
235+
$client->expects(self::once())
236+
->method('eval')
237+
->with(self::anything(), 1, 'php-malkusch-lock:test', new IsType(IsType::TYPE_STRING))
238+
->willReturn(true);
239+
240+
$this->mutex->synchronized(static function () {});
241+
}
242+
210243
/**
211244
* @param \Redis::SERIALIZER_* $serializer
212245
* @param \Redis::COMPRESSION_* $compressor

tests/Mutex/RedisMutexWithPredisTest.php

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Predis\ClientInterface as PredisClientInterface;
1414
use Predis\PredisException;
1515

16-
interface PredisClientInterfaceWithSetAndEvalMethods extends PredisClientInterface
16+
interface PredisClientInterfaceWithSetAndEvalMethods2 extends PredisClientInterface
1717
{
1818
/**
1919
* @return mixed
@@ -39,7 +39,7 @@ protected function setUp(): void
3939
{
4040
parent::setUp();
4141

42-
$this->client = $this->createMock(PredisClientInterfaceWithSetAndEvalMethods::class);
42+
$this->client = $this->createMock(PredisClientInterfaceWithSetAndEvalMethods2::class);
4343

4444
$this->mutex = new RedisMutex($this->client, 'test', 2.5, 3.5);
4545
}
@@ -98,23 +98,6 @@ public function testWorksNormally(): void
9898
self::assertTrue($executed);
9999
}
100100

101-
public function testAcquireExpireTimeoutLimit(): void
102-
{
103-
$this->mutex = new RedisMutex($this->client, 'test');
104-
105-
$this->client->expects(self::once())
106-
->method('set')
107-
->with('php-malkusch-lock:test', new IsType(IsType::TYPE_STRING), 'PX', 31_557_600_000_000, 'NX')
108-
->willReturnSelf();
109-
110-
$this->client->expects(self::once())
111-
->method('eval')
112-
->with(self::anything(), 1, 'php-malkusch-lock:test', new IsType(IsType::TYPE_STRING))
113-
->willReturn(true);
114-
115-
$this->mutex->synchronized(static function () {});
116-
}
117-
118101
/**
119102
* Tests evalScript() fails.
120103
*/

0 commit comments

Comments
 (0)