Skip to content

Commit bab2954

Browse files
committed
Updated test reflecting fix
1 parent 194679b commit bab2954

File tree

3 files changed

+133
-10
lines changed

3 files changed

+133
-10
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"phpunit/phpunit": "^5.2.3",
1717
"squizlabs/php_codesniffer": "^2.6",
1818
"vectorface/dunit": "~2.0",
19-
"phake/phake": "^2.3"
19+
"phake/phake": "^2.3",
20+
"clue/block-react": "^1.1"
2021
},
2122
"autoload": {
2223
"psr-4": {

composer.lock

Lines changed: 103 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/RedisTest.php

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44

55
use Phake;
66
use Clue\React\Redis\Client;
7+
use React\EventLoop\Factory;
8+
use React\Promise\FulfilledPromise;
79
use React\Promise\PromiseInterface;
10+
use React\Promise\RejectedPromise;
811
use WyriHaximus\React\Cache\Redis;
12+
use function Clue\React\Block\await;
913

1014
class RedisTest extends \PHPUnit_Framework_TestCase
1115
{
@@ -24,12 +28,30 @@ public function testGet()
2428
{
2529
$prefix = 'root:';
2630
$key = 'key';
27-
$promise = Phake::mock(PromiseInterface::class);
28-
Phake::when($this->client)->get($prefix . $key)->thenReturn($promise);
29-
$result = (new Redis($this->client, $prefix))->get($key);
30-
$this->assertInstanceOf(PromiseInterface::class, $result);
31-
$this->assertSame($promise, $result);
32-
Phake::verify($this->client)->get($prefix . $key);
31+
$value = 'value';
32+
Phake::when($this->client)->exists($prefix . $key)->thenReturn(new FulfilledPromise(1));
33+
Phake::when($this->client)->get($prefix . $key)->thenReturn(new FulfilledPromise($value));
34+
$promise = (new Redis($this->client, $prefix))->get($key);
35+
$this->assertInstanceOf(PromiseInterface::class, $promise);
36+
$result = await($promise, Factory::create());
37+
$this->assertSame($value, $result);
38+
Phake::inOrder(
39+
Phake::verify($this->client)->exists($prefix . $key),
40+
Phake::verify($this->client)->get($prefix . $key)
41+
);
42+
}
43+
44+
public function testGetNonExistant()
45+
{
46+
$prefix = 'root:';
47+
$key = 'key';
48+
Phake::when($this->client)->exists($prefix . $key)->thenReturn(new FulfilledPromise(0));
49+
Phake::when($this->client)->get($prefix . $key)->thenReturn(new RejectedPromise());
50+
$promise = (new Redis($this->client, $prefix))->get($key);
51+
$this->assertInstanceOf(PromiseInterface::class, $promise);
52+
$this->assertInstanceOf(RejectedPromise::class, $promise);
53+
Phake::verify($this->client)->exists($prefix . $key);
54+
Phake::verify($this->client, Phake::never())->get($prefix . $key);
3355
}
3456

3557
public function testSet()

0 commit comments

Comments
 (0)