Skip to content

Commit 2177985

Browse files
authored
Merge pull request #104 from syffer/watch-unwatch-supports
Adds watch() and unwatch() support
2 parents 69d63b4 + acf0023 commit 2177985

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Redis command | Description
8484

8585
It mocks **MULTI**, **DISCARD** and **EXEC** commands but without any transaction behaviors, they just make the interface fluent and return each command results.
8686
**PIPELINE** and **EXECUTE** pseudo commands (client pipelining) are also mocked.
87-
**EVAL** and **EVALSHA** are just stubs—they won't execute anything
87+
**EVAL**, **EVALSHA**, **WATCH** and **UNWATCH** are just stubs—they won't execute anything
8888

8989
## Usage
9090

src/M6Web/Component/RedisMock/RedisMock.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace M6Web\Component\RedisMock;
44

5+
use Predis\Response\Status;
6+
57
/**
68
* Redis mock class
79
*
@@ -1205,6 +1207,16 @@ public function exec()
12051207
return $pipedInfo;
12061208
}
12071209

1210+
public function watch($key)
1211+
{
1212+
return new Status('OK');
1213+
}
1214+
1215+
public function unwatch()
1216+
{
1217+
return new Status('OK');
1218+
}
1219+
12081220
// Client pipeline
12091221

12101222
public function pipeline()

tests/units/RedisMock.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use atoum;
66
use M6Web\Component\RedisMock\RedisMock as Redis;
7+
use Predis\Response\Status;
78

89
/**
910
* Redis mock test
@@ -1828,6 +1829,28 @@ public function testTransactions()
18281829
->isEmpty();
18291830
}
18301831

1832+
public function testWatch()
1833+
{
1834+
$redisMock = new Redis();
1835+
$redisMock->set('test', 'something');
1836+
1837+
$this->assert
1838+
->object($redisMock->watch('test'))
1839+
->isInstanceOf(Status::class)
1840+
->object($redisMock->watch('unexisting-key'))
1841+
->isInstanceOf(Status::class);
1842+
}
1843+
1844+
public function testUnwatch()
1845+
{
1846+
$redisMock = new Redis();
1847+
$redisMock->set('test', 'something');
1848+
1849+
$this->assert
1850+
->object($redisMock->unwatch())
1851+
->isInstanceOf(Status::class);
1852+
}
1853+
18311854
public function testDbsize()
18321855
{
18331856
$redisMock = new Redis();

0 commit comments

Comments
 (0)