Skip to content

Commit 4d6e293

Browse files
Clear redis locks after each test
1 parent b9a1ec4 commit 4d6e293

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

tests/mutex/PHPRedisMutexTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,17 @@ protected function setUp()
4747
} else {
4848
$this->redis->connect($uri["host"]);
4949
}
50-
50+
5151
$this->mutex = new PHPRedisMutex([$this->redis], "test");
5252
}
5353

54+
protected function tearDown()
55+
{
56+
$this->redis->flushAll();
57+
58+
parent::tearDown();
59+
}
60+
5461
/**
5562
* Tests add() fails.
5663
*

tests/mutex/PredisMutexTest.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace malkusch\lock\mutex;
44

55
use Predis\Client;
6+
use Predis\ClientInterface;
67

78
/**
89
* Tests for PredisMutex.
@@ -18,14 +19,27 @@
1819
*/
1920
class PredisMutexTest extends \PHPUnit_Framework_TestCase
2021
{
21-
22+
/**
23+
* @var ClientInterface
24+
*/
25+
protected $client;
26+
2227
protected function setUp()
2328
{
2429
parent::setUp();
2530

2631
if (!getenv("REDIS_URIS")) {
2732
$this->markTestSkipped();
2833
}
34+
35+
$this->client = new Client("redis://example.net");
36+
}
37+
38+
protected function tearDown()
39+
{
40+
$this->client->flushall();
41+
42+
parent::tearDown();
2943
}
3044

3145
/**
@@ -37,8 +51,7 @@ protected function setUp()
3751
*/
3852
public function testAddFails()
3953
{
40-
$client = new Client("redis://example.net");
41-
$mutex = new PredisMutex([$client], "test");
54+
$mutex = new PredisMutex([$this->client], "test");
4255

4356
$mutex->synchronized(function () {
4457
$this->fail("Code execution is not expected");

tests/mutex/RedisMutexTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected function setUp()
4242
* @param int $count The amount of redis apis.
4343
* @param int $timeout The timeout.
4444
*
45-
* @return \PHPUnit_Framework_MockObject_MockObject The mock.
45+
* @return \PHPUnit_Framework_MockObject_MockObject|RedisMutex
4646
*/
4747
private function buildRedisMutex($count, $timeout = 1)
4848
{

0 commit comments

Comments
 (0)