From 116eaba75e1de4044d937954b747dfe73ca76ace Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Sun, 17 Feb 2013 14:48:37 +0100 Subject: [PATCH] Deprecate the whole Predis\Helpers class. --- CHANGELOG.md | 3 ++ lib/Predis/Command/AbstractCommand.php | 30 ++++++++++++++++++ lib/Predis/Command/HashDelete.php | 4 +-- lib/Predis/Command/HashGetMultiple.php | 4 +-- lib/Predis/Command/KeyDelete.php | 4 +-- lib/Predis/Command/ListPushTail.php | 4 +-- lib/Predis/Command/PubSubSubscribe.php | 4 +-- .../Command/PubSubSubscribeByPattern.php | 2 -- lib/Predis/Command/PubSubUnsubscribe.php | 4 +-- lib/Predis/Command/ServerObject.php | 2 -- lib/Predis/Command/SetAdd.php | 4 +-- lib/Predis/Command/SetIntersection.php | 4 +-- lib/Predis/Command/SetRemove.php | 4 +-- lib/Predis/Command/StringGetMultiple.php | 4 +-- lib/Predis/Command/ZSetAdd.php | 2 -- lib/Predis/Command/ZSetRemove.php | 4 +-- lib/Predis/CommunicationException.php | 19 ++++++++++++ lib/Predis/Connection/AbstractConnection.php | 6 ++-- lib/Predis/Helpers.php | 4 +++ lib/Predis/Pipeline/PipelineContext.php | 1 - .../Protocol/Text/ResponseBulkHandler.php | 4 +-- .../Protocol/Text/ResponseIntegerHandler.php | 4 +-- .../Text/ResponseMultiBulkHandler.php | 4 +-- .../Text/ResponseMultiBulkStreamHandler.php | 4 +-- lib/Predis/Protocol/Text/TextProtocol.php | 4 +-- .../Protocol/Text/TextResponseReader.php | 4 +-- lib/Predis/PubSub/AbstractPubSubContext.php | 1 - lib/Predis/PubSub/PubSubContext.php | 4 +-- lib/Predis/Transaction/MultiExecContext.php | 3 +- tests/Predis/Command/CommandTest.php | 31 +++++++++++++++++++ tests/Predis/CommunicationExceptionTest.php | 16 ++++++++++ 31 files changed, 132 insertions(+), 60 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 88192a39..4cc9f3d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,9 @@ v0.8.3 (2013-xx-xx) instead of `FALSE` to indicate that all of the arguments of a Lua script must be used to populate `ARGV[]`. This does not represent a breaking change. +- The `Predis\Helpers` class has been deprecated and it will be removed in + future releases. + v0.8.2 (2013-02-03) =============================================================================== diff --git a/lib/Predis/Command/AbstractCommand.php b/lib/Predis/Command/AbstractCommand.php index 5a62c9f2..0584a9b2 100644 --- a/lib/Predis/Command/AbstractCommand.php +++ b/lib/Predis/Command/AbstractCommand.php @@ -129,4 +129,34 @@ abstract class AbstractCommand implements CommandInterface $this->getId() ); } + + /** + * Normalizes the arguments array passed to a Redis command. + * + * @param array $arguments Arguments for a command. + * @return array + */ + public static function normalizeArguments(Array $arguments) + { + if (count($arguments) === 1 && is_array($arguments[0])) { + return $arguments[0]; + } + + return $arguments; + } + + /** + * Normalizes the arguments array passed to a variadic Redis command. + * + * @param array $arguments Arguments for a command. + * @return array + */ + public static function normalizeVariadic(Array $arguments) + { + if (count($arguments) === 2 && is_array($arguments[1])) { + return array_merge(array($arguments[0]), $arguments[1]); + } + + return $arguments; + } } diff --git a/lib/Predis/Command/HashDelete.php b/lib/Predis/Command/HashDelete.php index ae726bbc..95846786 100644 --- a/lib/Predis/Command/HashDelete.php +++ b/lib/Predis/Command/HashDelete.php @@ -11,8 +11,6 @@ namespace Predis\Command; -use Predis\Helpers; - /** * @link http://redis.io/commands/hdel * @author Daniele Alessandri @@ -32,6 +30,6 @@ class HashDelete extends PrefixableCommand */ protected function filterArguments(Array $arguments) { - return Helpers::filterVariadicValues($arguments); + return self::normalizeVariadic($arguments); } } diff --git a/lib/Predis/Command/HashGetMultiple.php b/lib/Predis/Command/HashGetMultiple.php index 722721b9..d5334898 100644 --- a/lib/Predis/Command/HashGetMultiple.php +++ b/lib/Predis/Command/HashGetMultiple.php @@ -11,8 +11,6 @@ namespace Predis\Command; -use Predis\Helpers; - /** * @link http://redis.io/commands/hmget * @author Daniele Alessandri @@ -32,6 +30,6 @@ class HashGetMultiple extends PrefixableCommand */ protected function filterArguments(Array $arguments) { - return Helpers::filterVariadicValues($arguments); + return self::normalizeVariadic($arguments); } } diff --git a/lib/Predis/Command/KeyDelete.php b/lib/Predis/Command/KeyDelete.php index d6967848..4e43141c 100644 --- a/lib/Predis/Command/KeyDelete.php +++ b/lib/Predis/Command/KeyDelete.php @@ -11,8 +11,6 @@ namespace Predis\Command; -use Predis\Helpers; - /** * @link http://redis.io/commands/del * @author Daniele Alessandri @@ -32,7 +30,7 @@ class KeyDelete extends AbstractCommand implements PrefixableCommandInterface */ protected function filterArguments(Array $arguments) { - return Helpers::filterArrayArguments($arguments); + return self::normalizeArguments($arguments); } /** diff --git a/lib/Predis/Command/ListPushTail.php b/lib/Predis/Command/ListPushTail.php index 5c71aeb4..6a0f2e0b 100644 --- a/lib/Predis/Command/ListPushTail.php +++ b/lib/Predis/Command/ListPushTail.php @@ -11,8 +11,6 @@ namespace Predis\Command; -use Predis\Helpers; - /** * @link http://redis.io/commands/rpush * @author Daniele Alessandri @@ -32,6 +30,6 @@ class ListPushTail extends PrefixableCommand */ protected function filterArguments(Array $arguments) { - return Helpers::filterVariadicValues($arguments); + return self::normalizeVariadic($arguments); } } diff --git a/lib/Predis/Command/PubSubSubscribe.php b/lib/Predis/Command/PubSubSubscribe.php index bd7d7736..eb8be650 100644 --- a/lib/Predis/Command/PubSubSubscribe.php +++ b/lib/Predis/Command/PubSubSubscribe.php @@ -11,8 +11,6 @@ namespace Predis\Command; -use Predis\Helpers; - /** * @link http://redis.io/commands/subscribe * @author Daniele Alessandri @@ -32,7 +30,7 @@ class PubSubSubscribe extends AbstractCommand implements PrefixableCommandInterf */ protected function filterArguments(Array $arguments) { - return Helpers::filterArrayArguments($arguments); + return self::normalizeArguments($arguments); } /** diff --git a/lib/Predis/Command/PubSubSubscribeByPattern.php b/lib/Predis/Command/PubSubSubscribeByPattern.php index f58a6394..7629e6df 100644 --- a/lib/Predis/Command/PubSubSubscribeByPattern.php +++ b/lib/Predis/Command/PubSubSubscribeByPattern.php @@ -11,8 +11,6 @@ namespace Predis\Command; -use Predis\Helpers; - /** * @link http://redis.io/commands/psubscribe * @author Daniele Alessandri diff --git a/lib/Predis/Command/PubSubUnsubscribe.php b/lib/Predis/Command/PubSubUnsubscribe.php index 4bb6661e..ba70fe4d 100644 --- a/lib/Predis/Command/PubSubUnsubscribe.php +++ b/lib/Predis/Command/PubSubUnsubscribe.php @@ -11,8 +11,6 @@ namespace Predis\Command; -use Predis\Helpers; - /** * @link http://redis.io/commands/unsubscribe * @author Daniele Alessandri @@ -32,7 +30,7 @@ class PubSubUnsubscribe extends AbstractCommand implements PrefixableCommandInte */ protected function filterArguments(Array $arguments) { - return Helpers::filterArrayArguments($arguments); + return self::normalizeArguments($arguments); } /** diff --git a/lib/Predis/Command/ServerObject.php b/lib/Predis/Command/ServerObject.php index c344a4a8..989fbd77 100644 --- a/lib/Predis/Command/ServerObject.php +++ b/lib/Predis/Command/ServerObject.php @@ -11,8 +11,6 @@ namespace Predis\Command; -use Predis\Helpers; - /** * @link http://redis.io/commands/object * @author Daniele Alessandri diff --git a/lib/Predis/Command/SetAdd.php b/lib/Predis/Command/SetAdd.php index 1fc33012..f03e02bd 100644 --- a/lib/Predis/Command/SetAdd.php +++ b/lib/Predis/Command/SetAdd.php @@ -11,8 +11,6 @@ namespace Predis\Command; -use Predis\Helpers; - /** * @link http://redis.io/commands/sadd * @author Daniele Alessandri @@ -32,6 +30,6 @@ class SetAdd extends PrefixableCommand */ protected function filterArguments(Array $arguments) { - return Helpers::filterVariadicValues($arguments); + return self::normalizeVariadic($arguments); } } diff --git a/lib/Predis/Command/SetIntersection.php b/lib/Predis/Command/SetIntersection.php index 179473df..c6590d23 100644 --- a/lib/Predis/Command/SetIntersection.php +++ b/lib/Predis/Command/SetIntersection.php @@ -11,8 +11,6 @@ namespace Predis\Command; -use Predis\Helpers; - /** * @link http://redis.io/commands/sinter * @author Daniele Alessandri @@ -32,7 +30,7 @@ class SetIntersection extends AbstractCommand implements PrefixableCommandInterf */ protected function filterArguments(Array $arguments) { - return Helpers::filterArrayArguments($arguments); + return self::normalizeArguments($arguments); } /** diff --git a/lib/Predis/Command/SetRemove.php b/lib/Predis/Command/SetRemove.php index bae506f4..f7cb5772 100644 --- a/lib/Predis/Command/SetRemove.php +++ b/lib/Predis/Command/SetRemove.php @@ -11,8 +11,6 @@ namespace Predis\Command; -use Predis\Helpers; - /** * @link http://redis.io/commands/srem * @author Daniele Alessandri @@ -32,6 +30,6 @@ class SetRemove extends PrefixableCommand */ protected function filterArguments(Array $arguments) { - return Helpers::filterVariadicValues($arguments); + return self::normalizeVariadic($arguments); } } diff --git a/lib/Predis/Command/StringGetMultiple.php b/lib/Predis/Command/StringGetMultiple.php index 9a4646a9..71d91872 100644 --- a/lib/Predis/Command/StringGetMultiple.php +++ b/lib/Predis/Command/StringGetMultiple.php @@ -11,8 +11,6 @@ namespace Predis\Command; -use Predis\Helpers; - /** * @link http://redis.io/commands/mget * @author Daniele Alessandri @@ -32,7 +30,7 @@ class StringGetMultiple extends AbstractCommand implements PrefixableCommandInte */ protected function filterArguments(Array $arguments) { - return Helpers::filterArrayArguments($arguments); + return self::normalizeArguments($arguments); } /** diff --git a/lib/Predis/Command/ZSetAdd.php b/lib/Predis/Command/ZSetAdd.php index 569351a4..e0b1c53b 100644 --- a/lib/Predis/Command/ZSetAdd.php +++ b/lib/Predis/Command/ZSetAdd.php @@ -11,8 +11,6 @@ namespace Predis\Command; -use Predis\Helpers; - /** * @link http://redis.io/commands/zadd * @author Daniele Alessandri diff --git a/lib/Predis/Command/ZSetRemove.php b/lib/Predis/Command/ZSetRemove.php index 0917df45..ae7208d8 100644 --- a/lib/Predis/Command/ZSetRemove.php +++ b/lib/Predis/Command/ZSetRemove.php @@ -11,8 +11,6 @@ namespace Predis\Command; -use Predis\Helpers; - /** * @link http://redis.io/commands/zrem * @author Daniele Alessandri @@ -32,6 +30,6 @@ class ZSetRemove extends PrefixableCommand */ protected function filterArguments(Array $arguments) { - return Helpers::filterVariadicValues($arguments); + return self::normalizeVariadic($arguments); } } diff --git a/lib/Predis/CommunicationException.php b/lib/Predis/CommunicationException.php index f4b8687d..c9e75e23 100644 --- a/lib/Predis/CommunicationException.php +++ b/lib/Predis/CommunicationException.php @@ -54,4 +54,23 @@ abstract class CommunicationException extends PredisException { return true; } + + /** + * Offers a generic and reusable method to handle exceptions generated by + * a connection object. + * + * @param CommunicationException $exception Exception. + */ + public static function handle(CommunicationException $exception) + { + if ($exception->shouldResetConnection()) { + $connection = $exception->getConnection(); + + if ($connection->isConnected()) { + $connection->disconnect(); + } + } + + throw $exception; + } } diff --git a/lib/Predis/Connection/AbstractConnection.php b/lib/Predis/Connection/AbstractConnection.php index eac4a277..e37aede2 100644 --- a/lib/Predis/Connection/AbstractConnection.php +++ b/lib/Predis/Connection/AbstractConnection.php @@ -12,7 +12,7 @@ namespace Predis\Connection; use Predis\ClientException; -use Predis\Helpers; +use Predis\CommunicationException; use Predis\NotSupportedException; use Predis\Command\CommandInterface; use Predis\Protocol\ProtocolException; @@ -136,7 +136,7 @@ abstract class AbstractConnection implements SingleConnectionInterface */ protected function onConnectionError($message, $code = null) { - Helpers::onCommunicationException(new ConnectionException($this, $message, $code)); + CommunicationException::handle(new ConnectionException($this, $message, $code)); } /** @@ -146,7 +146,7 @@ abstract class AbstractConnection implements SingleConnectionInterface */ protected function onProtocolError($message) { - Helpers::onCommunicationException(new ProtocolException($this, $message)); + CommunicationException::handle(new ProtocolException($this, $message)); } /** diff --git a/lib/Predis/Helpers.php b/lib/Predis/Helpers.php index 4e06cd98..162e961e 100644 --- a/lib/Predis/Helpers.php +++ b/lib/Predis/Helpers.php @@ -19,6 +19,7 @@ use Predis\Connection\ConnectionInterface; * Defines a few helper methods. * * @author Daniele Alessandri + * @deprecated Deprecated since v0.8.3. */ class Helpers { @@ -26,6 +27,7 @@ class Helpers * Offers a generic and reusable method to handle exceptions generated by * a connection object. * + * @deprecated Deprecated since v0.8.3 - moved in Predis\CommunicationException::handle() * @param CommunicationException $exception Exception. */ public static function onCommunicationException(CommunicationException $exception) @@ -44,6 +46,7 @@ class Helpers /** * Normalizes the arguments array passed to a Redis command. * + * @deprecated Deprecated since v0.8.3 - moved in Predis\Command\AbstractCommand::normalizeArguments() * @param array $arguments Arguments for a command. * @return array */ @@ -59,6 +62,7 @@ class Helpers /** * Normalizes the arguments array passed to a variadic Redis command. * + * @deprecated Deprecated since v0.8.3 - moved in Predis\Command\AbstractCommand::normalizeVariadic() * @param array $arguments Arguments for a command. * @return array */ diff --git a/lib/Predis/Pipeline/PipelineContext.php b/lib/Predis/Pipeline/PipelineContext.php index 33dedd24..d26535a5 100644 --- a/lib/Predis/Pipeline/PipelineContext.php +++ b/lib/Predis/Pipeline/PipelineContext.php @@ -16,7 +16,6 @@ use Predis\BasicClientInterface; use Predis\ClientException; use Predis\ClientInterface; use Predis\ExecutableContextInterface; -use Predis\Helpers; use Predis\Command\CommandInterface; /** diff --git a/lib/Predis/Protocol/Text/ResponseBulkHandler.php b/lib/Predis/Protocol/Text/ResponseBulkHandler.php index 3360c5bd..7b9a9650 100644 --- a/lib/Predis/Protocol/Text/ResponseBulkHandler.php +++ b/lib/Predis/Protocol/Text/ResponseBulkHandler.php @@ -11,7 +11,7 @@ namespace Predis\Protocol\Text; -use Predis\Helpers; +use Predis\CommunicationException; use Predis\Connection\ComposableConnectionInterface; use Predis\Protocol\ProtocolException; use Predis\Protocol\ResponseHandlerInterface; @@ -37,7 +37,7 @@ class ResponseBulkHandler implements ResponseHandlerInterface $length = (int) $lengthString; if ("$length" !== $lengthString) { - Helpers::onCommunicationException(new ProtocolException( + CommunicationException::handle(new ProtocolException( $connection, "Cannot parse '$lengthString' as bulk length" )); } diff --git a/lib/Predis/Protocol/Text/ResponseIntegerHandler.php b/lib/Predis/Protocol/Text/ResponseIntegerHandler.php index 146ffb52..36556f33 100644 --- a/lib/Predis/Protocol/Text/ResponseIntegerHandler.php +++ b/lib/Predis/Protocol/Text/ResponseIntegerHandler.php @@ -11,7 +11,7 @@ namespace Predis\Protocol\Text; -use Predis\Helpers; +use Predis\CommunicationException; use Predis\Connection\ComposableConnectionInterface; use Predis\Protocol\ProtocolException; use Predis\Protocol\ResponseHandlerInterface; @@ -39,7 +39,7 @@ class ResponseIntegerHandler implements ResponseHandlerInterface } if ($number !== 'nil') { - Helpers::onCommunicationException(new ProtocolException( + CommunicationException::handle(new ProtocolException( $connection, "Cannot parse '$number' as numeric response" )); } diff --git a/lib/Predis/Protocol/Text/ResponseMultiBulkHandler.php b/lib/Predis/Protocol/Text/ResponseMultiBulkHandler.php index 366baf3b..2f31f321 100644 --- a/lib/Predis/Protocol/Text/ResponseMultiBulkHandler.php +++ b/lib/Predis/Protocol/Text/ResponseMultiBulkHandler.php @@ -11,7 +11,7 @@ namespace Predis\Protocol\Text; -use Predis\Helpers; +use Predis\CommunicationException; use Predis\Connection\ComposableConnectionInterface; use Predis\Protocol\ProtocolException; use Predis\Protocol\ResponseHandlerInterface; @@ -37,7 +37,7 @@ class ResponseMultiBulkHandler implements ResponseHandlerInterface $length = (int) $lengthString; if ("$length" !== $lengthString) { - Helpers::onCommunicationException(new ProtocolException( + CommunicationException::handle(new ProtocolException( $connection, "Cannot parse '$lengthString' as multi-bulk length" )); } diff --git a/lib/Predis/Protocol/Text/ResponseMultiBulkStreamHandler.php b/lib/Predis/Protocol/Text/ResponseMultiBulkStreamHandler.php index 3d2dd5ec..77bc19f6 100644 --- a/lib/Predis/Protocol/Text/ResponseMultiBulkStreamHandler.php +++ b/lib/Predis/Protocol/Text/ResponseMultiBulkStreamHandler.php @@ -11,7 +11,7 @@ namespace Predis\Protocol\Text; -use Predis\Helpers; +use Predis\CommunicationException; use Predis\Connection\ComposableConnectionInterface; use Predis\Iterator\MultiBulkResponseSimple; use Predis\Protocol\ProtocolException; @@ -38,7 +38,7 @@ class ResponseMultiBulkStreamHandler implements ResponseHandlerInterface $length = (int) $lengthString; if ("$length" != $lengthString) { - Helpers::onCommunicationException(new ProtocolException( + CommunicationException::handle(new ProtocolException( $connection, "Cannot parse '$lengthString' as multi-bulk length" )); } diff --git a/lib/Predis/Protocol/Text/TextProtocol.php b/lib/Predis/Protocol/Text/TextProtocol.php index 616d62ae..25a251a7 100644 --- a/lib/Predis/Protocol/Text/TextProtocol.php +++ b/lib/Predis/Protocol/Text/TextProtocol.php @@ -11,7 +11,7 @@ namespace Predis\Protocol\Text; -use Predis\Helpers; +use Predis\CommunicationException; use Predis\ResponseError; use Predis\ResponseQueued; use Predis\ServerException; @@ -117,7 +117,7 @@ class TextProtocol implements ProtocolInterface return new ResponseError($payload); default: - Helpers::onCommunicationException(new ProtocolException( + CommunicationException::handle(new ProtocolException( $connection, "Unknown prefix: '$prefix'" )); } diff --git a/lib/Predis/Protocol/Text/TextResponseReader.php b/lib/Predis/Protocol/Text/TextResponseReader.php index bda21b21..5364a219 100644 --- a/lib/Predis/Protocol/Text/TextResponseReader.php +++ b/lib/Predis/Protocol/Text/TextResponseReader.php @@ -11,7 +11,7 @@ namespace Predis\Protocol\Text; -use Predis\Helpers; +use Predis\CommunicationException; use Predis\Connection\ComposableConnectionInterface; use Predis\Protocol\ProtocolException; use Predis\Protocol\ResponseHandlerInterface; @@ -108,6 +108,6 @@ class TextResponseReader implements ResponseReaderInterface */ private function protocolError(ComposableConnectionInterface $connection, $message) { - Helpers::onCommunicationException(new ProtocolException($connection, $message)); + CommunicationException::handle(new ProtocolException($connection, $message)); } } diff --git a/lib/Predis/PubSub/AbstractPubSubContext.php b/lib/Predis/PubSub/AbstractPubSubContext.php index a9930971..29126b0a 100644 --- a/lib/Predis/PubSub/AbstractPubSubContext.php +++ b/lib/Predis/PubSub/AbstractPubSubContext.php @@ -13,7 +13,6 @@ namespace Predis\PubSub; use Predis\ClientException; use Predis\ClientInterface; -use Predis\Helpers; use Predis\NotSupportedException; /** diff --git a/lib/Predis/PubSub/PubSubContext.php b/lib/Predis/PubSub/PubSubContext.php index 6f53af37..910459b6 100644 --- a/lib/Predis/PubSub/PubSubContext.php +++ b/lib/Predis/PubSub/PubSubContext.php @@ -13,7 +13,7 @@ namespace Predis\PubSub; use Predis\ClientException; use Predis\ClientInterface; -use Predis\Helpers; +use Predis\Command\AbstractCommand as Command; use Predis\NotSupportedException; use Predis\Connection\AggregatedConnectionInterface; @@ -77,7 +77,7 @@ class PubSubContext extends AbstractPubSubContext */ protected function writeCommand($method, $arguments) { - $arguments = Helpers::filterArrayArguments($arguments); + $arguments = Command::normalizeArguments($arguments); $command = $this->client->createCommand($method, $arguments); $this->client->getConnection()->writeCommand($command); } diff --git a/lib/Predis/Transaction/MultiExecContext.php b/lib/Predis/Transaction/MultiExecContext.php index bc5b2082..b5d08332 100644 --- a/lib/Predis/Transaction/MultiExecContext.php +++ b/lib/Predis/Transaction/MultiExecContext.php @@ -17,7 +17,6 @@ use Predis\ClientException; use Predis\ClientInterface; use Predis\CommunicationException; use Predis\ExecutableContextInterface; -use Predis\Helpers; use Predis\NotSupportedException; use Predis\ResponseErrorInterface; use Predis\ResponseQueued; @@ -443,7 +442,7 @@ class MultiExecContext implements BasicClientInterface, ExecutableContextInterfa // Since a MULTI/EXEC block cannot be initialized when using aggregated // connections, we can safely assume that Predis\Client::getConnection() // will always return an instance of Predis\Connection\SingleConnectionInterface. - Helpers::onCommunicationException(new ProtocolException( + CommunicationException::handle(new ProtocolException( $this->client->getConnection(), $message )); } diff --git a/tests/Predis/Command/CommandTest.php b/tests/Predis/Command/CommandTest.php index a27d29d0..7cb3f884 100644 --- a/tests/Predis/Command/CommandTest.php +++ b/tests/Predis/Command/CommandTest.php @@ -140,4 +140,35 @@ class CommandTest extends StandardTestCase $this->assertEquals($expected, (string) $command); } + + /** + * @group disconnected + */ + public function testNormalizeArguments() + { + $arguments = array('arg1', 'arg2', 'arg3', 'arg4'); + + $this->assertSame($arguments, AbstractCommand::normalizeArguments($arguments)); + $this->assertSame($arguments, AbstractCommand::normalizeArguments(array($arguments))); + + $arguments = array(array(), array()); + $this->assertSame($arguments, AbstractCommand::normalizeArguments($arguments)); + + $arguments = array(new \stdClass()); + $this->assertSame($arguments, AbstractCommand::normalizeArguments($arguments)); + } + + /** + * @group disconnected + */ + public function testNormalizeVariadic() + { + $arguments = array('key', 'value1', 'value2', 'value3'); + + $this->assertSame($arguments, AbstractCommand::normalizeVariadic($arguments)); + $this->assertSame($arguments, AbstractCommand::normalizeVariadic(array('key', array('value1', 'value2', 'value3')))); + + $arguments = array(new \stdClass()); + $this->assertSame($arguments, AbstractCommand::normalizeVariadic($arguments)); + } } diff --git a/tests/Predis/CommunicationExceptionTest.php b/tests/Predis/CommunicationExceptionTest.php index 36ae11f0..b4c2ccde 100644 --- a/tests/Predis/CommunicationExceptionTest.php +++ b/tests/Predis/CommunicationExceptionTest.php @@ -56,6 +56,22 @@ class CommunicationExceptionTest extends StandardTestCase $this->assertTrue($exception->shouldResetConnection()); } + /** + * @group disconnected + * @expectedException Predis\CommunicationException + * @expectedExceptionMessage Communication error + */ + public function testCommunicationExceptionHandling() + { + $connection = $this->getMock('Predis\Connection\SingleConnectionInterface'); + $connection->expects($this->once())->method('isConnected')->will($this->returnValue(true)); + $connection->expects($this->once())->method('disconnect'); + + $exception = $this->getException($connection, 'Communication error'); + + CommunicationException::handle($exception); + } + // ******************************************************************** // // ---- HELPER METHODS ------------------------------------------------ // // ******************************************************************** //