From 373d30b0702f4347e2a2ba3e4007d25ecb098a7b Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Sat, 7 Dec 2013 12:01:27 +0100 Subject: [PATCH] Use Predis\Response\Status to identify all kinds of status responses. Status response objects are needed mostly to make it possible from the client perspective to differentiate a status response with the payload "OK" from a normale bulk reply containing "OK". The biggest change is for commands returning +OK responses: these were previously translated to TRUE (bool value), but they are now returned as instances of Predis\Response\Status. Just to illustrate an example of the possibilities with this change we will use SET since it is the most widely used command returning +OK: $response = $client->set('foo', 'bar'); echo $response; // 'OK' $response == 'OK'; // TRUE isset($response->ok); // TRUE $response == true; // TRUE $response === true; // FALSE $response instanceof Predis\Response\ObjectInterface; // TRUE $response instanceof Predis\Response\Status; // TRUE For those checking responses returned by commands such as SET or PONG, the breaking change basically lies in the usage of strict comparison: doing $response === true will now evaluate to FALSE instead of TRUE. By default Predis caches common status responses such as OK or QUEUED to lower the memory usage when using pipelines or transactions. --- CHANGELOG.md | 6 ++ examples/PipeliningCommands.php | 17 ++-- examples/TransactionWithCAS.php | 4 +- lib/Predis/Client.php | 6 +- lib/Predis/Command/ConnectionPing.php | 8 -- lib/Predis/Command/TransactionUnwatch.php | 8 -- lib/Predis/Command/TransactionWatch.php | 8 -- lib/Predis/Connection/PhpiredisConnection.php | 11 +-- .../Connection/PhpiredisStreamConnection.php | 11 +-- lib/Predis/Connection/StreamConnection.php | 11 +-- lib/Predis/Connection/WebdisConnection.php | 2 +- .../Protocol/Text/Handler/StatusResponse.php | 13 +-- .../Protocol/Text/ProtocolProcessor.php | 11 +-- lib/Predis/Response/Status.php | 81 +++++++++++++++++++ lib/Predis/Response/StatusQueued.php | 53 ------------ lib/Predis/Transaction/MultiExec.php | 2 +- tests/PHPUnit/PredisConnectionTestCase.php | 30 +++---- tests/Predis/ClientTest.php | 12 +-- tests/Predis/Command/ConnectionPingTest.php | 10 +-- tests/Predis/Command/ConnectionQuitTest.php | 10 +-- tests/Predis/Command/ConnectionSelectTest.php | 6 +- tests/Predis/Command/HashSetMultipleTest.php | 6 +- tests/Predis/Command/KeyRenameTest.php | 4 +- tests/Predis/Command/KeyTypeTest.php | 14 ++-- tests/Predis/Command/ListSetTest.php | 4 +- tests/Predis/Command/ListTrimTest.php | 12 +-- .../Command/PubSubSubscribeByPatternTest.php | 2 +- tests/Predis/Command/PubSubSubscribeTest.php | 2 +- tests/Predis/Command/ServerClientTest.php | 8 +- tests/Predis/Command/ServerConfigTest.php | 16 ++-- tests/Predis/Command/ServerFlushAllTest.php | 2 +- .../Command/ServerFlushDatabaseTest.php | 4 +- tests/Predis/Command/ServerMonitorTest.php | 6 +- tests/Predis/Command/ServerScriptTest.php | 6 +- tests/Predis/Command/ServerSlowlogTest.php | 2 +- tests/Predis/Command/StringBitOpTest.php | 2 +- tests/Predis/Command/StringGetTest.php | 2 +- .../Command/StringPreciseSetExpireTest.php | 4 +- tests/Predis/Command/StringSetExpireTest.php | 4 +- .../Predis/Command/StringSetMultipleTest.php | 4 +- tests/Predis/Command/StringSetTest.php | 6 +- .../Predis/Command/TransactionDiscardTest.php | 6 +- tests/Predis/Command/TransactionExecTest.php | 2 +- tests/Predis/Command/TransactionMultiTest.php | 16 ++-- .../Predis/Command/TransactionUnwatchTest.php | 6 +- tests/Predis/Command/TransactionWatchTest.php | 18 ++--- .../Connection/PhpiredisConnectionTest.php | 2 +- .../PhpiredisStreamConnectionTest.php | 2 +- .../Connection/WebdisConnectionTest.php | 2 +- tests/Predis/Monitor/ConsumerTest.php | 2 +- tests/Predis/Pipeline/AtomicTest.php | 16 ++-- tests/Predis/Pipeline/PipelineTest.php | 12 +-- .../Text/Handler/StatusResponseTest.php | 15 +++- .../Protocol/Text/ProtocolProcessorTest.php | 2 +- .../Protocol/Text/ResponseReaderTest.php | 4 +- tests/Predis/PubSub/ConsumerTest.php | 2 +- tests/Predis/PubSub/DispatcherLoopTest.php | 4 +- .../Response/Iterator/MultiBulkTest.php | 8 +- .../Response/Iterator/MultiBulkTupleTest.php | 4 +- tests/Predis/Response/StatusQueuedTest.php | 51 ------------ tests/Predis/Response/StatusTest.php | 57 +++++++++++++ tests/Predis/Transaction/MultiExecTest.php | 14 ++-- 62 files changed, 325 insertions(+), 350 deletions(-) create mode 100644 lib/Predis/Response/Status.php delete mode 100644 lib/Predis/Response/StatusQueued.php delete mode 100644 tests/Predis/Response/StatusQueuedTest.php create mode 100644 tests/Predis/Response/StatusTest.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 49dca1d1..5f7fcc68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,12 @@ v0.9.0 (201x-xx-xx) - Added `SENTINEL` to the profile for Redis 2.6 and `PUBSUB` to the profile for Redis 2.8. +- Status responses are returned as instances of `Predis\Response\Status`, for + example +OK is not returned as boolean TRUE anymore which is a breaking change + for those using strict comparisons. Status responses can be casted to string + values carrying the original payload, so one can do `$response == 'OK'` which + is also more akin to how Redis replies to clients. + - Added the `aggregate` client option, useful to fully customize how the client should aggregate multiple connections when an array of connection parameters is passed to `Predis\Client::__construct()`. diff --git a/examples/PipeliningCommands.php b/examples/PipeliningCommands.php index 315f2d08..49a81b5f 100644 --- a/examples/PipeliningCommands.php +++ b/examples/PipeliningCommands.php @@ -18,7 +18,6 @@ require 'SharedConfigurations.php'; $client = new Predis\Client($single_server); $replies = $client->pipeline(function ($pipe) { - $pipe->ping(); $pipe->flushdb(); $pipe->incrby('counter', 10); $pipe->incrby('counter', 30); @@ -31,14 +30,14 @@ var_export($replies); /* OUTPUT: array ( - 0 => true, - 1 => true, - 2 => 10, - 3 => 40, - 4 => true, - 5 => '40', - 6 => - array ( + 0 => Predis\Response\Status::__set_state(array( + 'payload' => 'OK', + )), + 1 => 10, + 2 => 40, + 3 => true, + 4 => '40', + 5 => array ( 0 => NULL, 1 => '40', ), diff --git a/examples/TransactionWithCAS.php b/examples/TransactionWithCAS.php index b6b0a318..412d714e 100644 --- a/examples/TransactionWithCAS.php +++ b/examples/TransactionWithCAS.php @@ -19,9 +19,7 @@ require 'SharedConfigurations.php'; // // ./redis-cli // SELECT 15 -// ZADD zset 1 a -// ZADD zset 2 b -// ZADD zset 3 c +// ZADD zset 1 a 2 b 3 c // // Then execute this script four times and see its output. // diff --git a/lib/Predis/Client.php b/lib/Predis/Client.php index 96c6a5f9..2fab2e6a 100644 --- a/lib/Predis/Client.php +++ b/lib/Predis/Client.php @@ -274,11 +274,9 @@ class Client implements ClientInterface } return (string) $response; - } else if ($response === true) { - return 'OK'; - } else { - return $response; } + + return $response; } /** diff --git a/lib/Predis/Command/ConnectionPing.php b/lib/Predis/Command/ConnectionPing.php index e49ec06f..f7e29ae9 100644 --- a/lib/Predis/Command/ConnectionPing.php +++ b/lib/Predis/Command/ConnectionPing.php @@ -24,12 +24,4 @@ class ConnectionPing extends Command { return 'PING'; } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - return $data === 'PONG' ? true : false; - } } diff --git a/lib/Predis/Command/TransactionUnwatch.php b/lib/Predis/Command/TransactionUnwatch.php index fcbc6ea3..a28abec2 100644 --- a/lib/Predis/Command/TransactionUnwatch.php +++ b/lib/Predis/Command/TransactionUnwatch.php @@ -24,12 +24,4 @@ class TransactionUnwatch extends Command { return 'UNWATCH'; } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - return (bool) $data; - } } diff --git a/lib/Predis/Command/TransactionWatch.php b/lib/Predis/Command/TransactionWatch.php index b1536647..1fc78808 100644 --- a/lib/Predis/Command/TransactionWatch.php +++ b/lib/Predis/Command/TransactionWatch.php @@ -36,12 +36,4 @@ class TransactionWatch extends Command return $arguments; } - - /** - * {@inheritdoc} - */ - public function parseResponse($data) - { - return (bool) $data; - } } diff --git a/lib/Predis/Connection/PhpiredisConnection.php b/lib/Predis/Connection/PhpiredisConnection.php index a9799235..41758267 100644 --- a/lib/Predis/Connection/PhpiredisConnection.php +++ b/lib/Predis/Connection/PhpiredisConnection.php @@ -134,16 +134,7 @@ class PhpiredisConnection extends AbstractConnection private function getStatusHandler() { return function ($payload) { - switch ($payload) { - case 'OK': - return true; - - case 'QUEUED': - return new Response\StatusQueued(); - - default: - return $payload; - } + return Response\Status::get($payload); }; } diff --git a/lib/Predis/Connection/PhpiredisStreamConnection.php b/lib/Predis/Connection/PhpiredisStreamConnection.php index a6c9c9b1..29d368a1 100644 --- a/lib/Predis/Connection/PhpiredisStreamConnection.php +++ b/lib/Predis/Connection/PhpiredisStreamConnection.php @@ -116,16 +116,7 @@ class PhpiredisStreamConnection extends StreamConnection protected function getStatusHandler() { return function ($payload) { - switch ($payload) { - case 'OK': - return true; - - case 'QUEUED': - return new Response\StatusQueued(); - - default: - return $payload; - } + return Response\Status::get($payload); }; } diff --git a/lib/Predis/Connection/StreamConnection.php b/lib/Predis/Connection/StreamConnection.php index f60a52b5..ddab47a9 100644 --- a/lib/Predis/Connection/StreamConnection.php +++ b/lib/Predis/Connection/StreamConnection.php @@ -187,16 +187,7 @@ class StreamConnection extends AbstractConnection switch ($prefix) { case '+': // inline - switch ($payload) { - case 'OK': - return true; - - case 'QUEUED': - return new Response\StatusQueued(); - - default: - return $payload; - } + return Response\Status::get($payload); case '$': // bulk $size = (int) $payload; diff --git a/lib/Predis/Connection/WebdisConnection.php b/lib/Predis/Connection/WebdisConnection.php index 35d3ca45..75924853 100644 --- a/lib/Predis/Connection/WebdisConnection.php +++ b/lib/Predis/Connection/WebdisConnection.php @@ -152,7 +152,7 @@ class WebdisConnection implements SingleConnectionInterface protected function getStatusHandler() { return function ($payload) { - return $payload === 'OK' ? true : $payload; + return Response\Status::get($payload); }; } diff --git a/lib/Predis/Protocol/Text/Handler/StatusResponse.php b/lib/Predis/Protocol/Text/Handler/StatusResponse.php index 8b526cb8..7aa8d027 100644 --- a/lib/Predis/Protocol/Text/Handler/StatusResponse.php +++ b/lib/Predis/Protocol/Text/Handler/StatusResponse.php @@ -27,17 +27,8 @@ class StatusResponse implements ResponseHandlerInterface /** * {@inheritdoc} */ - public function handle(ComposableConnectionInterface $connection, $status) + public function handle(ComposableConnectionInterface $connection, $payload) { - switch ($status) { - case 'OK': - return true; - - case 'QUEUED': - return new Response\StatusQueued(); - - default: - return $status; - } + return new Response\Status($payload); } } diff --git a/lib/Predis/Protocol/Text/ProtocolProcessor.php b/lib/Predis/Protocol/Text/ProtocolProcessor.php index 3e4c5f55..056fa985 100644 --- a/lib/Predis/Protocol/Text/ProtocolProcessor.php +++ b/lib/Predis/Protocol/Text/ProtocolProcessor.php @@ -59,16 +59,7 @@ class ProtocolProcessor implements ProtocolProcessorInterface switch ($prefix) { case '+': // inline - switch ($payload) { - case 'OK': - return true; - - case 'QUEUED': - return new Response\StatusQueued(); - - default: - return $payload; - } + return new Response\Status($payload); case '$': // bulk $size = (int) $payload; diff --git a/lib/Predis/Response/Status.php b/lib/Predis/Response/Status.php new file mode 100644 index 00000000..00ba2d7f --- /dev/null +++ b/lib/Predis/Response/Status.php @@ -0,0 +1,81 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Predis\Response; + +/** + * Represents a status response returned by Redis. + * + * @author Daniele Alessandri + */ +class Status implements ObjectInterface +{ + private static $OK; + private static $QUEUED; + + private $payload; + + /** + * @param string $payload Payload of the status response as returned by Redis. + */ + public function __construct($payload) + { + $this->payload = $payload; + } + + /** + * Converts the response object to its string representation. + * + * @return string + */ + public function __toString() + { + return $this->payload; + } + + /** + * Returns the payload of status response. + * + * @return string + */ + public function getPayload() + { + return $this->payload; + } + + /** + * Returns a new instance of a status response object. + * + * Common status responses such as OK or QUEUED are cached to lower the + * memory usage especially when using pipelines. + * + * @return string + */ + public static function get($payload) + { + switch ($payload) { + case 'OK': + if (!isset(self::$OK)) { + self::$OK = new self('OK'); + } + return self::$OK; + + case 'OK': + if (!isset(self::$QUEUED)) { + self::$QUEUED = new self('QUEUED'); + } + return self::$QUEUED; + + default: + return new self($payload); + } + } +} diff --git a/lib/Predis/Response/StatusQueued.php b/lib/Predis/Response/StatusQueued.php deleted file mode 100644 index f0fdf205..00000000 --- a/lib/Predis/Response/StatusQueued.php +++ /dev/null @@ -1,53 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Response; - -/** - * Represents a +QUEUED response returned by Redis as a reply to each command - * executed inside a MULTI/ EXEC transaction. - * - * @author Daniele Alessandri - */ -class StatusQueued implements ObjectInterface -{ - /** - * Converts the object to its string representation. - * - * @return string - */ - public function __toString() - { - return 'QUEUED'; - } - - /** - * Returns the value of the specified property. - * - * @param string $property Name of the property. - * @return mixed - */ - public function __get($property) - { - return $property === 'queued'; - } - - /** - * Checks if the specified property is set. - * - * @param string $property Name of the property. - * @return Boolean - */ - public function __isset($property) - { - return $property === 'queued'; - } -} diff --git a/lib/Predis/Transaction/MultiExec.php b/lib/Predis/Transaction/MultiExec.php index 58818051..a565cb49 100644 --- a/lib/Predis/Transaction/MultiExec.php +++ b/lib/Predis/Transaction/MultiExec.php @@ -193,7 +193,7 @@ class MultiExec implements BasicClientInterface, ExecutableContextInterface return $response; } - if (!$response instanceof Response\StatusQueued) { + if ($response != 'QUEUED' && !$response instanceof Response\Status) { $this->onProtocolError('The server did not respond with a QUEUED status response'); } diff --git a/tests/PHPUnit/PredisConnectionTestCase.php b/tests/PHPUnit/PredisConnectionTestCase.php index 41b40a44..850947d6 100644 --- a/tests/PHPUnit/PredisConnectionTestCase.php +++ b/tests/PHPUnit/PredisConnectionTestCase.php @@ -106,7 +106,7 @@ abstract class PredisConnectionTestCase extends PredisTestCase $connection = $this->getConnection($profile); $cmdPing = $profile->createCommand('ping'); - $this->assertSame('PONG', $connection->executeCommand($cmdPing)); + $this->assertEquals('PONG', $connection->executeCommand($cmdPing)); $this->assertTrue($connection->isConnected()); } @@ -121,7 +121,7 @@ abstract class PredisConnectionTestCase extends PredisTestCase $cmdPing->expects($this->never()) ->method('parseResponse'); - $this->assertSame('PONG', $connection->executeCommand($cmdPing)); + $this->assertEquals('PONG', $connection->executeCommand($cmdPing)); } /** @@ -131,11 +131,12 @@ abstract class PredisConnectionTestCase extends PredisTestCase { $connection = $this->getConnection($profile); - $cmdPing = $this->getMock($profile->getCommandClass('ping'), array('parseResponse')); - $cmdPing->expects($this->never()) + $cmdEcho = $this->getMock($profile->getCommandClass('echo'), array('parseResponse')); + $cmdEcho->setArguments(array('ECHOED')); + $cmdEcho->expects($this->never()) ->method('parseResponse'); - $connection->writeRequest($cmdPing); + $connection->writeRequest($cmdEcho); $connection->disconnect(); } @@ -146,12 +147,13 @@ abstract class PredisConnectionTestCase extends PredisTestCase { $connection = $this->getConnection($profile); - $cmdPing = $this->getMock($profile->getCommandClass('ping'), array('parseResponse')); - $cmdPing->expects($this->never()) + $cmdEcho = $this->getMock($profile->getCommandClass('echo'), array('parseResponse')); + $cmdEcho->setArguments(array('ECHOED')); + $cmdEcho->expects($this->never()) ->method('parseResponse'); - $connection->writeRequest($cmdPing); - $this->assertSame('PONG', $connection->readResponse($cmdPing)); + $connection->writeRequest($cmdEcho); + $this->assertSame('ECHOED', $connection->readResponse($cmdEcho)); } /** @@ -175,7 +177,7 @@ abstract class PredisConnectionTestCase extends PredisTestCase $connection->writeRequest($cmdPing); $connection->writeRequest($cmdEcho); - $this->assertSame('PONG', $connection->readResponse($cmdPing)); + $this->assertEquals('PONG', $connection->readResponse($cmdPing)); $this->assertSame('ECHOED', $connection->readResponse($cmdEcho)); } @@ -210,15 +212,15 @@ abstract class PredisConnectionTestCase extends PredisTestCase $connection = $this->getConnection($profile, true); $connection->writeRequest($profile->createCommand('set', array('foo', 'bar'))); - $this->assertTrue($connection->read()); + $this->assertInstanceOf('Predis\Response\Status', $connection->read()); $connection->writeRequest($profile->createCommand('ping')); - $this->assertSame('PONG', $connection->read()); + $this->assertInstanceOf('Predis\Response\Status', $connection->read()); $connection->writeRequest($profile->createCommand('multi')); $connection->writeRequest($profile->createCommand('ping')); - $this->assertTrue($connection->read()); - $this->assertInstanceOf('Predis\Response\StatusQueued', $connection->read()); + $this->assertInstanceOf('Predis\Response\Status', $connection->read()); + $this->assertInstanceOf('Predis\Response\Status', $connection->read()); } /** diff --git a/tests/Predis/ClientTest.php b/tests/Predis/ClientTest.php index 4642f22b..10afca0b 100644 --- a/tests/Predis/ClientTest.php +++ b/tests/Predis/ClientTest.php @@ -384,7 +384,7 @@ class ClientTest extends PredisTestCase $connection->expects($this->at(0)) ->method('executeCommand') ->with($ping) - ->will($this->returnValue('PONG')); + ->will($this->returnValue(new Response\Status('PONG'))); $connection->expects($this->at(1)) ->method('executeCommand') ->with($hgetall) @@ -392,7 +392,7 @@ class ClientTest extends PredisTestCase $client = new Client($connection); - $this->assertTrue($client->executeCommand($ping)); + $this->assertEquals('PONG', $client->executeCommand($ping)); $this->assertSame(array('foo' => 'bar', 'hoge' => 'piyo'), $client->executeCommand($hgetall)); } @@ -456,7 +456,7 @@ class ClientTest extends PredisTestCase $options = array('profile' => $profile); $client = $this->getMock('Predis\Client', null, array($connection, $options)); - $this->assertTrue($client->ping()); + $this->assertEquals('PONG', $client->ping()); } /** @@ -506,7 +506,7 @@ class ClientTest extends PredisTestCase $connection->expects($this->at(0)) ->method('executeCommand') ->with($this->isRedisCommand('SET', array('foo', 'bar'))) - ->will($this->returnValue(true)); + ->will($this->returnValue(new Response\Status('OK'))); $connection->expects($this->at(1)) ->method('executeCommand') ->with($this->isRedisCommand('GET', array('foo'))) @@ -535,7 +535,7 @@ class ClientTest extends PredisTestCase $connection->expects($this->at(0)) ->method('executeCommand') ->with($this->isRedisCommand('SET', array('foo', 'bar'))) - ->will($this->returnValue(true)); + ->will($this->returnValue(new Response\Status('OK'))); $connection->expects($this->at(1)) ->method('executeCommand') ->with($this->isRedisCommand('GET', array('foo'))) @@ -766,7 +766,7 @@ class ClientTest extends PredisTestCase $connection = $this->getMock('Predis\Connection\SingleConnectionInterface'); $connection->expects($this->once()) ->method('executeCommand') - ->will($this->returnValue(new Response\StatusQueued())); + ->will($this->returnValue(new Response\Status('QUEUED'))); $txCallback = function ($tx) { $tx->ping(); diff --git a/tests/Predis/Command/ConnectionPingTest.php b/tests/Predis/Command/ConnectionPingTest.php index 725337da..a34c95f4 100644 --- a/tests/Predis/Command/ConnectionPingTest.php +++ b/tests/Predis/Command/ConnectionPingTest.php @@ -52,18 +52,18 @@ class ConnectionPingTest extends PredisCommandTestCase */ public function testParseResponse() { - $command = $this->getCommand(); - - $this->assertTrue($command->parseResponse('PONG')); + $this->assertSame('PONG', $this->getCommand()->parseResponse('PONG')); } /** * @group connected */ - public function testAlwaysReturnsTrue() + public function testAlwaysReturnsStatusResponse() { $redis = $this->getClient(); + $response = $redis->ping(); - $this->assertTrue($redis->ping()); + $this->assertInstanceOf('Predis\Response\Status', $response); + $this->assertEquals('PONG', $response); } } diff --git a/tests/Predis/Command/ConnectionQuitTest.php b/tests/Predis/Command/ConnectionQuitTest.php index 1be47a54..a86530f3 100644 --- a/tests/Predis/Command/ConnectionQuitTest.php +++ b/tests/Predis/Command/ConnectionQuitTest.php @@ -52,19 +52,19 @@ class ConnectionQuitTest extends PredisCommandTestCase */ public function testParseResponse() { - $command = $this->getCommand(); - - $this->assertTrue($command->parseResponse(true)); + $this->assertSame('OK', $this->getCommand()->parseResponse('OK')); } /** * @group connected */ - public function testReturnsTrueWhenClosingConnection() + public function testReturnsStatusResponseWhenClosingConnection() { $redis = $this->getClient(); $command = $this->getCommand(); + $response = $redis->executeCommand($command); - $this->assertTrue($redis->executeCommand($command)); + $this->assertInstanceOf('Predis\Response\Status', $response); + $this->assertEquals('OK', $response); } } diff --git a/tests/Predis/Command/ConnectionSelectTest.php b/tests/Predis/Command/ConnectionSelectTest.php index c7623f05..72c19ab8 100644 --- a/tests/Predis/Command/ConnectionSelectTest.php +++ b/tests/Predis/Command/ConnectionSelectTest.php @@ -52,9 +52,7 @@ class ConnectionSelectTest extends PredisCommandTestCase */ public function testParseResponse() { - $command = $this->getCommand(); - - $this->assertTrue($command->parseResponse(true)); + $this->assertSame('OK', $this->getCommand()->parseResponse('OK')); } /** @@ -66,7 +64,7 @@ class ConnectionSelectTest extends PredisCommandTestCase $redis->set('foo', 'bar'); - $this->assertTrue($redis->select(REDIS_SERVER_DBNUM - 1)); + $this->assertEquals('OK', $redis->select(REDIS_SERVER_DBNUM - 1)); $this->assertFalse($redis->exists('foo')); } diff --git a/tests/Predis/Command/HashSetMultipleTest.php b/tests/Predis/Command/HashSetMultipleTest.php index ec64863b..3b2eb10a 100644 --- a/tests/Predis/Command/HashSetMultipleTest.php +++ b/tests/Predis/Command/HashSetMultipleTest.php @@ -66,7 +66,7 @@ class HashSetMultipleTest extends PredisCommandTestCase */ public function testParseResponse() { - $this->assertTrue($this->getCommand()->parseResponse(true)); + $this->assertSame('OK', $this->getCommand()->parseResponse('OK')); } /** @@ -76,10 +76,10 @@ class HashSetMultipleTest extends PredisCommandTestCase { $redis = $this->getClient(); - $this->assertTrue($redis->hmset('metavars', 'foo', 'bar', 'hoge', 'piyo')); + $this->assertEquals('OK', $redis->hmset('metavars', 'foo', 'bar', 'hoge', 'piyo')); $this->assertSame(array('foo' => 'bar', 'hoge' => 'piyo'), $redis->hgetall('metavars')); - $this->assertTrue($redis->hmset('metavars', 'foo', 'barbar', 'lol', 'wut')); + $this->assertEquals('OK', $redis->hmset('metavars', 'foo', 'barbar', 'lol', 'wut')); $this->assertSame(array('foo' => 'barbar', 'hoge' => 'piyo', 'lol' => 'wut'), $redis->hgetall('metavars')); } diff --git a/tests/Predis/Command/KeyRenameTest.php b/tests/Predis/Command/KeyRenameTest.php index 6041d236..8494dad7 100644 --- a/tests/Predis/Command/KeyRenameTest.php +++ b/tests/Predis/Command/KeyRenameTest.php @@ -52,7 +52,7 @@ class KeyRenameTest extends PredisCommandTestCase */ public function testParseResponse() { - $this->assertTrue($this->getCommand()->parseResponse(true)); + $this->assertSame('OK', $this->getCommand()->parseResponse('OK')); } /** @@ -64,7 +64,7 @@ class KeyRenameTest extends PredisCommandTestCase $redis->set('foo', 'bar'); - $this->assertTrue($redis->rename('foo', 'foofoo')); + $this->assertEquals('OK', $redis->rename('foo', 'foofoo')); $this->assertFalse($redis->exists('foo')); $this->assertTrue($redis->exists('foofoo')); } diff --git a/tests/Predis/Command/KeyTypeTest.php b/tests/Predis/Command/KeyTypeTest.php index 16f330bb..f2b053a3 100644 --- a/tests/Predis/Command/KeyTypeTest.php +++ b/tests/Predis/Command/KeyTypeTest.php @@ -52,7 +52,7 @@ class KeyTypeTest extends PredisCommandTestCase */ public function testParseResponse() { - $this->assertSame('type', $this->getCommand()->parseResponse('type')); + $this->assertSame('none', $this->getCommand()->parseResponse('none')); } /** @@ -62,21 +62,21 @@ class KeyTypeTest extends PredisCommandTestCase { $redis = $this->getClient(); - $this->assertSame('none', $redis->type('type:keydoesnotexist')); + $this->assertEquals('none', $redis->type('type:keydoesnotexist')); $redis->set('type:string', 'foobar'); - $this->assertSame('string', $redis->type('type:string')); + $this->assertEquals('string', $redis->type('type:string')); $redis->lpush('type:list', 'foobar'); - $this->assertSame('list', $redis->type('type:list')); + $this->assertEquals('list', $redis->type('type:list')); $redis->sadd('type:set', 'foobar'); - $this->assertSame('set', $redis->type('type:set')); + $this->assertEquals('set', $redis->type('type:set')); $redis->zadd('type:zset', 0, 'foobar'); - $this->assertSame('zset', $redis->type('type:zset')); + $this->assertEquals('zset', $redis->type('type:zset')); $redis->hset('type:hash', 'foo', 'bar'); - $this->assertSame('hash', $redis->type('type:hash')); + $this->assertEquals('hash', $redis->type('type:hash')); } } diff --git a/tests/Predis/Command/ListSetTest.php b/tests/Predis/Command/ListSetTest.php index ed1bb7b2..7ad9286f 100644 --- a/tests/Predis/Command/ListSetTest.php +++ b/tests/Predis/Command/ListSetTest.php @@ -52,7 +52,7 @@ class ListSetTest extends PredisCommandTestCase */ public function testParseResponse() { - $this->assertTrue($this->getCommand()->parseResponse(true)); + $this->assertSame('OK', $this->getCommand()->parseResponse('OK')); } /** @@ -64,7 +64,7 @@ class ListSetTest extends PredisCommandTestCase $redis->rpush('letters', 'a', 'b', 'c'); - $this->assertTrue($redis->lset('letters', 1, 'B')); + $this->assertEquals('OK', $redis->lset('letters', 1, 'B')); $this->assertSame(array('a', 'B', 'c'), $redis->lrange('letters', 0, -1)); } diff --git a/tests/Predis/Command/ListTrimTest.php b/tests/Predis/Command/ListTrimTest.php index 53af2b61..6c11d25b 100644 --- a/tests/Predis/Command/ListTrimTest.php +++ b/tests/Predis/Command/ListTrimTest.php @@ -52,7 +52,7 @@ class ListTrimTest extends PredisCommandTestCase */ public function testParseResponse() { - $this->assertTrue($this->getCommand()->parseResponse(true)); + $this->assertSame('OK', $this->getCommand()->parseResponse('OK')); } /** @@ -64,13 +64,13 @@ class ListTrimTest extends PredisCommandTestCase $redis->rpush('letters', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'l'); - $this->assertTrue($redis->ltrim('letters', 0, 2)); + $this->assertEquals('OK', $redis->ltrim('letters', 0, 2)); $this->assertSame(array('a', 'b', 'c'), $redis->lrange('letters', 0, -1)); $redis->flushdb(); $redis->rpush('letters', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'l'); - $this->assertTrue($redis->ltrim('letters', 5, 9)); + $this->assertEquals('OK', $redis->ltrim('letters', 5, 9)); $this->assertSame(array('f', 'g', 'h', 'i', 'l'), $redis->lrange('letters', 0, -1)); } @@ -83,7 +83,7 @@ class ListTrimTest extends PredisCommandTestCase $redis->rpush('letters', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'l'); - $this->assertTrue($redis->ltrim('letters', 0, -6)); + $this->assertEquals('OK', $redis->ltrim('letters', 0, -6)); $this->assertSame(array('a', 'b', 'c', 'd', 'e'), $redis->lrange('letters', 0, -1)); } @@ -96,7 +96,7 @@ class ListTrimTest extends PredisCommandTestCase $redis->rpush('letters', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'l'); - $this->assertTrue($redis->ltrim('letters', -5, -5)); + $this->assertEquals('OK', $redis->ltrim('letters', -5, -5)); $this->assertSame(array('f'), $redis->lrange('letters', 0, -1)); } @@ -109,7 +109,7 @@ class ListTrimTest extends PredisCommandTestCase $redis->rpush('letters', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'l'); - $this->assertTrue($redis->ltrim('letters', -100, 100)); + $this->assertEquals('OK', $redis->ltrim('letters', -100, 100)); $this->assertSame(array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'l'), $redis->lrange('letters', -100, 100)); } diff --git a/tests/Predis/Command/PubSubSubscribeByPatternTest.php b/tests/Predis/Command/PubSubSubscribeByPatternTest.php index adaacffd..7042a91c 100644 --- a/tests/Predis/Command/PubSubSubscribeByPatternTest.php +++ b/tests/Predis/Command/PubSubSubscribeByPatternTest.php @@ -139,7 +139,7 @@ class PubSubSubscribeByPatternTest extends PredisCommandTestCase $quit = $this->getProfile()->createCommand('quit'); $this->assertSame(array('subscribe', 'channel1', 1), $redis->subscribe('channel1')); - $this->assertTrue($redis->executeCommand($quit)); + $this->assertEquals('OK', $redis->executeCommand($quit)); } /** diff --git a/tests/Predis/Command/PubSubSubscribeTest.php b/tests/Predis/Command/PubSubSubscribeTest.php index f4eaf2bd..adb73829 100644 --- a/tests/Predis/Command/PubSubSubscribeTest.php +++ b/tests/Predis/Command/PubSubSubscribeTest.php @@ -139,7 +139,7 @@ class PubSubSubscribeTest extends PredisCommandTestCase $quit = $this->getProfile()->createCommand('quit'); $this->assertSame(array('subscribe', 'channel:foo', 1), $redis->subscribe('channel:foo')); - $this->assertTrue($redis->executeCommand($quit)); + $this->assertEquals('OK', $redis->executeCommand($quit)); } /** diff --git a/tests/Predis/Command/ServerClientTest.php b/tests/Predis/Command/ServerClientTest.php index bd97a858..ab4f3e56 100644 --- a/tests/Predis/Command/ServerClientTest.php +++ b/tests/Predis/Command/ServerClientTest.php @@ -153,7 +153,7 @@ BUFFER; $this->assertNull($clientName); $expectedConnectionName = 'foo-bar'; - $this->assertTrue($redis->client('SETNAME', $expectedConnectionName)); + $this->assertEquals('OK', $redis->client('SETNAME', $expectedConnectionName)); $this->assertEquals($expectedConnectionName, $redis->client('GETNAME')); } @@ -167,7 +167,7 @@ BUFFER; $redis = $this->getClient(); $expectedConnectionName = 'foo-baz'; - $this->assertTrue($redis->client('SETNAME', $expectedConnectionName)); + $this->assertEquals('OK', $redis->client('SETNAME', $expectedConnectionName)); $this->assertEquals($expectedConnectionName, $redis->client('GETNAME')); } @@ -204,7 +204,7 @@ BUFFER; { $redis = $this->getClient(); - $this->assertTrue($redis->client('FOO')); + $redis->client('FOO'); } /** @@ -216,6 +216,6 @@ BUFFER; { $redis = $this->getClient(); - $this->assertTrue($redis->client('KILL', '127.0.0.1:65535')); + $redis->client('KILL', '127.0.0.1:65535'); } } diff --git a/tests/Predis/Command/ServerConfigTest.php b/tests/Predis/Command/ServerConfigTest.php index 368754a9..39158605 100644 --- a/tests/Predis/Command/ServerConfigTest.php +++ b/tests/Predis/Command/ServerConfigTest.php @@ -69,9 +69,7 @@ class ServerConfigTest extends PredisCommandTestCase */ public function testParseResponseOfConfigSet() { - $command = $this->getCommand(); - - $this->assertTrue($command->parseResponse(true)); + $this->assertSame('OK', $this->getCommand()->parseResponse('OK')); } /** @@ -79,9 +77,7 @@ class ServerConfigTest extends PredisCommandTestCase */ public function testParseResponseOfConfigResetstat() { - $command = $this->getCommand(); - - $this->assertTrue($command->parseResponse(true)); + $this->assertSame('OK', $this->getCommand()->parseResponse('OK')); } /** @@ -129,7 +125,7 @@ class ServerConfigTest extends PredisCommandTestCase $previous = $redis->config('GET', 'loglevel'); - $this->assertTrue($redis->config('SET', 'loglevel', 'notice')); + $this->assertEquals('OK', $redis->config('SET', 'loglevel', 'notice')); $this->assertSame(array('loglevel' => 'notice'), $redis->config('GET', 'loglevel')); // We set the loglevel configuration to the previous value. @@ -145,7 +141,7 @@ class ServerConfigTest extends PredisCommandTestCase { $redis = $this->getClient(); - $this->assertFalse($redis->config('SET', 'foo', 'bar')); + $redis->config('SET', 'foo', 'bar'); } /** @@ -155,7 +151,7 @@ class ServerConfigTest extends PredisCommandTestCase { $redis = $this->getClient(); - $this->assertTrue($redis->config('RESETSTAT')); + $this->assertEquals('OK', $redis->config('RESETSTAT')); } /** @@ -166,6 +162,6 @@ class ServerConfigTest extends PredisCommandTestCase { $redis = $this->getClient(); - $this->assertFalse($redis->config('FOO')); + $redis->config('FOO'); } } diff --git a/tests/Predis/Command/ServerFlushAllTest.php b/tests/Predis/Command/ServerFlushAllTest.php index 6122e5d3..29736280 100644 --- a/tests/Predis/Command/ServerFlushAllTest.php +++ b/tests/Predis/Command/ServerFlushAllTest.php @@ -49,6 +49,6 @@ class ServerFlushAllTest extends PredisCommandTestCase */ public function testParseResponse() { - $this->assertTrue($this->getCommand()->parseResponse(true)); + $this->assertSame('OK', $this->getCommand()->parseResponse('OK')); } } diff --git a/tests/Predis/Command/ServerFlushDatabaseTest.php b/tests/Predis/Command/ServerFlushDatabaseTest.php index cb206f82..a86e9b9b 100644 --- a/tests/Predis/Command/ServerFlushDatabaseTest.php +++ b/tests/Predis/Command/ServerFlushDatabaseTest.php @@ -49,7 +49,7 @@ class ServerFlushDatabaseTest extends PredisCommandTestCase */ public function testParseResponse() { - $this->assertTrue($this->getCommand()->parseResponse(true)); + $this->assertSame('OK', $this->getCommand()->parseResponse('OK')); } /** @@ -61,7 +61,7 @@ class ServerFlushDatabaseTest extends PredisCommandTestCase $redis->set('foo', 'bar'); - $this->assertTrue($redis->flushdb()); + $this->assertEquals('OK', $redis->flushdb()); $this->assertFalse($redis->exists('foo')); } } diff --git a/tests/Predis/Command/ServerMonitorTest.php b/tests/Predis/Command/ServerMonitorTest.php index 01bd6aa6..68bdbcfe 100644 --- a/tests/Predis/Command/ServerMonitorTest.php +++ b/tests/Predis/Command/ServerMonitorTest.php @@ -50,18 +50,18 @@ class ServerMonitorTest extends PredisCommandTestCase */ public function testParseResponse() { - $this->assertTrue($this->getCommand()->parseResponse(true)); + $this->assertSame('OK', $this->getCommand()->parseResponse('OK')); } /** * @group connected */ - public function testReturnsTrueAndReadsEventsFromTheConnection() + public function testReturnsStatusResponseAndReadsEventsFromTheConnection() { $connection = $this->getClient()->getConnection(); $command = $this->getCommand(); - $this->assertTrue($connection->executeCommand($command)); + $this->assertEquals('OK', $connection->executeCommand($command)); // NOTE: Starting with 2.6 Redis does not return the "MONITOR" message after // +OK to the client that issued the MONITOR command. diff --git a/tests/Predis/Command/ServerScriptTest.php b/tests/Predis/Command/ServerScriptTest.php index 5db342d7..920b6796 100644 --- a/tests/Predis/Command/ServerScriptTest.php +++ b/tests/Predis/Command/ServerScriptTest.php @@ -52,14 +52,14 @@ class ServerScriptTest extends PredisCommandTestCase */ public function testParseResponse() { - $this->assertTrue($this->getCommand()->parseResponse(true)); + $this->assertSame('OK', $this->getCommand()->parseResponse('OK')); } /** * @group connected * @todo We should probably convert integers to booleans. */ - public function testExistsReturnAnArrayOfValues() + public function testExistsReturnsAnArrayOfValues() { $redis = $this->getClient(); @@ -91,7 +91,7 @@ class ServerScriptTest extends PredisCommandTestCase $sha1 = $redis->script('LOAD', 'return true'); - $this->assertTrue($redis->script('FLUSH')); + $this->assertEquals('OK', $redis->script('FLUSH')); $this->assertSame(array(0), $redis->script('EXISTS', $sha1)); } diff --git a/tests/Predis/Command/ServerSlowlogTest.php b/tests/Predis/Command/ServerSlowlogTest.php index 2a63fb64..0eb2f411 100644 --- a/tests/Predis/Command/ServerSlowlogTest.php +++ b/tests/Predis/Command/ServerSlowlogTest.php @@ -102,7 +102,7 @@ class ServerSlowlogTest extends PredisCommandTestCase { $redis = $this->getClient(); - $this->assertTrue($redis->slowlog('RESET')); + $this->assertEquals('OK', $redis->slowlog('RESET')); } /** diff --git a/tests/Predis/Command/StringBitOpTest.php b/tests/Predis/Command/StringBitOpTest.php index f22b9ba8..db0ae521 100644 --- a/tests/Predis/Command/StringBitOpTest.php +++ b/tests/Predis/Command/StringBitOpTest.php @@ -172,6 +172,6 @@ class StringBitOpTest extends PredisCommandTestCase $redis->lpush('key:dst', 'list'); $redis->bitop('AND', 'key:dst', 'key:src:1', 'key:src:2'); - $this->assertSame('none', $redis->type('key:dst')); + $this->assertEquals('none', $redis->type('key:dst')); } } diff --git a/tests/Predis/Command/StringGetTest.php b/tests/Predis/Command/StringGetTest.php index 523145ef..e132b09a 100644 --- a/tests/Predis/Command/StringGetTest.php +++ b/tests/Predis/Command/StringGetTest.php @@ -62,7 +62,7 @@ class StringGetTest extends PredisCommandTestCase { $redis = $this->getClient(); - $this->assertTrue($redis->set('foo', 'bar')); + $this->assertEquals('OK', $redis->set('foo', 'bar')); $this->assertEquals('bar', $redis->get('foo')); } diff --git a/tests/Predis/Command/StringPreciseSetExpireTest.php b/tests/Predis/Command/StringPreciseSetExpireTest.php index c064348d..e1cdc81c 100644 --- a/tests/Predis/Command/StringPreciseSetExpireTest.php +++ b/tests/Predis/Command/StringPreciseSetExpireTest.php @@ -52,7 +52,7 @@ class StringPreciseSetExpireTest extends PredisCommandTestCase */ public function testParseResponse() { - $this->assertTrue($this->getCommand()->parseResponse(true)); + $this->assertSame('OK', $this->getCommand()->parseResponse('OK')); } /** @@ -62,7 +62,7 @@ class StringPreciseSetExpireTest extends PredisCommandTestCase { $redis = $this->getClient(); - $this->assertTrue($redis->psetex('foo', 10000, 'bar')); + $this->assertEquals('OK', $redis->psetex('foo', 10000, 'bar')); $this->assertTrue($redis->exists('foo')); $this->assertEquals(10, $redis->ttl('foo')); } diff --git a/tests/Predis/Command/StringSetExpireTest.php b/tests/Predis/Command/StringSetExpireTest.php index b0a0afa9..7eb5f4ce 100644 --- a/tests/Predis/Command/StringSetExpireTest.php +++ b/tests/Predis/Command/StringSetExpireTest.php @@ -52,7 +52,7 @@ class StringSetExpireTest extends PredisCommandTestCase */ public function testParseResponse() { - $this->assertTrue($this->getCommand()->parseResponse(true)); + $this->assertSame('OK', $this->getCommand()->parseResponse('OK')); } /** @@ -62,7 +62,7 @@ class StringSetExpireTest extends PredisCommandTestCase { $redis = $this->getClient(); - $this->assertTrue($redis->setex('foo', 10, 'bar')); + $this->assertEquals('OK', $redis->setex('foo', 10, 'bar')); $this->assertTrue($redis->exists('foo')); $this->assertEquals(10, $redis->ttl('foo')); } diff --git a/tests/Predis/Command/StringSetMultipleTest.php b/tests/Predis/Command/StringSetMultipleTest.php index 40abdd99..4ba3c84a 100644 --- a/tests/Predis/Command/StringSetMultipleTest.php +++ b/tests/Predis/Command/StringSetMultipleTest.php @@ -66,7 +66,7 @@ class StringSetMultipleTest extends PredisCommandTestCase */ public function testParseResponse() { - $this->assertSame(true, $this->getCommand()->parseResponse(true)); + $this->assertSame('OK', $this->getCommand()->parseResponse('OK')); } /** @@ -76,7 +76,7 @@ class StringSetMultipleTest extends PredisCommandTestCase { $redis = $this->getClient(); - $this->assertTrue($redis->mset('foo', 'bar', 'hoge', 'piyo')); + $this->assertEquals('OK', $redis->mset('foo', 'bar', 'hoge', 'piyo')); $this->assertSame('bar', $redis->get('foo')); $this->assertSame('piyo', $redis->get('hoge')); } diff --git a/tests/Predis/Command/StringSetTest.php b/tests/Predis/Command/StringSetTest.php index 78f9d6bd..aeaa1d40 100644 --- a/tests/Predis/Command/StringSetTest.php +++ b/tests/Predis/Command/StringSetTest.php @@ -52,7 +52,7 @@ class StringSetTest extends PredisCommandTestCase */ public function testParseResponse() { - $this->assertTrue($this->getCommand()->parseResponse(true)); + $this->assertSame('OK', $this->getCommand()->parseResponse('OK')); } /** @@ -62,8 +62,8 @@ class StringSetTest extends PredisCommandTestCase { $redis = $this->getClient(); - $this->assertTrue($redis->set('foo', 'bar')); + $this->assertEquals('OK', $redis->set('foo', 'bar')); $this->assertTrue($redis->exists('foo')); - $this->assertEquals('bar', $redis->get('foo')); + $this->assertSame('bar', $redis->get('foo')); } } diff --git a/tests/Predis/Command/TransactionDiscardTest.php b/tests/Predis/Command/TransactionDiscardTest.php index c26a15c5..17013b41 100644 --- a/tests/Predis/Command/TransactionDiscardTest.php +++ b/tests/Predis/Command/TransactionDiscardTest.php @@ -49,7 +49,7 @@ class TransactionDiscardTest extends PredisCommandTestCase */ public function testParseResponse() { - $this->assertTrue($this->getCommand()->parseResponse(true)); + $this->assertSame('OK', $this->getCommand()->parseResponse('OK')); } /** @@ -61,8 +61,8 @@ class TransactionDiscardTest extends PredisCommandTestCase $redis->multi(); - $this->assertInstanceOf('Predis\Response\StatusQueued', $redis->set('foo', 'bar')); - $this->assertTrue($redis->discard()); + $this->assertEquals('QUEUED', $redis->set('foo', 'bar')); + $this->assertEquals('OK', $redis->discard()); $this->assertFalse($redis->exists('foo')); } diff --git a/tests/Predis/Command/TransactionExecTest.php b/tests/Predis/Command/TransactionExecTest.php index 7ed1324b..7788aa23 100644 --- a/tests/Predis/Command/TransactionExecTest.php +++ b/tests/Predis/Command/TransactionExecTest.php @@ -95,7 +95,7 @@ class TransactionExecTest extends PredisCommandTestCase $redis->set('foo', 'bar'); $redis->exists('foo'); - $this->assertSame(array('PONG', true, 1), $redis->exec()); + $this->assertEquals(array('PONG', 'OK', 1), $redis->exec()); } /** diff --git a/tests/Predis/Command/TransactionMultiTest.php b/tests/Predis/Command/TransactionMultiTest.php index d2b218dc..ecf414e9 100644 --- a/tests/Predis/Command/TransactionMultiTest.php +++ b/tests/Predis/Command/TransactionMultiTest.php @@ -49,7 +49,7 @@ class TransactionMultiTest extends PredisCommandTestCase */ public function testParseResponse() { - $this->assertTrue($this->getCommand()->parseResponse(true)); + $this->assertSame('OK', $this->getCommand()->parseResponse('OK')); } /** @@ -59,21 +59,21 @@ class TransactionMultiTest extends PredisCommandTestCase { $redis = $this->getClient(); - $this->assertTrue($redis->multi()); - $this->assertSame('QUEUED', (string) $redis->echo('tx1')); - $this->assertSame('QUEUED', (string) $redis->echo('tx2')); + $this->assertEquals('OK', $redis->multi()); + $this->assertEquals('QUEUED', $redis->echo('tx1')); + $this->assertEquals('QUEUED', $redis->echo('tx2')); } /** * @group connected */ - public function testActuallyReturnsReplyObjectAbstraction() + public function testActuallyReturnsResponseObjectAbstraction() { $redis = $this->getClient(); - $this->assertTrue($redis->multi()); - $this->assertInstanceOf('Predis\Response\ObjectInterface', $redis->echo('tx1')); - $this->assertInstanceOf('Predis\Response\StatusQueued', $redis->echo('tx2')); + $this->assertInstanceOf('Predis\Response\Status', $redis->multi()); + $this->assertInstanceOf('Predis\Response\Status', $redis->echo('tx1')); + $this->assertInstanceOf('Predis\Response\Status', $redis->echo('tx2')); } /** diff --git a/tests/Predis/Command/TransactionUnwatchTest.php b/tests/Predis/Command/TransactionUnwatchTest.php index 5bd6ec52..6aa26aa0 100644 --- a/tests/Predis/Command/TransactionUnwatchTest.php +++ b/tests/Predis/Command/TransactionUnwatchTest.php @@ -49,7 +49,7 @@ class TransactionUnwatchTest extends PredisCommandTestCase */ public function testParseResponse() { - $this->assertTrue($this->getCommand()->parseResponse(true)); + $this->assertSame('OK', $this->getCommand()->parseResponse('OK')); } /** @@ -62,7 +62,7 @@ class TransactionUnwatchTest extends PredisCommandTestCase $redis1->set('foo', 'bar'); $redis1->watch('foo'); - $this->assertTrue($redis1->unwatch()); + $this->assertEquals('OK', $redis1->unwatch()); $redis1->multi(); $redis1->get('foo'); @@ -79,6 +79,6 @@ class TransactionUnwatchTest extends PredisCommandTestCase $redis = $this->getClient(); $redis->multi(); - $this->assertInstanceOf('Predis\Response\StatusQueued', $redis->unwatch()); + $this->assertInstanceOf('Predis\Response\Status', $redis->unwatch()); } } diff --git a/tests/Predis/Command/TransactionWatchTest.php b/tests/Predis/Command/TransactionWatchTest.php index 71576370..23dd1609 100644 --- a/tests/Predis/Command/TransactionWatchTest.php +++ b/tests/Predis/Command/TransactionWatchTest.php @@ -66,7 +66,7 @@ class TransactionWatchTest extends PredisCommandTestCase */ public function testParseResponse() { - $this->assertTrue($this->getCommand()->parseResponse(true)); + $this->assertSame('OK', $this->getCommand()->parseResponse('OK')); } /** @@ -79,10 +79,10 @@ class TransactionWatchTest extends PredisCommandTestCase $redis1->mset('foo', 'bar', 'hoge', 'piyo'); - $this->assertTrue($redis1->watch('foo', 'hoge')); - $this->assertTrue($redis1->multi()); - $this->assertInstanceOf('Predis\Response\StatusQueued', $redis1->get('foo')); - $this->assertTrue($redis2->set('foo', 'hijacked')); + $this->assertEquals('OK', $redis1->watch('foo', 'hoge')); + $this->assertEquals('OK', $redis1->multi()); + $this->assertEquals('QUEUED', $redis1->get('foo')); + $this->assertEquals('OK', $redis2->set('foo', 'hijacked')); $this->assertNull($redis1->exec()); $this->assertSame('hijacked', $redis1->get('foo')); } @@ -95,10 +95,10 @@ class TransactionWatchTest extends PredisCommandTestCase $redis1 = $this->getClient(); $redis2 = $this->getClient(); - $this->assertTrue($redis1->watch('foo')); - $this->assertTrue($redis1->multi()); - $this->assertInstanceOf('Predis\Response\StatusQueued', $redis1->set('foo', 'bar')); - $this->assertTrue($redis2->set('foo', 'hijacked')); + $this->assertEquals('OK', $redis1->watch('foo')); + $this->assertEquals('OK', $redis1->multi()); + $this->assertEquals('QUEUED', $redis1->set('foo', 'bar')); + $this->assertEquals('OK', $redis2->set('foo', 'hijacked')); $this->assertNull($redis1->exec()); $this->assertSame('hijacked', $redis1->get('foo')); } diff --git a/tests/Predis/Connection/PhpiredisConnectionTest.php b/tests/Predis/Connection/PhpiredisConnectionTest.php index a34424a4..8d65df68 100644 --- a/tests/Predis/Connection/PhpiredisConnectionTest.php +++ b/tests/Predis/Connection/PhpiredisConnectionTest.php @@ -79,7 +79,7 @@ class PhpiredisConnectionTest extends PredisConnectionTestCase $cmdRpush = $profile->createCommand('rpush', array('metavars', 'foo', 'hoge', 'lol')); $cmdLrange = $profile->createCommand('lrange', array('metavars', 0, -1)); - $this->assertSame('PONG', $connection->executeCommand($cmdPing)); + $this->assertEquals('PONG', $connection->executeCommand($cmdPing)); $this->assertSame('echoed', $connection->executeCommand($cmdEcho)); $this->assertNull($connection->executeCommand($cmdGet)); $this->assertSame(3, $connection->executeCommand($cmdRpush)); diff --git a/tests/Predis/Connection/PhpiredisStreamConnectionTest.php b/tests/Predis/Connection/PhpiredisStreamConnectionTest.php index f68673d9..554159bc 100644 --- a/tests/Predis/Connection/PhpiredisStreamConnectionTest.php +++ b/tests/Predis/Connection/PhpiredisStreamConnectionTest.php @@ -97,7 +97,7 @@ class PhpiredisStreamConnectionTest extends PredisConnectionTestCase $cmdRpush = $profile->createCommand('rpush', array('metavars', 'foo', 'hoge', 'lol')); $cmdLrange = $profile->createCommand('lrange', array('metavars', 0, -1)); - $this->assertSame('PONG', $connection->executeCommand($cmdPing)); + $this->assertEquals('PONG', $connection->executeCommand($cmdPing)); $this->assertSame('echoed', $connection->executeCommand($cmdEcho)); $this->assertNull($connection->executeCommand($cmdGet)); $this->assertSame(3, $connection->executeCommand($cmdRpush)); diff --git a/tests/Predis/Connection/WebdisConnectionTest.php b/tests/Predis/Connection/WebdisConnectionTest.php index 64c67c72..76c91d29 100644 --- a/tests/Predis/Connection/WebdisConnectionTest.php +++ b/tests/Predis/Connection/WebdisConnectionTest.php @@ -129,7 +129,7 @@ class WebdisConnectionTest extends PredisTestCase $cmdRpush = $profile->createCommand('rpush', array('metavars', 'foo', 'hoge', 'lol')); $cmdLrange = $profile->createCommand('lrange', array('metavars', 0, -1)); - $this->assertSame('PONG', $connection->executeCommand($cmdPing)); + $this->assertEquals('PONG', $connection->executeCommand($cmdPing)); $this->assertSame('echoed', $connection->executeCommand($cmdEcho)); $this->assertNull($connection->executeCommand($cmdGet)); $this->assertSame(3, $connection->executeCommand($cmdRpush)); diff --git a/tests/Predis/Monitor/ConsumerTest.php b/tests/Predis/Monitor/ConsumerTest.php index 1b7751dd..95e1053b 100644 --- a/tests/Predis/Monitor/ConsumerTest.php +++ b/tests/Predis/Monitor/ConsumerTest.php @@ -192,6 +192,6 @@ class ConsumerTest extends PredisTestCase $this->assertSame(array('message1', 'message2', 'QUIT'), $echoed); $this->assertFalse($monitor->valid()); - $this->assertTrue($consumer->ping()); + $this->assertEquals('PONG', $consumer->ping()); } } diff --git a/tests/Predis/Pipeline/AtomicTest.php b/tests/Predis/Pipeline/AtomicTest.php index b6528ee2..e1e74660 100644 --- a/tests/Predis/Pipeline/AtomicTest.php +++ b/tests/Predis/Pipeline/AtomicTest.php @@ -26,12 +26,13 @@ class AtomicTest extends PredisTestCase */ public function testPipelineWithSingleConnection() { - $queued = new Response\StatusQueued(); + $pong = new Response\Status('PONG'); + $queued = new Response\Status('QUEUED'); $connection = $this->getMock('Predis\Connection\SingleConnectionInterface'); $connection->expects($this->exactly(2)) ->method('executeCommand') - ->will($this->onConsecutiveCalls(true, array('PONG', 'PONG', 'PONG'))); + ->will($this->onConsecutiveCalls(true, array($pong, $pong, $pong))); $connection->expects($this->exactly(3)) ->method('writeRequest'); $connection->expects($this->at(3)) @@ -44,7 +45,7 @@ class AtomicTest extends PredisTestCase $pipeline->ping(); $pipeline->ping(); - $this->assertSame(array(true, true, true), $pipeline->execute()); + $this->assertSame(array($pong, $pong, $pong), $pipeline->execute()); } /** @@ -75,7 +76,7 @@ class AtomicTest extends PredisTestCase */ public function testPipelineWithErrorInTransaction() { - $queued = new Response\StatusQueued(); + $queued = new Response\Status('QUEUED'); $error = new Response\Error('ERR Test error'); $connection = $this->getMock('Predis\Connection\SingleConnectionInterface'); @@ -125,7 +126,8 @@ class AtomicTest extends PredisTestCase */ public function testReturnsResponseErrorWithClientExceptionsSetToFalse() { - $queued = new Response\StatusQueued(); + $pong = new Response\Status('PONG'); + $queued = new Response\Status('QUEUED'); $error = new Response\Error('ERR Test error'); $connection = $this->getMock('Predis\Connection\SingleConnectionInterface'); @@ -134,7 +136,7 @@ class AtomicTest extends PredisTestCase ->will($this->onConsecutiveCalls($queued, $queued, $queued)); $connection->expects($this->at(7)) ->method('executeCommand') - ->will($this->returnValue(array('PONG', 'PONG', $error))); + ->will($this->returnValue(array($pong, $pong, $error))); $pipeline = new Atomic(new Client($connection, array('exceptions' => false))); @@ -142,7 +144,7 @@ class AtomicTest extends PredisTestCase $pipeline->ping(); $pipeline->ping(); - $this->assertSame(array(true, true, $error), $pipeline->execute()); + $this->assertSame(array($pong, $pong, $error), $pipeline->execute()); } /** diff --git a/tests/Predis/Pipeline/PipelineTest.php b/tests/Predis/Pipeline/PipelineTest.php index 8032b4da..2a105e90 100644 --- a/tests/Predis/Pipeline/PipelineTest.php +++ b/tests/Predis/Pipeline/PipelineTest.php @@ -228,6 +228,8 @@ class PipelineTest extends PredisTestCase */ public function testSwitchesToMasterWithReplicationConnection() { + $pong = new Response\Status('PONG'); + $connection = $this->getMock('Predis\Connection\ReplicationConnectionInterface'); $connection->expects($this->once()) ->method('switchTo') @@ -236,7 +238,7 @@ class PipelineTest extends PredisTestCase ->method('writeRequest'); $connection->expects($this->exactly(3)) ->method('readResponse') - ->will($this->returnValue('PONG')); + ->will($this->returnValue($pong)); $pipeline = new Pipeline(new Client($connection)); @@ -244,7 +246,7 @@ class PipelineTest extends PredisTestCase $pipeline->ping(); $pipeline->ping(); - $this->assertSame(array(true, true, true), $pipeline->execute()); + $this->assertSame(array($pong, $pong, $pong), $pipeline->execute()); } /** @@ -372,7 +374,7 @@ class PipelineTest extends PredisTestCase $pipe->get('foo'); }); - $this->assertSame(array(true, 'bar'), $results); + $this->assertEquals(array('OK', 'bar'), $results); $this->assertTrue($client->exists('foo')); } @@ -390,7 +392,7 @@ class PipelineTest extends PredisTestCase $pipe->get('foo'); }); - $this->assertSame(array(true, 'bar'), $results); + $this->assertEquals(array('OK', 'bar'), $results); $this->assertSame('oob message', $oob); $this->assertTrue($client->exists('foo')); } @@ -453,7 +455,7 @@ class PipelineTest extends PredisTestCase $pipe->get('foo'); }); - $this->assertTrue($results[0]); + $this->assertEquals('OK', $results[0]); $this->assertInstanceOf('Predis\Response\Error', $results[1]); $this->assertSame('bar', $results[2]); } diff --git a/tests/Predis/Protocol/Text/Handler/StatusResponseTest.php b/tests/Predis/Protocol/Text/Handler/StatusResponseTest.php index b211598f..fb7ca6e8 100644 --- a/tests/Predis/Protocol/Text/Handler/StatusResponseTest.php +++ b/tests/Predis/Protocol/Text/Handler/StatusResponseTest.php @@ -30,7 +30,10 @@ class StatusResponseTest extends PredisTestCase $connection->expects($this->never())->method('readLine'); $connection->expects($this->never())->method('readBytes'); - $this->assertTrue($handler->handle($connection, 'OK')); + $response = $handler->handle($connection, 'OK'); + + $this->assertInstanceOf('Predis\Response\Status', $response); + $this->assertEquals('OK', $response); } /** @@ -45,7 +48,10 @@ class StatusResponseTest extends PredisTestCase $connection->expects($this->never())->method('readLine'); $connection->expects($this->never())->method('readBytes'); - $this->assertInstanceOf('Predis\Response\StatusQueued', $handler->handle($connection, 'QUEUED')); + $response = $handler->handle($connection, 'QUEUED'); + + $this->assertInstanceOf('Predis\Response\Status', $response); + $this->assertEquals('QUEUED', $response); } /** @@ -60,6 +66,9 @@ class StatusResponseTest extends PredisTestCase $connection->expects($this->never())->method('readLine'); $connection->expects($this->never())->method('readBytes'); - $this->assertSame('Background saving started', $handler->handle($connection, 'Background saving started')); + $response = $handler->handle($connection, 'Background saving started'); + + $this->assertInstanceOf('Predis\Response\Status', $response); + $this->assertEquals('Background saving started', $response); } } diff --git a/tests/Predis/Protocol/Text/ProtocolProcessorTest.php b/tests/Predis/Protocol/Text/ProtocolProcessorTest.php index 363f4c3e..ea3c23fe 100644 --- a/tests/Predis/Protocol/Text/ProtocolProcessorTest.php +++ b/tests/Predis/Protocol/Text/ProtocolProcessorTest.php @@ -76,7 +76,7 @@ class ProtocolProcessorTest extends PredisTestCase ->method('readLine') ->will($this->returnValue("*-1")); - $this->assertTrue($protocol->read($connection)); + $this->assertEquals('OK', $protocol->read($connection)); $this->assertEquals("ERR error message", $protocol->read($connection)); $this->assertSame(2, $protocol->read($connection)); $this->assertNull($protocol->read($connection)); diff --git a/tests/Predis/Protocol/Text/ResponseReaderTest.php b/tests/Predis/Protocol/Text/ResponseReaderTest.php index c860ff69..a6ecc177 100644 --- a/tests/Predis/Protocol/Text/ResponseReaderTest.php +++ b/tests/Predis/Protocol/Text/ResponseReaderTest.php @@ -79,8 +79,8 @@ class ResponseReaderTest extends PredisTestCase ->method('readLine') ->will($this->returnValue("*-1")); - $this->assertTrue($reader->read($connection)); - $this->assertEquals("ERR error message", $reader->read($connection)); + $this->assertEquals('OK', $reader->read($connection)); + $this->assertEquals('ERR error message', $reader->read($connection)); $this->assertSame(2, $reader->read($connection)); $this->assertNull($reader->read($connection)); $this->assertNull($reader->read($connection)); diff --git a/tests/Predis/PubSub/ConsumerTest.php b/tests/Predis/PubSub/ConsumerTest.php index 9490b145..37dcf344 100644 --- a/tests/Predis/PubSub/ConsumerTest.php +++ b/tests/Predis/PubSub/ConsumerTest.php @@ -303,6 +303,6 @@ class ConsumerTest extends PredisTestCase $this->assertSame(array('message1', 'message2', 'QUIT'), $messages); $this->assertFalse($pubsub->valid()); - $this->assertTrue($consumer->ping()); + $this->assertEquals('PONG', $consumer->ping()); } } diff --git a/tests/Predis/PubSub/DispatcherLoopTest.php b/tests/Predis/PubSub/DispatcherLoopTest.php index e92c8940..2b5f83f8 100644 --- a/tests/Predis/PubSub/DispatcherLoopTest.php +++ b/tests/Predis/PubSub/DispatcherLoopTest.php @@ -78,7 +78,7 @@ class DispatcherLoopTest extends PredisTestCase $dispatcher->run(); - $this->assertTrue($consumer->ping()); + $this->assertEquals('PONG', $consumer->ping()); } /** @@ -120,6 +120,6 @@ class DispatcherLoopTest extends PredisTestCase $dispatcher->run(); - $this->assertTrue($consumer->ping()); + $this->assertEquals('PONG', $consumer->ping()); } } diff --git a/tests/Predis/Response/Iterator/MultiBulkTest.php b/tests/Predis/Response/Iterator/MultiBulkTest.php index 39f5bbeb..0e7b9ced 100644 --- a/tests/Predis/Response/Iterator/MultiBulkTest.php +++ b/tests/Predis/Response/Iterator/MultiBulkTest.php @@ -47,7 +47,7 @@ class MultiBulkTest extends PredisTestCase $this->assertSame(3, $iterator->next()); $this->assertFalse($iterator->valid()); - $this->assertTrue($client->ping()); + $this->assertEquals('PONG', $client->ping()); } /** @@ -74,7 +74,7 @@ class MultiBulkTest extends PredisTestCase $iterator->drop(false); $this->assertTrue($client->isConnected()); - $this->assertTrue($client->ping()); + $this->assertEquals('PONG', $client->ping()); } /** @@ -89,7 +89,7 @@ class MultiBulkTest extends PredisTestCase $iterator->drop(true); $this->assertFalse($client->isConnected()); - $this->assertTrue($client->ping()); + $this->assertEquals('PONG', $client->ping()); } /** @@ -105,7 +105,7 @@ class MultiBulkTest extends PredisTestCase unset($iterator); $this->assertFalse($client->isConnected()); - $this->assertTrue($client->ping()); + $this->assertEquals('PONG', $client->ping()); } // ******************************************************************** // diff --git a/tests/Predis/Response/Iterator/MultiBulkTupleTest.php b/tests/Predis/Response/Iterator/MultiBulkTupleTest.php index 3fa16a7e..e3fbe51c 100644 --- a/tests/Predis/Response/Iterator/MultiBulkTupleTest.php +++ b/tests/Predis/Response/Iterator/MultiBulkTupleTest.php @@ -75,7 +75,7 @@ class MultiBulkTupleTest extends PredisTestCase $this->assertSame(3, $iterator->next()); $this->assertFalse($iterator->valid()); - $this->assertTrue($client->ping()); + $this->assertEquals('PONG', $client->ping()); } /** @@ -91,7 +91,7 @@ class MultiBulkTupleTest extends PredisTestCase unset($iterator); $this->assertFalse($client->isConnected()); - $this->assertTrue($client->ping()); + $this->assertEquals('PONG', $client->ping()); } // ******************************************************************** // diff --git a/tests/Predis/Response/StatusQueuedTest.php b/tests/Predis/Response/StatusQueuedTest.php deleted file mode 100644 index a7d43334..00000000 --- a/tests/Predis/Response/StatusQueuedTest.php +++ /dev/null @@ -1,51 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace Predis\Response; - -use PredisTestCase; - -/** - * - */ -class StatusQueuedTest extends PredisTestCase -{ - /** - * @group disconnected - */ - public function testResponseQueuedClass() - { - $queued = new StatusQueued(); - - $this->assertInstanceOf('Predis\Response\ObjectInterface', $queued); - } - - /** - * @group disconnected - */ - public function testToString() - { - $queued = new StatusQueued(); - - $this->assertEquals('QUEUED', (string) $queued); - } - - /** - * @group disconnected - */ - public function testQueuedProperty() - { - $queued = new StatusQueued(); - - $this->assertTrue(isset($queued->queued)); - $this->assertTrue($queued->queued); - } -} diff --git a/tests/Predis/Response/StatusTest.php b/tests/Predis/Response/StatusTest.php new file mode 100644 index 00000000..d5f9a4a1 --- /dev/null +++ b/tests/Predis/Response/StatusTest.php @@ -0,0 +1,57 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Predis\Response; + +use PredisTestCase; + +/** + * + */ +class StatusTest extends PredisTestCase +{ + /** + * @group disconnected + */ + public function testStatusResponse() + { + $status = new Status('OK'); + + $this->assertInstanceOf('Predis\Response\ObjectInterface', $status); + $this->assertSame('OK', $status->getPayload()); + } + + /** + * @group disconnected + */ + public function testStatusToString() + { + $queued = new Status('OK'); + + $this->assertSame('OK', (string) $queued); + $this->assertEquals('OK', $queued); + } + + /** + * @group disconnected + */ + public function testStaticGetMethod() + { + $this->assertInstanceOf('Predis\Response\Status', $response = Status::get('OK')); + $this->assertEquals('OK', $response); + + $this->assertInstanceOf('Predis\Response\Status', $response = Status::get('QUEUED')); + $this->assertEquals('QUEUED', $response); + + $this->assertInstanceOf('Predis\Response\Status', $response = Status::get('PONG')); + $this->assertEquals('PONG', $response); + } +} diff --git a/tests/Predis/Transaction/MultiExecTest.php b/tests/Predis/Transaction/MultiExecTest.php index 682a6572..a0a27094 100644 --- a/tests/Predis/Transaction/MultiExecTest.php +++ b/tests/Predis/Transaction/MultiExecTest.php @@ -498,7 +498,7 @@ class MultiExecTest extends PredisTestCase return $expected; default: - return new Response\StatusQueued(); + return new Response\Status('QUEUED'); } }); @@ -532,7 +532,7 @@ class MultiExecTest extends PredisTestCase return $expected; default: - return new Response\StatusQueued(); + return new Response\Status('QUEUED'); } }); @@ -558,7 +558,7 @@ class MultiExecTest extends PredisTestCase return new Response\Error('ERR simulated failure on EXEC'); default: - return new Response\StatusQueued(); + return new Response\Status('QUEUED'); } }); @@ -629,8 +629,8 @@ class MultiExecTest extends PredisTestCase $tx->echo('foobar'); }); - $this->assertTrue($replies[0]); - $this->assertInstanceOf('Predis\Response\ErrorInterface', $replies[1]); + $this->assertInstanceOf('Predis\Response\Status', $replies[0]); + $this->assertInstanceOf('Predis\Response\Error', $replies[1]); $this->assertSame('foobar', $replies[2]); } @@ -829,13 +829,13 @@ class MultiExecTest extends PredisTestCase $abort = true; } - return new Response\StatusQueued(); + return new Response\Status('QUEUED'); case 'UNWATCH': $watch = false; default: - return $multi ? new Response\StatusQueued() : 'DUMMY_REPLY'; + return $multi ? new Response\Status('QUEUED') : 'DUMMY_REPLY'; } }; }