From a753f969b77516aaceb185d5142ba61231379884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sun, 29 Aug 2021 15:19:06 +0200 Subject: [PATCH] Consistently use `$redis` and fully qualified class names for `Client` --- README.md | 76 +++++++++--------- examples/cli.php | 17 ++-- examples/incr.php | 12 ++- examples/publish.php | 10 +-- examples/subscribe.php | 19 +++-- src/Factory.php | 24 +++--- src/LazyClient.php | 34 ++++---- tests/FactoryLazyClientTest.php | 12 +-- tests/FunctionalTest.php | 90 ++++++++++----------- tests/LazyClientTest.php | 138 ++++++++++++++++---------------- tests/StreamingClientTest.php | 98 +++++++++++------------ 11 files changed, 261 insertions(+), 269 deletions(-) diff --git a/README.md b/README.md index cc374da..3b4a5e9 100644 --- a/README.md +++ b/README.md @@ -63,22 +63,22 @@ local Redis server and send some requests: ```php $factory = new Clue\React\Redis\Factory(); -$client = $factory->createLazyClient('localhost:6379'); +$redis = $factory->createLazyClient('localhost:6379'); -$client->set('greeting', 'Hello world'); -$client->append('greeting', '!'); +$redis->set('greeting', 'Hello world'); +$redis->append('greeting', '!'); -$client->get('greeting')->then(function ($greeting) { +$redis->get('greeting')->then(function ($greeting) { // Hello world! echo $greeting . PHP_EOL; }); -$client->incr('invocation')->then(function ($n) { +$redis->incr('invocation')->then(function ($n) { echo 'This is invocation #' . $n . PHP_EOL; }); // end connection once all pending requests have been resolved -$client->end(); +$redis->end(); ``` See also the [examples](examples). @@ -91,20 +91,20 @@ Most importantly, this project provides a [`Client`](#client) instance that can be used to invoke all [Redis commands](https://redis.io/commands) (such as `GET`, `SET`, etc.). ```php -$client->get($key); -$client->set($key, $value); -$client->exists($key); -$client->expire($key, $seconds); -$client->mget($key1, $key2, $key3); +$redis->get($key); +$redis->set($key, $value); +$redis->exists($key); +$redis->expire($key, $seconds); +$redis->mget($key1, $key2, $key3); -$client->multi(); -$client->exec(); +$redis->multi(); +$redis->exec(); -$client->publish($channel, $payload); -$client->subscribe($channel); +$redis->publish($channel, $payload); +$redis->subscribe($channel); -$client->ping(); -$client->select($database); +$redis->ping(); +$redis->select($database); // many moreā€¦ ``` @@ -161,7 +161,7 @@ send a message to all clients currently subscribed to a given channel: ```php $channel = 'user'; $message = json_encode(array('id' => 10)); -$client->publish($channel, $message); +$redis->publish($channel, $message); ``` The [`SUBSCRIBE` command](https://redis.io/commands/subscribe) can be used to @@ -169,9 +169,9 @@ subscribe to a channel and then receive incoming PubSub `message` events: ```php $channel = 'user'; -$client->subscribe($channel); +$redis->subscribe($channel); -$client->on('message', function ($channel, $payload) { +$redis->on('message', function ($channel, $payload) { // pubsub message received on given $channel var_dump($channel, json_decode($payload)); }); @@ -181,9 +181,9 @@ Likewise, you can use the same client connection to subscribe to multiple channels by simply executing this command multiple times: ```php -$client->subscribe('user.register'); -$client->subscribe('user.join'); -$client->subscribe('user.leave'); +$redis->subscribe('user.register'); +$redis->subscribe('user.join'); +$redis->subscribe('user.leave'); ``` Similarly, the [`PSUBSCRIBE` command](https://redis.io/commands/psubscribe) can @@ -193,9 +193,9 @@ all incoming PubSub messages with the `pmessage` event: ```php $pattern = 'user.*'; -$client->psubscribe($pattern); +$redis->psubscribe($pattern); -$client->on('pmessage', function ($pattern, $channel, $payload) { +$redis->on('pmessage', function ($pattern, $channel, $payload) { // pubsub message received matching given $pattern var_dump($channel, json_decode($payload)); }); @@ -213,10 +213,10 @@ receiving any further events for the given channel and pattern subscriptions respectively: ```php -$client->subscribe('user'); +$redis->subscribe('user'); -Loop::addTimer(60.0, function () use ($client) { - $client->unsubscribe('user'); +Loop::addTimer(60.0, function () use ($redis) { + $redis->unsubscribe('user'); }); ``` @@ -235,16 +235,16 @@ Additionally, can listen for the following PubSub events to get notifications about subscribed/unsubscribed channels and patterns: ```php -$client->on('subscribe', function ($channel, $total) { +$redis->on('subscribe', function ($channel, $total) { // subscribed to given $channel }); -$client->on('psubscribe', function ($pattern, $total) { +$redis->on('psubscribe', function ($pattern, $total) { // subscribed to matching given $pattern }); -$client->on('unsubscribe', function ($channel, $total) { +$redis->on('unsubscribe', function ($channel, $total) { // unsubscribed from given $channel }); -$client->on('punsubscribe', function ($pattern, $total) { +$redis->on('punsubscribe', function ($pattern, $total) { // unsubscribed from matching given $pattern }); ``` @@ -299,7 +299,7 @@ and optionally authenticating (AUTH) and selecting the right database (SELECT). ```php $factory->createClient('localhost:6379')->then( - function (Client $client) { + function (Client $redis) { // client connected (and authenticated) }, function (Exception $e) { @@ -395,10 +395,10 @@ It helps with establishing a plain TCP/IP or secure TLS connection to Redis and optionally authenticating (AUTH) and selecting the right database (SELECT). ```php -$client = $factory->createLazyClient('localhost:6379'); +$redis = $factory->createLazyClient('localhost:6379'); -$client->incr('hello'); -$client->end(); +$redis->incr('hello'); +$redis->end(); ``` This method immediately returns a "virtual" connection implementing the @@ -576,7 +576,7 @@ when the client connection is lost or is invalid. The event receives a single `Exception` argument for the error instance. ```php -$client->on('error', function (Exception $e) { +$redis->on('error', function (Exception $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; }); ``` @@ -590,7 +590,7 @@ errors caused by invalid commands. The `close` event will be emitted once the client connection closes (terminates). ```php -$client->on('close', function () { +$redis->on('close', function () { echo 'Connection closed' . PHP_EOL; }); ``` diff --git a/examples/cli.php b/examples/cli.php index 8b7fa03..c1c629f 100644 --- a/examples/cli.php +++ b/examples/cli.php @@ -3,26 +3,23 @@ // $ php examples/cli.php // $ REDIS_URI=localhost:6379 php examples/cli.php -use Clue\React\Redis\Client; -use Clue\React\Redis\Factory; use React\EventLoop\Loop; -use React\Promise\PromiseInterface; require __DIR__ . '/../vendor/autoload.php'; -$factory = new Factory(); +$factory = new Clue\React\Redis\Factory(); echo '# connecting to redis...' . PHP_EOL; -$factory->createClient(getenv('REDIS_URI') ?: 'localhost:6379')->then(function (Client $client) { +$factory->createClient(getenv('REDIS_URI') ?: 'localhost:6379')->then(function (Clue\React\Redis\Client $redis) { echo '# connected! Entering interactive mode, hit CTRL-D to quit' . PHP_EOL; - Loop::addReadStream(STDIN, function () use ($client) { + Loop::addReadStream(STDIN, function () use ($redis) { $line = fgets(STDIN); if ($line === false || $line === '') { echo '# CTRL-D -> Ending connection...' . PHP_EOL; Loop::removeReadStream(STDIN); - return $client->end(); + return $redis->end(); } $line = rtrim($line); @@ -32,10 +29,10 @@ $params = explode(' ', $line); $method = array_shift($params); - $promise = call_user_func_array(array($client, $method), $params); + $promise = call_user_func_array(array($redis, $method), $params); // special method such as end() / close() called - if (!$promise instanceof PromiseInterface) { + if (!$promise instanceof React\Promise\PromiseInterface) { return; } @@ -46,7 +43,7 @@ }); }); - $client->on('close', function() { + $redis->on('close', function() { echo '## DISCONNECTED' . PHP_EOL; Loop::removeReadStream(STDIN); diff --git a/examples/incr.php b/examples/incr.php index 36a24d2..71887e4 100644 --- a/examples/incr.php +++ b/examples/incr.php @@ -3,20 +3,18 @@ // $ php examples/incr.php // $ REDIS_URI=localhost:6379 php examples/incr.php -use Clue\React\Redis\Factory; - require __DIR__ . '/../vendor/autoload.php'; -$factory = new Factory(); -$client = $factory->createLazyClient(getenv('REDIS_URI') ?: 'localhost:6379'); +$factory = new Clue\React\Redis\Factory(); +$redis = $factory->createLazyClient(getenv('REDIS_URI') ?: 'localhost:6379'); -$client->incr('test'); +$redis->incr('test'); -$client->get('test')->then(function ($result) { +$redis->get('test')->then(function ($result) { var_dump($result); }, function (Exception $e) { echo 'Error: ' . $e->getMessage() . PHP_EOL; exit(1); }); -//$client->end(); +//$redis->end(); diff --git a/examples/publish.php b/examples/publish.php index 5353301..6eb2f9d 100644 --- a/examples/publish.php +++ b/examples/publish.php @@ -3,21 +3,19 @@ // $ php examples/publish.php // $ REDIS_URI=localhost:6379 php examples/publish.php channel message -use Clue\React\Redis\Factory; - require __DIR__ . '/../vendor/autoload.php'; -$factory = new Factory(); -$client = $factory->createLazyClient(getenv('REDIS_URI') ?: 'localhost:6379'); +$factory = new Clue\React\Redis\Factory(); +$redis = $factory->createLazyClient(getenv('REDIS_URI') ?: 'localhost:6379'); $channel = isset($argv[1]) ? $argv[1] : 'channel'; $message = isset($argv[2]) ? $argv[2] : 'message'; -$client->publish($channel, $message)->then(function ($received) { +$redis->publish($channel, $message)->then(function ($received) { echo 'Successfully published. Received by ' . $received . PHP_EOL; }, function (Exception $e) { echo 'Unable to publish: ' . $e->getMessage() . PHP_EOL; exit(1); }); -$client->end(); +$redis->end(); diff --git a/examples/subscribe.php b/examples/subscribe.php index 4e8c6fe..9f93f2e 100644 --- a/examples/subscribe.php +++ b/examples/subscribe.php @@ -3,33 +3,32 @@ // $ php examples/subscribe.php // $ REDIS_URI=localhost:6379 php examples/subscribe.php channel -use Clue\React\Redis\Factory; use React\EventLoop\Loop; require __DIR__ . '/../vendor/autoload.php'; -$factory = new Factory(); -$client = $factory->createLazyClient(getenv('REDIS_URI') ?: 'localhost:6379'); +$factory = new Clue\React\Redis\Factory(); +$redis = $factory->createLazyClient(getenv('REDIS_URI') ?: 'localhost:6379'); $channel = isset($argv[1]) ? $argv[1] : 'channel'; -$client->subscribe($channel)->then(function () { +$redis->subscribe($channel)->then(function () { echo 'Now subscribed to channel ' . PHP_EOL; -}, function (Exception $e) use ($client) { - $client->close(); +}, function (Exception $e) use ($redis) { + $redis->close(); echo 'Unable to subscribe: ' . $e->getMessage() . PHP_EOL; }); -$client->on('message', function ($channel, $message) { +$redis->on('message', function ($channel, $message) { echo 'Message on ' . $channel . ': ' . $message . PHP_EOL; }); // automatically re-subscribe to channel on connection issues -$client->on('unsubscribe', function ($channel) use ($client) { +$redis->on('unsubscribe', function ($channel) use ($redis) { echo 'Unsubscribed from ' . $channel . PHP_EOL; - Loop::addPeriodicTimer(2.0, function ($timer) use ($client, $channel){ - $client->subscribe($channel)->then(function () use ($timer) { + Loop::addPeriodicTimer(2.0, function ($timer) use ($redis, $channel){ + $redis->subscribe($channel)->then(function () use ($timer) { echo 'Now subscribed again' . PHP_EOL; Loop::cancelTimer($timer); }, function (Exception $e) { diff --git a/src/Factory.php b/src/Factory.php index 171523c..4e94905 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -103,13 +103,13 @@ public function createClient($uri) $pass = isset($args['password']) ? $args['password'] : (isset($parts['pass']) ? rawurldecode($parts['pass']) : null); if (isset($args['password']) || isset($parts['pass'])) { $pass = isset($args['password']) ? $args['password'] : rawurldecode($parts['pass']); - $promise = $promise->then(function (StreamingClient $client) use ($pass, $uri) { - return $client->auth($pass)->then( - function () use ($client) { - return $client; + $promise = $promise->then(function (StreamingClient $redis) use ($pass, $uri) { + return $redis->auth($pass)->then( + function () use ($redis) { + return $redis; }, - function (\Exception $e) use ($client, $uri) { - $client->close(); + function (\Exception $e) use ($redis, $uri) { + $redis->close(); $const = ''; $errno = $e->getCode(); @@ -131,13 +131,13 @@ function (\Exception $e) use ($client, $uri) { // use `?db=1` query or `/1` path (skip first slash) if (isset($args['db']) || (isset($parts['path']) && $parts['path'] !== '/')) { $db = isset($args['db']) ? $args['db'] : substr($parts['path'], 1); - $promise = $promise->then(function (StreamingClient $client) use ($db, $uri) { - return $client->select($db)->then( - function () use ($client) { - return $client; + $promise = $promise->then(function (StreamingClient $redis) use ($db, $uri) { + return $redis->select($db)->then( + function () use ($redis) { + return $redis; }, - function (\Exception $e) use ($client, $uri) { - $client->close(); + function (\Exception $e) use ($redis, $uri) { + $redis->close(); $const = ''; $errno = $e->getCode(); diff --git a/src/LazyClient.php b/src/LazyClient.php index c542f6b..42aceca 100644 --- a/src/LazyClient.php +++ b/src/LazyClient.php @@ -53,9 +53,9 @@ private function client() $subscribed =& $this->subscribed; $psubscribed =& $this->psubscribed; $loop = $this->loop; - return $pending = $this->factory->createClient($this->target)->then(function (Client $client) use ($self, &$pending, &$idleTimer, &$subscribed, &$psubscribed, $loop) { + return $pending = $this->factory->createClient($this->target)->then(function (Client $redis) use ($self, &$pending, &$idleTimer, &$subscribed, &$psubscribed, $loop) { // connection completed => remember only until closed - $client->on('close', function () use (&$pending, $self, &$subscribed, &$psubscribed, &$idleTimer, $loop) { + $redis->on('close', function () use (&$pending, $self, &$subscribed, &$psubscribed, &$idleTimer, $loop) { $pending = null; // foward unsubscribe/punsubscribe events when underlying connection closes @@ -77,21 +77,21 @@ private function client() }); // keep track of all channels and patterns this connection is subscribed to - $client->on('subscribe', function ($channel) use (&$subscribed) { + $redis->on('subscribe', function ($channel) use (&$subscribed) { $subscribed[$channel] = true; }); - $client->on('psubscribe', function ($pattern) use (&$psubscribed) { + $redis->on('psubscribe', function ($pattern) use (&$psubscribed) { $psubscribed[$pattern] = true; }); - $client->on('unsubscribe', function ($channel) use (&$subscribed) { + $redis->on('unsubscribe', function ($channel) use (&$subscribed) { unset($subscribed[$channel]); }); - $client->on('punsubscribe', function ($pattern) use (&$psubscribed) { + $redis->on('punsubscribe', function ($pattern) use (&$psubscribed) { unset($psubscribed[$pattern]); }); Util::forwardEvents( - $client, + $redis, $self, array( 'message', @@ -103,7 +103,7 @@ private function client() ) ); - return $client; + return $redis; }, function (\Exception $e) use (&$pending) { // connection failed => discard connection attempt $pending = null; @@ -122,9 +122,9 @@ public function __call($name, $args) } $that = $this; - return $this->client()->then(function (Client $client) use ($name, $args, $that) { + return $this->client()->then(function (Client $redis) use ($name, $args, $that) { $that->awake(); - return \call_user_func_array(array($client, $name), $args)->then( + return \call_user_func_array(array($redis, $name), $args)->then( function ($result) use ($that) { $that->idle(); return $result; @@ -148,11 +148,11 @@ public function end() } $that = $this; - return $this->client()->then(function (Client $client) use ($that) { - $client->on('close', function () use ($that) { + return $this->client()->then(function (Client $redis) use ($that) { + $redis->on('close', function () use ($that) { $that->close(); }); - $client->end(); + $redis->end(); }); } @@ -166,8 +166,8 @@ public function close() // either close active connection or cancel pending connection attempt if ($this->promise !== null) { - $this->promise->then(function (Client $client) { - $client->close(); + $this->promise->then(function (Client $redis) { + $redis->close(); }); if ($this->promise !== null) { $this->promise->cancel(); @@ -208,8 +208,8 @@ public function idle() $idleTimer =& $this->idleTimer; $promise =& $this->promise; $idleTimer = $this->loop->addTimer($this->idlePeriod, function () use (&$idleTimer, &$promise) { - $promise->then(function (Client $client) { - $client->close(); + $promise->then(function (Client $redis) { + $redis->close(); }); $promise = null; $idleTimer = null; diff --git a/tests/FactoryLazyClientTest.php b/tests/FactoryLazyClientTest.php index 33a216c..8b5005b 100644 --- a/tests/FactoryLazyClientTest.php +++ b/tests/FactoryLazyClientTest.php @@ -50,9 +50,9 @@ public function testWillResolveIfConnectorResolves() $stream->expects($this->never())->method('write'); $this->connector->expects($this->never())->method('connect')->willReturn(Promise\resolve($stream)); - $client = $this->factory->createLazyClient('localhost'); + $redis = $this->factory->createLazyClient('localhost'); - $this->assertInstanceOf('Clue\React\Redis\Client', $client); + $this->assertInstanceOf('Clue\React\Redis\Client', $redis); } public function testWillWriteSelectCommandIfTargetContainsPath() @@ -148,15 +148,15 @@ public function testWillWriteSelectCommandIfRedisUnixUriContainsDbQueryParameter public function testWillRejectIfConnectorRejects() { $this->connector->expects($this->never())->method('connect')->with('127.0.0.1:2')->willReturn(Promise\reject(new \RuntimeException())); - $client = $this->factory->createLazyClient('redis://127.0.0.1:2'); + $redis = $this->factory->createLazyClient('redis://127.0.0.1:2'); - $this->assertInstanceOf('Clue\React\Redis\Client', $client); + $this->assertInstanceOf('Clue\React\Redis\Client', $redis); } public function testWillRejectIfTargetIsInvalid() { - $client = $this->factory->createLazyClient('http://invalid target'); + $redis = $this->factory->createLazyClient('http://invalid target'); - $this->assertInstanceOf('Clue\React\Redis\Client', $client); + $this->assertInstanceOf('Clue\React\Redis\Client', $redis); } } diff --git a/tests/FunctionalTest.php b/tests/FunctionalTest.php index 7e70b71..45a9fcd 100644 --- a/tests/FunctionalTest.php +++ b/tests/FunctionalTest.php @@ -32,9 +32,9 @@ public function setUpFactory() public function testPing() { - $client = $this->createClient($this->uri); + $redis = $this->createClient($this->uri); - $promise = $client->ping(); + $promise = $redis->ping(); $this->assertInstanceOf('React\Promise\PromiseInterface', $promise); $ret = Block\await($promise, $this->loop); @@ -44,9 +44,9 @@ public function testPing() public function testPingLazy() { - $client = $this->factory->createLazyClient($this->uri); + $redis = $this->factory->createLazyClient($this->uri); - $promise = $client->ping(); + $promise = $redis->ping(); $this->assertInstanceOf('React\Promise\PromiseInterface', $promise); $ret = Block\await($promise, $this->loop); @@ -59,9 +59,9 @@ public function testPingLazy() */ public function testPingLazyWillNotBlockLoopWhenIdleTimeIsSmall() { - $client = $this->factory->createLazyClient($this->uri . '?idle=0'); + $redis = $this->factory->createLazyClient($this->uri . '?idle=0'); - $client->ping(); + $redis->ping(); $this->loop->run(); } @@ -71,41 +71,41 @@ public function testPingLazyWillNotBlockLoopWhenIdleTimeIsSmall() */ public function testLazyClientWithoutCommandsWillNotBlockLoop() { - $client = $this->factory->createLazyClient($this->uri); + $redis = $this->factory->createLazyClient($this->uri); $this->loop->run(); - unset($client); + unset($redis); } public function testMgetIsNotInterpretedAsSubMessage() { - $client = $this->createClient($this->uri); + $redis = $this->createClient($this->uri); - $client->mset('message', 'message', 'channel', 'channel', 'payload', 'payload'); + $redis->mset('message', 'message', 'channel', 'channel', 'payload', 'payload'); - $promise = $client->mget('message', 'channel', 'payload')->then($this->expectCallableOnce()); - $client->on('message', $this->expectCallableNever()); + $promise = $redis->mget('message', 'channel', 'payload')->then($this->expectCallableOnce()); + $redis->on('message', $this->expectCallableNever()); Block\await($promise, $this->loop); } public function testPipeline() { - $client = $this->createClient($this->uri); + $redis = $this->createClient($this->uri); - $client->set('a', 1)->then($this->expectCallableOnceWith('OK')); - $client->incr('a')->then($this->expectCallableOnceWith(2)); - $client->incr('a')->then($this->expectCallableOnceWith(3)); - $promise = $client->get('a')->then($this->expectCallableOnceWith('3')); + $redis->set('a', 1)->then($this->expectCallableOnceWith('OK')); + $redis->incr('a')->then($this->expectCallableOnceWith(2)); + $redis->incr('a')->then($this->expectCallableOnceWith(3)); + $promise = $redis->get('a')->then($this->expectCallableOnceWith('3')); Block\await($promise, $this->loop); } public function testInvalidCommand() { - $client = $this->createClient($this->uri); - $promise = $client->doesnotexist(1, 2, 3); + $redis = $this->createClient($this->uri); + $promise = $redis->doesnotexist(1, 2, 3); if (method_exists($this, 'expectException')) { $this->expectException('Exception'); @@ -117,23 +117,23 @@ public function testInvalidCommand() public function testMultiExecEmpty() { - $client = $this->createClient($this->uri); - $client->multi()->then($this->expectCallableOnceWith('OK')); - $promise = $client->exec()->then($this->expectCallableOnceWith(array())); + $redis = $this->createClient($this->uri); + $redis->multi()->then($this->expectCallableOnceWith('OK')); + $promise = $redis->exec()->then($this->expectCallableOnceWith(array())); Block\await($promise, $this->loop); } public function testMultiExecQueuedExecHasValues() { - $client = $this->createClient($this->uri); + $redis = $this->createClient($this->uri); - $client->multi()->then($this->expectCallableOnceWith('OK')); - $client->set('b', 10)->then($this->expectCallableOnceWith('QUEUED')); - $client->expire('b', 20)->then($this->expectCallableOnceWith('QUEUED')); - $client->incrBy('b', 2)->then($this->expectCallableOnceWith('QUEUED')); - $client->ttl('b')->then($this->expectCallableOnceWith('QUEUED')); - $promise = $client->exec()->then($this->expectCallableOnceWith(array('OK', 1, 12, 20))); + $redis->multi()->then($this->expectCallableOnceWith('OK')); + $redis->set('b', 10)->then($this->expectCallableOnceWith('QUEUED')); + $redis->expire('b', 20)->then($this->expectCallableOnceWith('QUEUED')); + $redis->incrBy('b', 2)->then($this->expectCallableOnceWith('QUEUED')); + $redis->ttl('b')->then($this->expectCallableOnceWith('QUEUED')); + $promise = $redis->exec()->then($this->expectCallableOnceWith(array('OK', 1, 12, 20))); Block\await($promise, $this->loop); } @@ -161,34 +161,34 @@ public function testPubSub() public function testClose() { - $client = $this->createClient($this->uri); + $redis = $this->createClient($this->uri); - $client->get('willBeCanceledAnyway')->then(null, $this->expectCallableOnce()); + $redis->get('willBeCanceledAnyway')->then(null, $this->expectCallableOnce()); - $client->close(); + $redis->close(); - $client->get('willBeRejectedRightAway')->then(null, $this->expectCallableOnce()); + $redis->get('willBeRejectedRightAway')->then(null, $this->expectCallableOnce()); } public function testCloseLazy() { - $client = $this->factory->createLazyClient($this->uri); + $redis = $this->factory->createLazyClient($this->uri); - $client->get('willBeCanceledAnyway')->then(null, $this->expectCallableOnce()); + $redis->get('willBeCanceledAnyway')->then(null, $this->expectCallableOnce()); - $client->close(); + $redis->close(); - $client->get('willBeRejectedRightAway')->then(null, $this->expectCallableOnce()); + $redis->get('willBeRejectedRightAway')->then(null, $this->expectCallableOnce()); } public function testInvalidProtocol() { - $client = $this->createClientResponse("communication does not conform to protocol\r\n"); + $redis = $this->createClientResponse("communication does not conform to protocol\r\n"); - $client->on('error', $this->expectCallableOnce()); - $client->on('close', $this->expectCallableOnce()); + $redis->on('error', $this->expectCallableOnce()); + $redis->on('close', $this->expectCallableOnce()); - $promise = $client->get('willBeRejectedDueToClosing'); + $promise = $redis->get('willBeRejectedDueToClosing'); if (method_exists($this, 'expectException')) { $this->expectException('Exception'); @@ -200,12 +200,12 @@ public function testInvalidProtocol() public function testInvalidServerRepliesWithDuplicateMessages() { - $client = $this->createClientResponse("+OK\r\n-ERR invalid\r\n"); + $redis = $this->createClientResponse("+OK\r\n-ERR invalid\r\n"); - $client->on('error', $this->expectCallableOnce()); - $client->on('close', $this->expectCallableOnce()); + $redis->on('error', $this->expectCallableOnce()); + $redis->on('close', $this->expectCallableOnce()); - $promise = $client->set('a', 0)->then($this->expectCallableOnceWith('OK')); + $promise = $redis->set('a', 0)->then($this->expectCallableOnceWith('OK')); Block\await($promise, $this->loop); } diff --git a/tests/LazyClientTest.php b/tests/LazyClientTest.php index 5510ec9..2ad644e 100644 --- a/tests/LazyClientTest.php +++ b/tests/LazyClientTest.php @@ -19,7 +19,7 @@ class LazyClientTest extends TestCase { private $factory; private $loop; - private $client; + private $redis; /** * @before @@ -29,7 +29,7 @@ public function setUpClient() $this->factory = $this->getMockBuilder('Clue\React\Redis\Factory')->disableOriginalConstructor()->getMock(); $this->loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); - $this->client = new LazyClient('localhost', $this->factory, $this->loop); + $this->redis = new LazyClient('localhost', $this->factory, $this->loop); } public function testPingWillCreateUnderlyingClientAndReturnPendingPromise() @@ -39,7 +39,7 @@ public function testPingWillCreateUnderlyingClientAndReturnPendingPromise() $this->loop->expects($this->never())->method('addTimer'); - $promise = $this->client->ping(); + $promise = $this->redis->ping(); $promise->then($this->expectCallableNever()); } @@ -49,8 +49,8 @@ public function testPingTwiceWillCreateOnceUnderlyingClient() $promise = new Promise(function () { }); $this->factory->expects($this->once())->method('createClient')->willReturn($promise); - $this->client->ping(); - $this->client->ping(); + $this->redis->ping(); + $this->redis->ping(); } public function testPingWillResolveWhenUnderlyingClientResolvesPingAndStartIdleTimer() @@ -63,7 +63,7 @@ public function testPingWillResolveWhenUnderlyingClientResolvesPingAndStartIdleT $this->loop->expects($this->once())->method('addTimer')->with(60.0, $this->anything()); - $promise = $this->client->ping(); + $promise = $this->redis->ping(); $deferred->resolve($client); $promise->then($this->expectCallableOnceWith('PONG')); @@ -71,7 +71,7 @@ public function testPingWillResolveWhenUnderlyingClientResolvesPingAndStartIdleT public function testPingWillResolveWhenUnderlyingClientResolvesPingAndStartIdleTimerWithIdleTimeFromQueryParam() { - $this->client = new LazyClient('localhost?idle=10', $this->factory, $this->loop); + $this->redis = new LazyClient('localhost?idle=10', $this->factory, $this->loop); $client = $this->getMockBuilder('Clue\React\Redis\Client')->getMock(); $client->expects($this->once())->method('__call')->with('ping')->willReturn(\React\Promise\resolve('PONG')); @@ -81,7 +81,7 @@ public function testPingWillResolveWhenUnderlyingClientResolvesPingAndStartIdleT $this->loop->expects($this->once())->method('addTimer')->with(10.0, $this->anything()); - $promise = $this->client->ping(); + $promise = $this->redis->ping(); $deferred->resolve($client); $promise->then($this->expectCallableOnceWith('PONG')); @@ -89,7 +89,7 @@ public function testPingWillResolveWhenUnderlyingClientResolvesPingAndStartIdleT public function testPingWillResolveWhenUnderlyingClientResolvesPingAndNotStartIdleTimerWhenIdleParamIsNegative() { - $this->client = new LazyClient('localhost?idle=-1', $this->factory, $this->loop); + $this->redis = new LazyClient('localhost?idle=-1', $this->factory, $this->loop); $client = $this->getMockBuilder('Clue\React\Redis\Client')->getMock(); $client->expects($this->once())->method('__call')->with('ping')->willReturn(\React\Promise\resolve('PONG')); @@ -99,7 +99,7 @@ public function testPingWillResolveWhenUnderlyingClientResolvesPingAndNotStartId $this->loop->expects($this->never())->method('addTimer'); - $promise = $this->client->ping(); + $promise = $this->redis->ping(); $deferred->resolve($client); $promise->then($this->expectCallableOnceWith('PONG')); @@ -116,7 +116,7 @@ public function testPingWillRejectWhenUnderlyingClientRejectsPingAndStartIdleTim $this->loop->expects($this->once())->method('addTimer'); - $promise = $this->client->ping(); + $promise = $this->redis->ping(); $deferred->resolve($client); $promise->then(null, $this->expectCallableOnceWith($error)); @@ -129,10 +129,10 @@ public function testPingWillRejectAndNotEmitErrorOrCloseWhenFactoryRejectsUnderl $deferred = new Deferred(); $this->factory->expects($this->once())->method('createClient')->willReturn($deferred->promise()); - $this->client->on('error', $this->expectCallableNever()); - $this->client->on('close', $this->expectCallableNever()); + $this->redis->on('error', $this->expectCallableNever()); + $this->redis->on('close', $this->expectCallableNever()); - $promise = $this->client->ping(); + $promise = $this->redis->ping(); $deferred->reject($error); $promise->then(null, $this->expectCallableOnceWith($error)); @@ -148,10 +148,10 @@ public function testPingAfterPreviousFactoryRejectsUnderlyingClientWillCreateNew new Promise(function () { }) ); - $this->client->ping(); + $this->redis->ping(); $deferred->reject($error); - $this->client->ping(); + $this->redis->ping(); } public function testPingAfterPreviousUnderlyingClientAlreadyClosedWillCreateNewUnderlyingConnection() @@ -171,19 +171,19 @@ public function testPingAfterPreviousUnderlyingClientAlreadyClosedWillCreateNewU new Promise(function () { }) ); - $this->client->ping(); + $this->redis->ping(); $this->assertTrue(is_callable($closeHandler)); $closeHandler(); - $this->client->ping(); + $this->redis->ping(); } public function testPingAfterCloseWillRejectWithoutCreatingUnderlyingConnection() { $this->factory->expects($this->never())->method('createClient'); - $this->client->close(); - $promise = $this->client->ping(); + $this->redis->close(); + $promise = $this->redis->ping(); $promise->then(null, $this->expectCallableOnceWith( $this->logicalAnd( @@ -211,8 +211,8 @@ public function testPingAfterPingWillNotStartIdleTimerWhenFirstPingResolves() $this->loop->expects($this->never())->method('addTimer'); - $this->client->ping(); - $this->client->ping(); + $this->redis->ping(); + $this->redis->ping(); $deferred->resolve(); } @@ -231,9 +231,9 @@ public function testPingAfterPingWillStartAndCancelIdleTimerWhenSecondPingStarts $this->loop->expects($this->once())->method('addTimer')->willReturn($timer); $this->loop->expects($this->once())->method('cancelTimer')->with($timer); - $this->client->ping(); + $this->redis->ping(); $deferred->resolve(); - $this->client->ping(); + $this->redis->ping(); } public function testPingFollowedByIdleTimerWillCloseUnderlyingConnectionWithoutCloseEvent() @@ -251,9 +251,9 @@ public function testPingFollowedByIdleTimerWillCloseUnderlyingConnectionWithoutC return true; }))->willReturn($timer); - $this->client->on('close', $this->expectCallableNever()); + $this->redis->on('close', $this->expectCallableNever()); - $this->client->ping(); + $this->redis->ping(); $this->assertNotNull($timeout); $timeout(); @@ -263,17 +263,17 @@ public function testCloseWillEmitCloseEventWithoutCreatingUnderlyingClient() { $this->factory->expects($this->never())->method('createClient'); - $this->client->on('close', $this->expectCallableOnce()); + $this->redis->on('close', $this->expectCallableOnce()); - $this->client->close(); + $this->redis->close(); } public function testCloseTwiceWillEmitCloseEventOnce() { - $this->client->on('close', $this->expectCallableOnce()); + $this->redis->on('close', $this->expectCallableOnce()); - $this->client->close(); - $this->client->close(); + $this->redis->close(); + $this->redis->close(); } public function testCloseAfterPingWillCancelUnderlyingClientConnectionWhenStillPending() @@ -281,8 +281,8 @@ public function testCloseAfterPingWillCancelUnderlyingClientConnectionWhenStillP $promise = new Promise(function () { }, $this->expectCallableOnce()); $this->factory->expects($this->once())->method('createClient')->willReturn($promise); - $this->client->ping(); - $this->client->close(); + $this->redis->ping(); + $this->redis->close(); } public function testCloseAfterPingWillEmitCloseWithoutErrorWhenUnderlyingClientConnectionThrowsDueToCancellation() @@ -292,11 +292,11 @@ public function testCloseAfterPingWillEmitCloseWithoutErrorWhenUnderlyingClientC }); $this->factory->expects($this->once())->method('createClient')->willReturn($promise); - $this->client->on('error', $this->expectCallableNever()); - $this->client->on('close', $this->expectCallableOnce()); + $this->redis->on('error', $this->expectCallableNever()); + $this->redis->on('close', $this->expectCallableOnce()); - $this->client->ping(); - $this->client->close(); + $this->redis->ping(); + $this->redis->close(); } public function testCloseAfterPingWillCloseUnderlyingClientConnectionWhenAlreadyResolved() @@ -308,9 +308,9 @@ public function testCloseAfterPingWillCloseUnderlyingClientConnectionWhenAlready $deferred = new Deferred(); $this->factory->expects($this->once())->method('createClient')->willReturn($deferred->promise()); - $this->client->ping(); + $this->redis->ping(); $deferred->resolve($client); - $this->client->close(); + $this->redis->close(); } public function testCloseAfterPingWillCancelIdleTimerWhenPingIsAlreadyResolved() @@ -326,9 +326,9 @@ public function testCloseAfterPingWillCancelIdleTimerWhenPingIsAlreadyResolved() $this->loop->expects($this->once())->method('addTimer')->willReturn($timer); $this->loop->expects($this->once())->method('cancelTimer')->with($timer); - $this->client->ping(); + $this->redis->ping(); $deferred->resolve(); - $this->client->close(); + $this->redis->close(); } public function testCloseAfterPingRejectsWillEmitClose() @@ -346,7 +346,7 @@ public function testCloseAfterPingRejectsWillEmitClose() $this->loop->expects($this->once())->method('addTimer')->willReturn($timer); $this->loop->expects($this->once())->method('cancelTimer')->with($timer); - $ref = $this->client; + $ref = $this->redis; $ref->ping()->then(null, function () use ($ref, $client) { $ref->close(); }); @@ -356,8 +356,8 @@ public function testCloseAfterPingRejectsWillEmitClose() public function testEndWillCloseClientIfUnderlyingConnectionIsNotPending() { - $this->client->on('close', $this->expectCallableOnce()); - $this->client->end(); + $this->redis->on('close', $this->expectCallableOnce()); + $this->redis->end(); } public function testEndAfterPingWillEndUnderlyingClient() @@ -369,9 +369,9 @@ public function testEndAfterPingWillEndUnderlyingClient() $deferred = new Deferred(); $this->factory->expects($this->once())->method('createClient')->willReturn($deferred->promise()); - $this->client->ping(); + $this->redis->ping(); $deferred->resolve($client); - $this->client->end(); + $this->redis->end(); } public function testEndAfterPingWillCloseClientWhenUnderlyingClientEmitsClose() @@ -389,11 +389,11 @@ public function testEndAfterPingWillCloseClientWhenUnderlyingClientEmitsClose() $deferred = new Deferred(); $this->factory->expects($this->once())->method('createClient')->willReturn($deferred->promise()); - $this->client->ping(); + $this->redis->ping(); $deferred->resolve($client); - $this->client->on('close', $this->expectCallableOnce()); - $this->client->end(); + $this->redis->on('close', $this->expectCallableOnce()); + $this->redis->end(); $this->assertTrue(is_callable($closeHandler)); $closeHandler(); @@ -409,10 +409,10 @@ public function testEmitsNoErrorEventWhenUnderlyingClientEmitsError() $deferred = new Deferred(); $this->factory->expects($this->once())->method('createClient')->willReturn($deferred->promise()); - $this->client->ping(); + $this->redis->ping(); $deferred->resolve($client); - $this->client->on('error', $this->expectCallableNever()); + $this->redis->on('error', $this->expectCallableNever()); $client->emit('error', array($error)); } @@ -424,10 +424,10 @@ public function testEmitsNoCloseEventWhenUnderlyingClientEmitsClose() $deferred = new Deferred(); $this->factory->expects($this->once())->method('createClient')->willReturn($deferred->promise()); - $this->client->ping(); + $this->redis->ping(); $deferred->resolve($client); - $this->client->on('close', $this->expectCallableNever()); + $this->redis->on('close', $this->expectCallableNever()); $client->emit('close'); } @@ -450,9 +450,9 @@ public function testEmitsNoCloseEventButWillCancelIdleTimerWhenUnderlyingConnect $this->loop->expects($this->once())->method('addTimer')->willReturn($timer); $this->loop->expects($this->once())->method('cancelTimer')->with($timer); - $this->client->on('close', $this->expectCallableNever()); + $this->redis->on('close', $this->expectCallableNever()); - $this->client->ping(); + $this->redis->ping(); $deferred->resolve(); $this->assertTrue(is_callable($closeHandler)); @@ -473,10 +473,10 @@ public function testEmitsMessageEventWhenUnderlyingClientEmitsMessageForPubSubCh $deferred = new Deferred(); $this->factory->expects($this->once())->method('createClient')->willReturn($deferred->promise()); - $this->client->subscribe('foo'); + $this->redis->subscribe('foo'); $deferred->resolve($client); - $this->client->on('message', $this->expectCallableOnce()); + $this->redis->on('message', $this->expectCallableOnce()); $this->assertTrue(is_callable($messageHandler)); $messageHandler('foo', 'bar'); } @@ -494,32 +494,32 @@ public function testEmitsUnsubscribeAndPunsubscribeEventsWhenUnderlyingClientClo $this->factory->expects($this->once())->method('createClient')->willReturn(\React\Promise\resolve($client)); - $this->client->subscribe('foo'); + $this->redis->subscribe('foo'); $this->assertTrue(is_callable($allHandler['subscribe'])); $allHandler['subscribe']('foo', 1); - $this->client->subscribe('bar'); + $this->redis->subscribe('bar'); $this->assertTrue(is_callable($allHandler['subscribe'])); $allHandler['subscribe']('bar', 2); - $this->client->unsubscribe('bar'); + $this->redis->unsubscribe('bar'); $this->assertTrue(is_callable($allHandler['unsubscribe'])); $allHandler['unsubscribe']('bar', 1); - $this->client->psubscribe('foo*'); + $this->redis->psubscribe('foo*'); $this->assertTrue(is_callable($allHandler['psubscribe'])); $allHandler['psubscribe']('foo*', 1); - $this->client->psubscribe('bar*'); + $this->redis->psubscribe('bar*'); $this->assertTrue(is_callable($allHandler['psubscribe'])); $allHandler['psubscribe']('bar*', 2); - $this->client->punsubscribe('bar*'); + $this->redis->punsubscribe('bar*'); $this->assertTrue(is_callable($allHandler['punsubscribe'])); $allHandler['punsubscribe']('bar*', 1); - $this->client->on('unsubscribe', $this->expectCallableOnce()); - $this->client->on('punsubscribe', $this->expectCallableOnce()); + $this->redis->on('unsubscribe', $this->expectCallableOnce()); + $this->redis->on('punsubscribe', $this->expectCallableOnce()); $this->assertTrue(is_callable($allHandler['close'])); $allHandler['close'](); @@ -541,7 +541,7 @@ public function testSubscribeWillResolveWhenUnderlyingClientResolvesSubscribeAnd $this->loop->expects($this->never())->method('addTimer'); - $promise = $this->client->subscribe('foo'); + $promise = $this->redis->subscribe('foo'); $this->assertTrue(is_callable($subscribeHandler)); $subscribeHandler('foo', 1); $deferred->resolve(array('subscribe', 'foo', 1)); @@ -570,13 +570,13 @@ public function testUnsubscribeAfterSubscribeWillResolveWhenUnderlyingClientReso $this->loop->expects($this->once())->method('addTimer'); - $promise = $this->client->subscribe('foo'); + $promise = $this->redis->subscribe('foo'); $this->assertTrue(is_callable($subscribeHandler)); $subscribeHandler('foo', 1); $deferredSubscribe->resolve(array('subscribe', 'foo', 1)); $promise->then($this->expectCallableOnceWith(array('subscribe', 'foo', 1))); - $promise = $this->client->unsubscribe('foo'); + $promise = $this->redis->unsubscribe('foo'); $this->assertTrue(is_callable($unsubscribeHandler)); $unsubscribeHandler('foo', 0); $deferredUnsubscribe->resolve(array('unsubscribe', 'foo', 0)); @@ -600,7 +600,7 @@ public function testBlpopWillRejectWhenUnderlyingClientClosesWhileWaitingForResp $this->loop->expects($this->never())->method('addTimer'); - $promise = $this->client->blpop('list'); + $promise = $this->redis->blpop('list'); $this->assertTrue(is_callable($closeHandler)); $closeHandler(); diff --git a/tests/StreamingClientTest.php b/tests/StreamingClientTest.php index af54942..bff6ca1 100644 --- a/tests/StreamingClientTest.php +++ b/tests/StreamingClientTest.php @@ -16,7 +16,7 @@ class StreamingClientTest extends TestCase private $stream; private $parser; private $serializer; - private $client; + private $redis; /** * @before @@ -27,27 +27,27 @@ public function setUpClient() $this->parser = $this->getMockBuilder('Clue\Redis\Protocol\Parser\ParserInterface')->getMock(); $this->serializer = $this->getMockBuilder('Clue\Redis\Protocol\Serializer\SerializerInterface')->getMock(); - $this->client = new StreamingClient($this->stream, $this->parser, $this->serializer); + $this->redis = new StreamingClient($this->stream, $this->parser, $this->serializer); } public function testConstructWithoutParserAssignsParserAutomatically() { - $this->client = new StreamingClient($this->stream, null, $this->serializer); + $this->redis = new StreamingClient($this->stream, null, $this->serializer); - $ref = new \ReflectionProperty($this->client, 'parser'); + $ref = new \ReflectionProperty($this->redis, 'parser'); $ref->setAccessible(true); - $parser = $ref->getValue($this->client); + $parser = $ref->getValue($this->redis); $this->assertInstanceOf('Clue\Redis\Protocol\Parser\ParserInterface', $parser); } public function testConstructWithoutParserAndSerializerAssignsParserAndSerializerAutomatically() { - $this->client = new StreamingClient($this->stream, $this->parser); + $this->redis = new StreamingClient($this->stream, $this->parser); - $ref = new \ReflectionProperty($this->client, 'serializer'); + $ref = new \ReflectionProperty($this->redis, 'serializer'); $ref->setAccessible(true); - $serializer = $ref->getValue($this->client); + $serializer = $ref->getValue($this->redis); $this->assertInstanceOf('Clue\Redis\Protocol\Serializer\SerializerInterface', $serializer); } @@ -57,22 +57,22 @@ public function testSending() $this->serializer->expects($this->once())->method('getRequestMessage')->with($this->equalTo('ping'))->will($this->returnValue('message')); $this->stream->expects($this->once())->method('write')->with($this->equalTo('message')); - $this->client->ping(); + $this->redis->ping(); } public function testClosingClientEmitsEvent() { - $this->client->on('close', $this->expectCallableOnce()); + $this->redis->on('close', $this->expectCallableOnce()); - $this->client->close(); + $this->redis->close(); } public function testClosingStreamClosesClient() { $this->stream = new ThroughStream(); - $this->client = new StreamingClient($this->stream, $this->parser, $this->serializer); + $this->redis = new StreamingClient($this->stream, $this->parser, $this->serializer); - $this->client->on('close', $this->expectCallableOnce()); + $this->redis->on('close', $this->expectCallableOnce()); $this->stream->emit('close'); } @@ -80,9 +80,9 @@ public function testClosingStreamClosesClient() public function testReceiveParseErrorEmitsErrorEvent() { $this->stream = new ThroughStream(); - $this->client = new StreamingClient($this->stream, $this->parser, $this->serializer); + $this->redis = new StreamingClient($this->stream, $this->parser, $this->serializer); - $this->client->on('error', $this->expectCallableOnceWith( + $this->redis->on('error', $this->expectCallableOnceWith( $this->logicalAnd( $this->isInstanceOf('UnexpectedValueException'), $this->callback(function (\UnexpectedValueException $e) { @@ -93,7 +93,7 @@ public function testReceiveParseErrorEmitsErrorEvent() }) ) )); - $this->client->on('close', $this->expectCallableOnce()); + $this->redis->on('close', $this->expectCallableOnce()); $this->parser->expects($this->once())->method('pushIncoming')->with('message')->willThrowException(new ParserException('Foo')); $this->stream->emit('data', array('message')); @@ -102,10 +102,10 @@ public function testReceiveParseErrorEmitsErrorEvent() public function testReceiveUnexpectedReplyEmitsErrorEvent() { $this->stream = new ThroughStream(); - $this->client = new StreamingClient($this->stream, $this->parser, $this->serializer); + $this->redis = new StreamingClient($this->stream, $this->parser, $this->serializer); - $this->client->on('error', $this->expectCallableOnce()); - $this->client->on('error', $this->expectCallableOnceWith( + $this->redis->on('error', $this->expectCallableOnce()); + $this->redis->on('error', $this->expectCallableOnceWith( $this->logicalAnd( $this->isInstanceOf('UnderflowException'), $this->callback(function (\UnderflowException $e) { @@ -134,9 +134,9 @@ public function testPingPong() { $this->serializer->expects($this->once())->method('getRequestMessage')->with($this->equalTo('ping')); - $promise = $this->client->ping(); + $promise = $this->redis->ping(); - $this->client->handleMessage(new BulkReply('PONG')); + $this->redis->handleMessage(new BulkReply('PONG')); $this->expectPromiseResolve($promise); $promise->then($this->expectCallableOnceWith('PONG')); @@ -144,7 +144,7 @@ public function testPingPong() public function testMonitorCommandIsNotSupported() { - $promise = $this->client->monitor(); + $promise = $this->redis->monitor(); $promise->then(null, $this->expectCallableOnceWith( $this->logicalAnd( @@ -161,18 +161,18 @@ public function testMonitorCommandIsNotSupported() public function testErrorReply() { - $promise = $this->client->invalid(); + $promise = $this->redis->invalid(); $err = new ErrorReply("ERR unknown command 'invalid'"); - $this->client->handleMessage($err); + $this->redis->handleMessage($err); $promise->then(null, $this->expectCallableOnceWith($err)); } public function testClosingClientRejectsAllRemainingRequests() { - $promise = $this->client->ping(); - $this->client->close(); + $promise = $this->redis->ping(); + $this->redis->close(); $promise->then(null, $this->expectCallableOnceWith( $this->logicalAnd( @@ -191,9 +191,9 @@ public function testClosingStreamRejectsAllRemainingRequests() { $this->stream = new ThroughStream(); $this->parser->expects($this->once())->method('pushIncoming')->willReturn(array()); - $this->client = new StreamingClient($this->stream, $this->parser, $this->serializer); + $this->redis = new StreamingClient($this->stream, $this->parser, $this->serializer); - $promise = $this->client->ping(); + $promise = $this->redis->ping(); $this->stream->close(); $promise->then(null, $this->expectCallableOnceWith( @@ -211,9 +211,9 @@ public function testClosingStreamRejectsAllRemainingRequests() public function testEndingClientRejectsAllNewRequests() { - $this->client->ping(); - $this->client->end(); - $promise = $this->client->ping(); + $this->redis->ping(); + $this->redis->end(); + $promise = $this->redis->ping(); $promise->then(null, $this->expectCallableOnceWith( $this->logicalAnd( @@ -230,8 +230,8 @@ public function testEndingClientRejectsAllNewRequests() public function testClosedClientRejectsAllNewRequests() { - $this->client->close(); - $promise = $this->client->ping(); + $this->redis->close(); + $promise = $this->redis->ping(); $promise->then(null, $this->expectCallableOnceWith( $this->logicalAnd( @@ -248,35 +248,35 @@ public function testClosedClientRejectsAllNewRequests() public function testEndingNonBusyClosesClient() { - $this->client->on('close', $this->expectCallableOnce()); - $this->client->end(); + $this->redis->on('close', $this->expectCallableOnce()); + $this->redis->end(); } public function testEndingBusyClosesClientWhenNotBusyAnymore() { // count how often the "close" method has been called $closed = 0; - $this->client->on('close', function() use (&$closed) { + $this->redis->on('close', function() use (&$closed) { ++$closed; }); - $promise = $this->client->ping(); + $promise = $this->redis->ping(); $this->assertEquals(0, $closed); - $this->client->end(); + $this->redis->end(); $this->assertEquals(0, $closed); - $this->client->handleMessage(new BulkReply('PONG')); + $this->redis->handleMessage(new BulkReply('PONG')); $promise->then($this->expectCallableOnceWith('PONG')); $this->assertEquals(1, $closed); } public function testClosingMultipleTimesEmitsOnce() { - $this->client->on('close', $this->expectCallableOnce()); + $this->redis->on('close', $this->expectCallableOnce()); - $this->client->close(); - $this->client->close(); + $this->redis->close(); + $this->redis->close(); } public function testReceivingUnexpectedMessageThrowsException() @@ -286,18 +286,18 @@ public function testReceivingUnexpectedMessageThrowsException() } else { $this->setExpectedException('UnderflowException'); } - $this->client->handleMessage(new BulkReply('PONG')); + $this->redis->handleMessage(new BulkReply('PONG')); } public function testPubsubSubscribe() { - $promise = $this->client->subscribe('test'); + $promise = $this->redis->subscribe('test'); $this->expectPromiseResolve($promise); - $this->client->on('subscribe', $this->expectCallableOnce()); - $this->client->handleMessage(new MultiBulkReply(array(new BulkReply('subscribe'), new BulkReply('test'), new IntegerReply(1)))); + $this->redis->on('subscribe', $this->expectCallableOnce()); + $this->redis->handleMessage(new MultiBulkReply(array(new BulkReply('subscribe'), new BulkReply('test'), new IntegerReply(1)))); - return $this->client; + return $this->redis; } /** @@ -327,7 +327,7 @@ public function testPubsubMessage(Client $client) public function testSubscribeWithMultipleArgumentsRejects() { - $promise = $this->client->subscribe('a', 'b'); + $promise = $this->redis->subscribe('a', 'b'); $promise->then(null, $this->expectCallableOnceWith( $this->logicalAnd( @@ -344,7 +344,7 @@ public function testSubscribeWithMultipleArgumentsRejects() public function testUnsubscribeWithoutArgumentsRejects() { - $promise = $this->client->unsubscribe(); + $promise = $this->redis->unsubscribe(); $promise->then(null, $this->expectCallableOnceWith( $this->logicalAnd(