Skip to content

Commit d9b8a5f

Browse files
Update Redis tests
1 parent 15e54e1 commit d9b8a5f

File tree

3 files changed

+12
-26
lines changed

3 files changed

+12
-26
lines changed

tests/mutex/PHPRedisMutexTest.php

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

55
use Redis;
6+
use RedisException;
67

78
/**
89
* Tests for PHPRedisMutex.
@@ -16,10 +17,10 @@
1617
* @license WTFPL
1718
* @see PHPRedisMutex
1819
* @requires redis
20+
* @group redis
1921
*/
2022
class PHPRedisMutexTest extends \PHPUnit_Framework_TestCase
2123
{
22-
2324
/**
2425
* @var Redis The Redis API.
2526
*/
@@ -34,28 +35,19 @@ protected function setUp()
3435
{
3536
parent::setUp();
3637

37-
if (!getenv("REDIS_URIS")) {
38-
$this->markTestSkipped();
39-
return;
40-
}
4138
$this->redis = new Redis();
4239

43-
$uris = explode(",", getenv("REDIS_URIS"));
40+
$uris = explode(",", getenv("REDIS_URIS") ?: "redis://localhost");
4441
$uri = parse_url($uris[0]);
4542
if (!empty($uri["port"])) {
4643
$this->redis->connect($uri["host"], $uri["port"]);
4744
} else {
4845
$this->redis->connect($uri["host"]);
4946
}
5047

51-
$this->mutex = new PHPRedisMutex([$this->redis], "test");
52-
}
48+
$this->redis->flushAll(); // Clear any existing locks.
5349

54-
protected function tearDown()
55-
{
56-
$this->redis->flushAll();
57-
58-
parent::tearDown();
50+
$this->mutex = new PHPRedisMutex([$this->redis], "test");
5951
}
6052

6153
/**

tests/mutex/PredisMutexTest.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* @link bitcoin:1335STSwu9hST4vcMRppEPgENMHD2r1REK Donations
1717
* @license WTFPL
1818
* @see PredisMutex
19+
* @group redis
1920
*/
2021
class PredisMutexTest extends \PHPUnit_Framework_TestCase
2122
{
@@ -28,18 +29,8 @@ protected function setUp()
2829
{
2930
parent::setUp();
3031

31-
if (!getenv("REDIS_URIS")) {
32-
$this->markTestSkipped();
33-
}
34-
35-
$this->client = new Client("redis://example.net");
36-
}
37-
38-
protected function tearDown()
39-
{
40-
$this->client->flushall();
41-
42-
parent::tearDown();
32+
$this->client = new Client(getenv("REDIS_URIS") ?: "redis://localhost");
33+
$this->client->flushall(); // Clear any existing locks
4334
}
4435

4536
/**
@@ -51,7 +42,9 @@ protected function tearDown()
5142
*/
5243
public function testAddFails()
5344
{
54-
$mutex = new PredisMutex([$this->client], "test");
45+
$client = new Client("redis://127.0.0.1:12345");
46+
47+
$mutex = new PredisMutex([$client], "test");
5548

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

tests/mutex/RedisMutexTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* @license WTFPL
1818
*
1919
* @see RedisMutex
20+
* @group redis
2021
*/
2122
class RedisMutexTest extends \PHPUnit_Framework_TestCase
2223
{

0 commit comments

Comments
 (0)