Skip to content

Commit 5fb935d

Browse files
committed
Moved the test to the factory
1 parent 7516cb8 commit 5fb935d

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

src/RedisSimpleLockFactory.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ class RedisSimpleLockFactory implements TtlFactory
1212
private $client;
1313
private $defaultTtl;
1414
private $logger;
15+
private $ignoredSapis;
1516

16-
public function __construct(Client $client, $defaultTtl = 10000, LoggerInterface $logger = null)
17+
public function __construct(Client $client, $defaultTtl = 10000, LoggerInterface $logger = null, array $ignoredSapis = [])
1718
{
18-
$this->client = $client;
19-
$this->defaultTtl = $defaultTtl;
20-
$this->logger = $logger ?: new NullLogger;
19+
$this->client = $client;
20+
$this->defaultTtl = $defaultTtl;
21+
$this->logger = $logger ?: new NullLogger;
22+
$this->ignoredSapis = $ignoredSapis;
2123
}
2224

2325
/**
@@ -30,6 +32,6 @@ public function __construct(Client $client, $defaultTtl = 10000, LoggerInterface
3032
*/
3133
public function create($identifier, $ttl = null)
3234
{
33-
return new RedisSimpleLock($identifier, $this->client, $ttl ?: $this->defaultTtl, $this->logger);
35+
return new RedisSimpleLock($identifier, $this->client, $ttl ?: $this->defaultTtl, $this->logger, $this->ignoredSapis);
3436
}
3537
}

tests/RedisSimpleLockFactoryTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,23 @@ protected function setUp()
1313
$this->redisClient->flushdb();
1414
}
1515

16+
public function testCreateIgnoredSapisLock()
17+
{
18+
$factory = new RedisSimpleLockFactory($this->redisClient, 50, null, [php_sapi_name()]);
19+
$lock = $factory->create('lock identifier');
20+
$this->assertInstanceOf(RedisSimpleLock::class, $lock);
21+
22+
$handler = pcntl_signal_get_handler(SIGINT);
23+
$this->assertEmpty($handler);
24+
}
25+
1626
public function testCreateLock()
1727
{
1828
$factory = new RedisSimpleLockFactory($this->redisClient, 50);
1929
$lock = $factory->create('lock identifier');
2030
$this->assertInstanceOf(RedisSimpleLock::class, $lock);
31+
32+
$handler = pcntl_signal_get_handler(SIGINT);
33+
$this->assertInstanceOf(Closure::class, $handler);
2134
}
2235
}

tests/RedisSimpleLockTest.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,7 @@ protected function setUp()
1111
$this->redisClient = new \Predis\Client(getenv("REDIS_URI"));
1212
$this->redisClient->flushdb();
1313
}
14-
15-
public function testSAPIIgnore()
16-
{
17-
$lock1 = new RedisSimpleLock("lock identifier", $this->redisClient, 50, null, [php_sapi_name()]);
18-
$handler = pcntl_signal_get_handler(SIGINT);
19-
$this->assertEmpty($handler);
20-
21-
$lock2 = new RedisSimpleLock("lock identifier", $this->redisClient, 50, null);
22-
$handler = pcntl_signal_get_handler(SIGINT);
23-
$this->assertInstanceOf(Closure::class, $handler);
24-
}
25-
14+
2615
public function testLock()
2716
{
2817
$lock1 = new RedisSimpleLock("lock identifier", $this->redisClient, 50);

0 commit comments

Comments
 (0)