-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathRedisSimpleLockFactoryTest.php
41 lines (34 loc) · 1.25 KB
/
RedisSimpleLockFactoryTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
use PHPUnit\Framework\TestCase;
use TH\RedisLock\RedisSimpleLock;
use TH\RedisLock\RedisSimpleLockFactory;
class RedisSimpleLockFactoryTest extends TestCase
{
private $redisClient;
public function setUp(): void
{
$uri = getenv("REDIS_URI");
$this->redisClient = is_string($uri) ? new \Predis\Client($uri) : new \Predis\Client();
$this->redisClient->flushdb();
}
public function testCreateIgnoredSAPIsLock()
{
$factory = new RedisSimpleLockFactory($this->redisClient, 50, null, [php_sapi_name()]);
$lock = $factory->create('lock identifier');
$this->assertInstanceOf(RedisSimpleLock::class, $lock);
if (function_exists('pcntl_signal_get_handler')) {
$handler = pcntl_signal_get_handler(SIGINT);
$this->assertEmpty($handler);
}
}
public function testCreateLock()
{
$factory = new RedisSimpleLockFactory($this->redisClient, 50);
$lock = $factory->create('lock identifier');
$this->assertInstanceOf(RedisSimpleLock::class, $lock);
if (function_exists('pcntl_signal_get_handler')) {
$handler = pcntl_signal_get_handler(SIGINT);
$this->assertInstanceOf(Closure::class, $handler);
}
}
}