Explorar el Código

[tests] Change indentation of mock method expectations.

Daniele Alessandri hace 8 años
padre
commit
eb1e686ff9
Se han modificado 49 ficheros con 3255 adiciones y 2361 borrados
  1. 14 10
      tests/PHPUnit/PredisConnectionTestCase.php
  2. 8 6
      tests/PHPUnit/PredisTestCase.php
  3. 190 146
      tests/Predis/ClientTest.php
  4. 5 4
      tests/Predis/Cluster/Distributor/HashRingTest.php
  5. 5 4
      tests/Predis/Cluster/Distributor/KetamaRingTest.php
  6. 13 10
      tests/Predis/Cluster/PredisStrategyTest.php
  7. 13 10
      tests/Predis/Cluster/RedisStrategyTest.php
  8. 200 172
      tests/Predis/Collection/Iterator/HashKeyTest.php
  9. 187 130
      tests/Predis/Collection/Iterator/KeyspaceTest.php
  10. 92 66
      tests/Predis/Collection/Iterator/ListKeyTest.php
  11. 189 130
      tests/Predis/Collection/Iterator/SetKeyTest.php
  12. 200 172
      tests/Predis/Collection/Iterator/SortedSetKeyTest.php
  13. 12 8
      tests/Predis/Command/RedisFactoryTest.php
  14. 82 75
      tests/Predis/Command/ScriptCommandTest.php
  15. 10 8
      tests/Predis/Configuration/Option/AggregateTest.php
  16. 21 17
      tests/Predis/Configuration/Option/ClusterTest.php
  17. 29 20
      tests/Predis/Configuration/Option/CommandsTest.php
  18. 30 23
      tests/Predis/Configuration/Option/ConnectionsTest.php
  19. 16 12
      tests/Predis/Configuration/Option/PrefixTest.php
  20. 32 26
      tests/Predis/Configuration/Option/ReplicationTest.php
  21. 18 13
      tests/Predis/Configuration/OptionsTest.php
  22. 66 22
      tests/Predis/Connection/Cluster/PredisClusterTest.php
  23. 390 264
      tests/Predis/Connection/Cluster/RedisClusterTest.php
  24. 11 10
      tests/Predis/Connection/CompositeStreamConnectionTest.php
  25. 44 29
      tests/Predis/Connection/FactoryTest.php
  26. 11 10
      tests/Predis/Connection/PhpiredisSocketConnectionTest.php
  27. 11 10
      tests/Predis/Connection/PhpiredisStreamConnectionTest.php
  28. 337 162
      tests/Predis/Connection/Replication/MasterSlaveReplicationTest.php
  29. 449 367
      tests/Predis/Connection/Replication/SentinelReplicationTest.php
  30. 11 10
      tests/Predis/Connection/StreamConnectionTest.php
  31. 34 22
      tests/Predis/Monitor/ConsumerTest.php
  32. 40 29
      tests/Predis/Pipeline/AtomicTest.php
  33. 15 8
      tests/Predis/Pipeline/FireAndForgetTest.php
  34. 84 53
      tests/Predis/Pipeline/PipelineTest.php
  35. 16 17
      tests/Predis/Protocol/Text/CompositeProtocolProcessorTest.php
  36. 39 26
      tests/Predis/Protocol/Text/Handler/BulkResponseTest.php
  37. 8 5
      tests/Predis/Protocol/Text/Handler/ErrorResponseTest.php
  38. 21 12
      tests/Predis/Protocol/Text/Handler/IntegerResponseTest.php
  39. 35 29
      tests/Predis/Protocol/Text/Handler/MultiBulkResponseTest.php
  40. 21 15
      tests/Predis/Protocol/Text/Handler/StatusResponseTest.php
  41. 14 8
      tests/Predis/Protocol/Text/Handler/StreamableMultiBulkResponseTest.php
  42. 40 40
      tests/Predis/Protocol/Text/ProtocolProcessorTest.php
  43. 24 24
      tests/Predis/Protocol/Text/RequestSerializerTest.php
  44. 31 35
      tests/Predis/Protocol/Text/ResponseReaderTest.php
  45. 49 23
      tests/Predis/PubSub/ConsumerTest.php
  46. 26 22
      tests/Predis/PubSub/DispatcherLoopTest.php
  47. 20 15
      tests/Predis/Replication/ReplicationStrategyTest.php
  48. 2 0
      tests/Predis/Response/Iterator/MultiBulkTupleTest.php
  49. 40 32
      tests/Predis/Transaction/MultiExecTest.php

+ 14 - 10
tests/PHPUnit/PredisConnectionTestCase.php

@@ -273,8 +273,9 @@ abstract class PredisConnectionTestCase extends PredisTestCase
 
         $cmdEcho = $this->getMock($commands->getCommandClass('echo'), array('parseResponse'));
         $cmdEcho->setArguments(array('ECHOED'));
-        $cmdEcho->expects($this->never())
-                ->method('parseResponse');
+        $cmdEcho
+            ->expects($this->never())
+            ->method('parseResponse');
 
         $connection = $this->createConnection();
         $connection->writeRequest($cmdEcho);
@@ -290,8 +291,9 @@ abstract class PredisConnectionTestCase extends PredisTestCase
 
         $cmdEcho = $this->getMock($commands->getCommandClass('echo'), array('parseResponse'));
         $cmdEcho->setArguments(array('ECHOED'));
-        $cmdEcho->expects($this->never())
-                ->method('parseResponse');
+        $cmdEcho
+            ->expects($this->never())
+            ->method('parseResponse');
 
         $connection = $this->createConnection();
         $connection->writeRequest($cmdEcho);
@@ -332,14 +334,16 @@ abstract class PredisConnectionTestCase extends PredisTestCase
         $commands = $this->getCommandFactory();
 
         $cmdPing = $this->getMock($commands->getCommandClass('ping'), array('getArguments'));
-        $cmdPing->expects($this->once())
-                ->method('getArguments')
-                ->will($this->returnValue(array()));
+        $cmdPing
+            ->expects($this->once())
+            ->method('getArguments')
+            ->will($this->returnValue(array()));
 
         $cmdEcho = $this->getMock($commands->getCommandClass('echo'), array('getArguments'));
-        $cmdEcho->expects($this->once())
-                ->method('getArguments')
-                ->will($this->returnValue(array('ECHOED')));
+        $cmdEcho
+            ->expects($this->once())
+            ->method('getArguments')
+            ->will($this->returnValue(array('ECHOED')));
 
         $connection = $this->createConnection();
         $connection->addConnectCommand($cmdPing);

+ 8 - 6
tests/PHPUnit/PredisTestCase.php

@@ -202,12 +202,14 @@ abstract class PredisTestCase extends \PHPUnit_Framework_TestCase
             $parameters = Connection\Parameters::create($parameters);
             $hash = "{$parameters->host}:{$parameters->port}";
 
-            $connection->expects($this->any())
-                       ->method('getParameters')
-                       ->will($this->returnValue($parameters));
-            $connection->expects($this->any())
-                       ->method('__toString')
-                       ->will($this->returnValue($hash));
+            $connection
+                ->expects($this->any())
+                ->method('getParameters')
+                ->will($this->returnValue($parameters));
+            $connection
+                ->expects($this->any())
+                ->method('__toString')
+                ->will($this->returnValue($hash));
         }
 
         return $connection;

+ 190 - 146
tests/Predis/ClientTest.php

@@ -223,10 +223,11 @@ class ClientTest extends PredisTestCase
         $connection = $this->getMock('Predis\Connection\ConnectionInterface');
 
         $callable = $this->getMock('stdClass', array('__invoke'));
-        $callable->expects($this->once())
-                 ->method('__invoke')
-                 ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
-                 ->will($this->returnValue($connection));
+        $callable
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
+            ->will($this->returnValue($connection));
 
         $client = new Client($callable);
 
@@ -243,10 +244,11 @@ class ClientTest extends PredisTestCase
         $wrongType = $this->getMock('stdClass');
 
         $callable = $this->getMock('stdClass', array('__invoke'));
-        $callable->expects($this->once())
-                 ->method('__invoke')
-                 ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
-                 ->will($this->returnValue($wrongType));
+        $callable
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
+            ->will($this->returnValue($wrongType));
 
         new Client($callable);
     }
@@ -290,16 +292,21 @@ class ClientTest extends PredisTestCase
         $connection = $this->getMock('Predis\Connection\AggregateConnectionInterface');
 
         $fncluster = $this->getMock('stdClass', array('__invoke'));
-        $fncluster->expects($this->once())
-                  ->method('__invoke')
-                  ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'), $arg1)
-                  ->will($this->returnValue($connection));
+        $fncluster
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'), $arg1)
+            ->will($this->returnValue($connection));
 
         $fnreplication = $this->getMock('stdClass', array('__invoke'));
-        $fnreplication->expects($this->never())->method('__invoke');
+        $fnreplication
+            ->expects($this->never())
+            ->method('__invoke');
 
         $fnaggregate = $this->getMock('stdClass', array('__invoke'));
-        $fnaggregate->expects($this->never())->method('__invoke');
+        $fnaggregate
+            ->expects($this->never())
+            ->method('__invoke');
 
         $arg2 = array(
             'cluster' => $fncluster,
@@ -322,10 +329,11 @@ class ClientTest extends PredisTestCase
         $connection = $this->getMock('Predis\Connection\AggregateConnectionInterface');
 
         $fnreplication = $this->getMock('stdClass', array('__invoke'));
-        $fnreplication->expects($this->once())
-                      ->method('__invoke')
-                      ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'), $arg1)
-                      ->will($this->returnValue($connection));
+        $fnreplication
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'), $arg1)
+            ->will($this->returnValue($connection));
 
         $fnaggregate = $this->getMock('stdClass', array('__invoke'));
         $fnaggregate->expects($this->never())->method('__invoke');
@@ -350,14 +358,16 @@ class ClientTest extends PredisTestCase
         $connection = $this->getMock('Predis\Connection\AggregateConnectionInterface');
 
         $fnaggregate = $this->getMock('stdClass', array('__invoke'));
-        $fnaggregate->expects($this->once())
-                    ->method('__invoke')
-                    ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'), $arg1)
-                    ->will($this->returnValue($connection));
+        $fnaggregate
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'), $arg1)
+            ->will($this->returnValue($connection));
 
         $connections = $this->getMock('Predis\Connection\FactoryInterface');
-        $connections->expects($this->never())
-                    ->method('aggregate');
+        $connections
+            ->expects($this->never())
+            ->method('aggregate');
 
         $arg2 = array('aggregate' => $fnaggregate, 'connections' => $connections);
 
@@ -392,8 +402,12 @@ class ClientTest extends PredisTestCase
     public function testConnectAndDisconnect()
     {
         $connection = $this->getMock('Predis\Connection\ConnectionInterface');
-        $connection->expects($this->once())->method('connect');
-        $connection->expects($this->once())->method('disconnect');
+        $connection
+            ->expects($this->once())
+            ->method('connect');
+        $connection
+            ->expects($this->once())
+            ->method('disconnect');
 
         $client = new Client($connection);
         $client->connect();
@@ -406,7 +420,9 @@ class ClientTest extends PredisTestCase
     public function testIsConnectedChecksConnectionState()
     {
         $connection = $this->getMock('Predis\Connection\ConnectionInterface');
-        $connection->expects($this->once())->method('isConnected');
+        $connection
+            ->expects($this->once())
+            ->method('isConnected');
 
         $client = new Client($connection);
         $client->isConnected();
@@ -418,7 +434,9 @@ class ClientTest extends PredisTestCase
     public function testQuitIsAliasForDisconnect()
     {
         $connection = $this->getMock('Predis\Connection\ConnectionInterface');
-        $connection->expects($this->once())->method('disconnect');
+        $connection
+            ->expects($this->once())
+            ->method('disconnect');
 
         $client = new Client($connection);
         $client->quit();
@@ -432,10 +450,11 @@ class ClientTest extends PredisTestCase
         $ping = $this->getCommandFactory()->createCommand('ping', array());
 
         $commands = $this->getMock('Predis\Command\FactoryInterface');
-        $commands->expects($this->once())
-                 ->method('createCommand')
-                 ->with('ping', array())
-                 ->will($this->returnValue($ping));
+        $commands
+            ->expects($this->once())
+            ->method('createCommand')
+            ->with('ping', array())
+            ->will($this->returnValue($ping));
 
         $client = new Client(null, array('commands' => $commands));
         $this->assertSame($ping, $client->createCommand('ping', array()));
@@ -452,14 +471,16 @@ class ClientTest extends PredisTestCase
         $hgetall = $commands->createCommand('hgetall', array('metavars', 'foo', 'hoge'));
 
         $connection = $this->getMock('Predis\Connection\ConnectionInterface');
-        $connection->expects($this->at(0))
-                   ->method('executeCommand')
-                   ->with($ping)
-                   ->will($this->returnValue(new Response\Status('PONG')));
-        $connection->expects($this->at(1))
-                   ->method('executeCommand')
-                   ->with($hgetall)
-                   ->will($this->returnValue(array('foo', 'bar', 'hoge', 'piyo')));
+        $connection
+            ->expects($this->at(0))
+            ->method('executeCommand')
+            ->with($ping)
+            ->will($this->returnValue(new Response\Status('PONG')));
+        $connection
+            ->expects($this->at(1))
+            ->method('executeCommand')
+            ->with($hgetall)
+            ->will($this->returnValue(array('foo', 'bar', 'hoge', 'piyo')));
 
         $client = new Client($connection);
 
@@ -478,9 +499,10 @@ class ClientTest extends PredisTestCase
         $expectedResponse = new Response\Error('ERR Operation against a key holding the wrong kind of value');
 
         $connection = $this->getMock('Predis\Connection\ConnectionInterface');
-        $connection->expects($this->once())
-                   ->method('executeCommand')
-                   ->will($this->returnValue($expectedResponse));
+        $connection
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->will($this->returnValue($expectedResponse));
 
         $client = new Client($connection);
         $client->executeCommand($ping);
@@ -495,9 +517,10 @@ class ClientTest extends PredisTestCase
         $expectedResponse = new Response\Error('ERR Operation against a key holding the wrong kind of value');
 
         $connection = $this->getMock('Predis\Connection\ConnectionInterface');
-        $connection->expects($this->once())
-                   ->method('executeCommand')
-                   ->will($this->returnValue($expectedResponse));
+        $connection
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->will($this->returnValue($expectedResponse));
 
         $client = new Client($connection, array('exceptions' => false));
         $response = $client->executeCommand($ping);
@@ -513,16 +536,18 @@ class ClientTest extends PredisTestCase
         $ping = $this->getCommandFactory()->createCommand('ping', array());
 
         $connection = $this->getMock('Predis\Connection\ConnectionInterface');
-        $connection->expects($this->once())
-                   ->method('executeCommand')
-                   ->with($this->isInstanceOf('Predis\Command\Redis\PING'))
-                   ->will($this->returnValue('PONG'));
+        $connection
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($this->isInstanceOf('Predis\Command\Redis\PING'))
+            ->will($this->returnValue('PONG'));
 
         $commands = $this->getMock('Predis\Command\FactoryInterface');
-        $commands->expects($this->once())
-                 ->method('createCommand')
-                 ->with('ping', array())
-                 ->will($this->returnValue($ping));
+        $commands
+            ->expects($this->once())
+            ->method('createCommand')
+            ->with('ping', array())
+            ->will($this->returnValue($ping));
 
         $options = array('commands' => $commands);
         $client = $this->getMock('Predis\Client', null, array($connection, $options));
@@ -540,10 +565,11 @@ class ClientTest extends PredisTestCase
         $expectedResponse = new Response\Error('ERR Operation against a key holding the wrong kind of value');
 
         $connection = $this->getMock('Predis\Connection\ConnectionInterface');
-        $connection->expects($this->once())
-                   ->method('executeCommand')
-                   ->with($this->isRedisCommand('PING'))
-                   ->will($this->returnValue($expectedResponse));
+        $connection
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($this->isRedisCommand('PING'))
+            ->will($this->returnValue($expectedResponse));
 
         $client = new Client($connection);
         $client->ping();
@@ -557,10 +583,11 @@ class ClientTest extends PredisTestCase
         $expectedResponse = new Response\Error('ERR Operation against a key holding the wrong kind of value');
 
         $connection = $this->getMock('Predis\Connection\ConnectionInterface');
-        $connection->expects($this->once())
-                   ->method('executeCommand')
-                   ->with($this->isRedisCommand('PING'))
-                   ->will($this->returnValue($expectedResponse));
+        $connection
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($this->isRedisCommand('PING'))
+            ->will($this->returnValue($expectedResponse));
 
         $client = new Client($connection, array('exceptions' => false));
         $response = $client->ping();
@@ -574,18 +601,21 @@ class ClientTest extends PredisTestCase
     public function testRawCommand()
     {
         $connection = $this->getMock('Predis\Connection\ConnectionInterface');
-        $connection->expects($this->at(0))
-                   ->method('executeCommand')
-                   ->with($this->isRedisCommand('SET', array('foo', 'bar')))
-                   ->will($this->returnValue(new Response\Status('OK')));
-        $connection->expects($this->at(1))
-                   ->method('executeCommand')
-                   ->with($this->isRedisCommand('GET', array('foo')))
-                   ->will($this->returnValue('bar'));
-        $connection->expects($this->at(2))
-                   ->method('executeCommand')
-                   ->with($this->isRedisCommand('PING'))
-                   ->will($this->returnValue('PONG'));
+        $connection
+            ->expects($this->at(0))
+            ->method('executeCommand')
+            ->with($this->isRedisCommand('SET', array('foo', 'bar')))
+            ->will($this->returnValue(new Response\Status('OK')));
+        $connection
+            ->expects($this->at(1))
+            ->method('executeCommand')
+            ->with($this->isRedisCommand('GET', array('foo')))
+            ->will($this->returnValue('bar'));
+        $connection
+            ->expects($this->at(2))
+            ->method('executeCommand')
+            ->with($this->isRedisCommand('PING'))
+            ->will($this->returnValue('PONG'));
 
         $client = new Client($connection);
 
@@ -603,14 +633,16 @@ class ClientTest extends PredisTestCase
     public function testRawCommandNeverAppliesPrefix()
     {
         $connection = $this->getMock('Predis\Connection\ConnectionInterface');
-        $connection->expects($this->at(0))
-                   ->method('executeCommand')
-                   ->with($this->isRedisCommand('SET', array('foo', 'bar')))
-                   ->will($this->returnValue(new Response\Status('OK')));
-        $connection->expects($this->at(1))
-                   ->method('executeCommand')
-                   ->with($this->isRedisCommand('GET', array('foo')))
-                   ->will($this->returnValue('bar'));
+        $connection
+            ->expects($this->at(0))
+            ->method('executeCommand')
+            ->with($this->isRedisCommand('SET', array('foo', 'bar')))
+            ->will($this->returnValue(new Response\Status('OK')));
+        $connection
+            ->expects($this->at(1))
+            ->method('executeCommand')
+            ->with($this->isRedisCommand('GET', array('foo')))
+            ->will($this->returnValue('bar'));
 
         $client = new Client($connection, array('prefix' => 'predis:'));
 
@@ -627,10 +659,11 @@ class ClientTest extends PredisTestCase
         $response = new Response\Error($message);
 
         $connection = $this->getMock('Predis\Connection\ConnectionInterface');
-        $connection->expects($this->once())
-                   ->method('executeCommand')
-                   ->with($this->isRedisCommand('PING'))
-                   ->will($this->returnValue($response));
+        $connection
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($this->isRedisCommand('PING'))
+            ->will($this->returnValue($response));
 
         $client = new Client($connection, array('exceptions' => true));
 
@@ -714,17 +747,18 @@ class ClientTest extends PredisTestCase
         $client = new Client(array('tcp://host1?alias=node01', 'tcp://host2?alias=node02'), array('cluster' => 'predis'));
 
         $callable = $this->getMock('stdClass', array('__invoke'));
-        $callable->expects($this->once())
-                 ->method('__invoke')
-                 ->with($this->callback(function ($clientNode) use ($test, $client) {
-                     $test->isInstanceOf('Predis\ClientInterface', $clientNode);
-                     $test->assertNotSame($client, $clientNode);
-                     $test->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $connection = $clientNode->getConnection());
-                     $test->assertSame('node02', $connection->getParameters()->alias);
-
-                     return true;
-                 }))
-                 ->will($this->returnValue('value'));
+        $callable
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($this->callback(function ($clientNode) use ($test, $client) {
+                $test->isInstanceOf('Predis\ClientInterface', $clientNode);
+                $test->assertNotSame($client, $clientNode);
+                $test->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $connection = $clientNode->getConnection());
+                $test->assertSame('node02', $connection->getParameters()->alias);
+
+                return true;
+            }))
+            ->will($this->returnValue('value'));
 
         $this->assertSame('value', $client->on('node02', $callable));
     }
@@ -781,9 +815,10 @@ class ClientTest extends PredisTestCase
     public function testPipelineWithCallableExecutesPipeline()
     {
         $callable = $this->getMock('stdClass', array('__invoke'));
-        $callable->expects($this->once())
-                 ->method('__invoke')
-                 ->with($this->isInstanceOf('Predis\Pipeline\Pipeline'));
+        $callable
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($this->isInstanceOf('Predis\Pipeline\Pipeline'));
 
         $client = new Client();
         $client->pipeline($callable);
@@ -826,13 +861,15 @@ class ClientTest extends PredisTestCase
         //       the context and forcing it to be closed since there are no more
         //       active subscriptions.
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->once())
-                   ->method('read')
-                   ->will($this->returnValue(array('subscribe', 'channel', 0)));
+        $connection
+            ->expects($this->once())
+            ->method('read')
+            ->will($this->returnValue(array('subscribe', 'channel', 0)));
 
         $callable = $this->getMock('stdClass', array('__invoke'));
-        $callable->expects($this->once())
-                 ->method('__invoke');
+        $callable
+            ->expects($this->once())
+            ->method('__invoke');
 
         $client = new Client($connection);
         $this->assertNull($client->pubSubLoop(array('subscribe' => 'channel'), $callable));
@@ -844,20 +881,24 @@ class ClientTest extends PredisTestCase
     public function testPubSubLoopWithCallableReturningFalseStopsPubSubConsumer()
     {
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->at(1))
-                   ->method('read')
-                   ->will($this->returnValue(array('subscribe', 'channel', 1)));
-        $connection->expects($this->at(2))
-                   ->method('writeRequest')
-                   ->with($this->isRedisCommand('UNSUBSCRIBE'));
-        $connection->expects($this->at(3))
-                   ->method('read')
-                   ->will($this->returnValue(array('unsubscribe', 'channel', 0)));
+        $connection
+            ->expects($this->at(1))
+            ->method('read')
+            ->will($this->returnValue(array('subscribe', 'channel', 1)));
+        $connection
+            ->expects($this->at(2))
+            ->method('writeRequest')
+            ->with($this->isRedisCommand('UNSUBSCRIBE'));
+        $connection
+            ->expects($this->at(3))
+            ->method('read')
+            ->will($this->returnValue(array('unsubscribe', 'channel', 0)));
 
         $callable = $this->getMock('stdClass', array('__invoke'));
-        $callable->expects($this->at(0))
-                 ->method('__invoke')
-                 ->will($this->returnValue(false));
+        $callable
+            ->expects($this->at(0))
+            ->method('__invoke')
+            ->will($this->returnValue(false));
 
         $client = new Client($connection);
 
@@ -904,18 +945,16 @@ class ClientTest extends PredisTestCase
         $options = array('cas' => true, 'retry' => 3);
 
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->once())
-                   ->method('executeCommand')
-                   ->will($this->returnValue(new Response\Status('QUEUED')));
-
-        $txCallback = function ($tx) {
-            $tx->ping();
-        };
+        $connection
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->will($this->returnValue(new Response\Status('QUEUED')));
 
         $callable = $this->getMock('stdClass', array('__invoke'));
-        $callable->expects($this->once())
-                 ->method('__invoke')
-                 ->will($this->returnCallback($txCallback));
+        $callable
+            ->expects($this->once())
+            ->method('__invoke')
+            ->will($this->returnCallback(function ($tx) { $tx->ping(); }));
 
         $client = new Client($connection);
         $client->transaction($options, $callable);
@@ -938,23 +977,27 @@ class ClientTest extends PredisTestCase
     public function testClientResendScriptCommandUsingEvalOnNoScriptErrors()
     {
         $command = $this->getMockForAbstractClass('Predis\Command\ScriptCommand', array(), '', true, true, true, array('parseResponse'));
-        $command->expects($this->once())
-                ->method('getScript')
-                ->will($this->returnValue('return redis.call(\'exists\', KEYS[1])'));
-        $command->expects($this->once())
-                ->method('parseResponse')
-                ->with('OK')
-                ->will($this->returnValue(true));
+        $command
+            ->expects($this->once())
+            ->method('getScript')
+            ->will($this->returnValue('return redis.call(\'exists\', KEYS[1])'));
+        $command
+            ->expects($this->once())
+            ->method('parseResponse')
+            ->with('OK')
+            ->will($this->returnValue(true));
 
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->at(0))
-                   ->method('executeCommand')
-                   ->with($command)
-                   ->will($this->returnValue(new Response\Error('NOSCRIPT')));
-        $connection->expects($this->at(1))
-                   ->method('executeCommand')
-                   ->with($this->isRedisCommand('EVAL'))
-                   ->will($this->returnValue('OK'));
+        $connection
+            ->expects($this->at(0))
+            ->method('executeCommand')
+            ->with($command)
+            ->will($this->returnValue(new Response\Error('NOSCRIPT')));
+        $connection
+            ->expects($this->at(1))
+            ->method('executeCommand')
+            ->with($this->isRedisCommand('EVAL'))
+            ->will($this->returnValue('OK'));
 
         $client = new Client($connection);
 
@@ -1051,10 +1094,11 @@ class ClientTest extends PredisTestCase
         $connection = $this->getMock('Predis\Connection\AggregateConnectionInterface');
 
         $callable = $this->getMock('stdClass', array('__invoke'));
-        $callable->expects($this->once())
-                 ->method('__invoke')
-                 ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'), $parameters)
-                 ->will($this->returnValue($connection));
+        $callable
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'), $parameters)
+            ->will($this->returnValue($connection));
 
         return $callable;
     }

+ 5 - 4
tests/Predis/Cluster/Distributor/HashRingTest.php

@@ -197,10 +197,11 @@ class HashRingTest extends PredisDistributorTestCase
         $node = '127.0.0.1:7000';
         $callable = $this->getMock('stdClass', array('__invoke'));
 
-        $callable->expects($this->once())
-                 ->method('__invoke')
-                 ->with($node)
-                 ->will($this->returnValue($node));
+        $callable
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($node)
+            ->will($this->returnValue($node));
 
         $distributor = new HashRing(HashRing::DEFAULT_REPLICAS, $callable);
         $distributor->add($node);

+ 5 - 4
tests/Predis/Cluster/Distributor/KetamaRingTest.php

@@ -198,10 +198,11 @@ class KetamaRingTest extends PredisDistributorTestCase
         $node = '127.0.0.1:7000';
         $callable = $this->getMock('stdClass', array('__invoke'));
 
-        $callable->expects($this->once())
-                 ->method('__invoke')
-                 ->with($node)
-                 ->will($this->returnValue($node));
+        $callable
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($node)
+            ->will($this->returnValue($node));
 
         $distributor = new KetamaRing($callable);
         $distributor->add($node);

+ 13 - 10
tests/Predis/Cluster/PredisStrategyTest.php

@@ -225,12 +225,14 @@ class PredisStrategyTest extends PredisTestCase
         $arguments = array('{key}:1', '{key}:2', 'value1', 'value2');
 
         $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount'));
-        $command->expects($this->once())
-                ->method('getScript')
-                ->will($this->returnValue('return true'));
-        $command->expects($this->exactly(2))
-                ->method('getKeysCount')
-                ->will($this->returnValue(2));
+        $command
+            ->expects($this->once())
+            ->method('getScript')
+            ->will($this->returnValue('return true'));
+        $command
+            ->expects($this->exactly(2))
+            ->method('getKeysCount')
+            ->will($this->returnValue(2));
         $command->setArguments($arguments);
 
         $this->assertNotNull($strategy->getSlot($command), "Script Command [{$command->getId()}]");
@@ -263,10 +265,11 @@ class PredisStrategyTest extends PredisTestCase
         $commands = $this->getCommandFactory();
 
         $callable = $this->getMock('stdClass', array('__invoke'));
-        $callable->expects($this->once())
-                 ->method('__invoke')
-                 ->with($this->isInstanceOf('Predis\Command\CommandInterface'))
-                 ->will($this->returnValue('key'));
+        $callable
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($this->isInstanceOf('Predis\Command\CommandInterface'))
+            ->will($this->returnValue('key'));
 
         $strategy->setCommandHandler('get', $callable);
 

+ 13 - 10
tests/Predis/Cluster/RedisStrategyTest.php

@@ -240,12 +240,14 @@ class RedisStrategyTest extends PredisTestCase
         $arguments = array('key:1', 'value1');
 
         $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount'));
-        $command->expects($this->once())
-                ->method('getScript')
-                ->will($this->returnValue('return true'));
-        $command->expects($this->exactly(2))
-                ->method('getKeysCount')
-                ->will($this->returnValue(1));
+        $command
+            ->expects($this->once())
+            ->method('getScript')
+            ->will($this->returnValue('return true'));
+        $command
+            ->expects($this->exactly(2))
+            ->method('getKeysCount')
+            ->will($this->returnValue(1));
         $command->setArguments($arguments);
 
         $this->assertNotNull($strategy->getSlot($command), "Script Command [{$command->getId()}]");
@@ -278,10 +280,11 @@ class RedisStrategyTest extends PredisTestCase
         $commands = $this->getCommandFactory();
 
         $callable = $this->getMock('stdClass', array('__invoke'));
-        $callable->expects($this->once())
-                 ->method('__invoke')
-                 ->with($this->isInstanceOf('Predis\Command\CommandInterface'))
-                 ->will($this->returnValue('key'));
+        $callable
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($this->isInstanceOf('Predis\Command\CommandInterface'))
+            ->will($this->returnValue('key'));
 
         $strategy->setCommandHandler('get', $callable);
 

+ 200 - 172
tests/Predis/Collection/Iterator/HashKeyTest.php

@@ -26,14 +26,16 @@ class HashKeyTest extends PredisTestCase
     public function testThrowsExceptionOnMissingCommand()
     {
         $commands = $this->getMock('Predis\Command\FactoryInterface');
-        $commands->expects($this->any())
-                 ->method('supportsCommand')
-                 ->will($this->returnValue(false));
+        $commands
+            ->expects($this->any())
+            ->method('supportsCommand')
+            ->will($this->returnValue(false));
 
         $client = $this->getMock('Predis\ClientInterface');
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($commands));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($commands));
 
         new HashKey($client, 'key:hash');
     }
@@ -44,14 +46,17 @@ class HashKeyTest extends PredisTestCase
     public function testIterationWithNoResults()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->once())
-               ->method('hscan')
-               ->with('key:hash', 0, array())
-               ->will($this->returnValue(array(0, array())));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->once())
+            ->method('hscan')
+            ->with('key:hash', 0, array())
+            ->will($this->returnValue(
+                array(0, array()
+            )));
 
         $iterator = new HashKey($client, 'key:hash');
 
@@ -67,16 +72,17 @@ class HashKeyTest extends PredisTestCase
     public function testIterationWithIntegerFields()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->once())
-               ->method('hscan')
-               ->with('key:hash', 0, array())
-               ->will($this->returnValue(array(0, array(
-                    1 => 'a', 2 => 'b', 3 => 100, 'foo' => 'bar',
-               ))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->once())
+            ->method('hscan')
+            ->with('key:hash', 0, array())
+            ->will($this->returnValue(
+                array(0, array(1 => 'a', 2 => 'b', 3 => 100, 'foo' => 'bar'))
+            ));
 
         $iterator = new HashKey($client, 'key:hash');
 
@@ -110,16 +116,17 @@ class HashKeyTest extends PredisTestCase
     public function testIterationOnSingleFetch()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->once())
-               ->method('hscan')
-               ->with('key:hash', 0, array())
-               ->will($this->returnValue(array(0, array(
-                    'field:1st' => 'value:1st', 'field:2nd' => 'value:2nd', 'field:3rd' => 'value:3rd',
-               ))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->once())
+            ->method('hscan')
+            ->with('key:hash', 0, array())
+            ->will($this->returnValue(
+                array(0, array('field:1st' => 'value:1st', 'field:2nd' => 'value:2nd', 'field:3rd' => 'value:3rd'))
+            ));
 
         $iterator = new HashKey($client, 'key:hash');
 
@@ -148,22 +155,24 @@ class HashKeyTest extends PredisTestCase
     public function testIterationOnMultipleFetches()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('hscan')
-               ->with('key:hash', 0, array())
-               ->will($this->returnValue(array(2, array(
-                    'field:1st' => 'value:1st', 'field:2nd' => 'value:2nd',
-               ))));
-        $client->expects($this->at(2))
-               ->method('hscan')
-               ->with('key:hash', 2, array())
-               ->will($this->returnValue(array(0, array(
-                    'field:3rd' => 'value:3rd',
-               ))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('hscan')
+            ->with('key:hash', 0, array())
+            ->will($this->returnValue(
+                array(2, array('field:1st' => 'value:1st', 'field:2nd' => 'value:2nd'))
+            ));
+        $client
+            ->expects($this->at(2))
+            ->method('hscan')
+            ->with('key:hash', 2, array())
+            ->will($this->returnValue(
+                array(0, array('field:3rd' => 'value:3rd'))
+            ));
 
         $iterator = new HashKey($client, 'key:hash');
 
@@ -192,20 +201,24 @@ class HashKeyTest extends PredisTestCase
     public function testIterationOnMultipleFetchesAndHoleInFirstFetch()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('hscan')
-               ->with('key:hash', 0, array())
-               ->will($this->returnValue(array(4, array())));
-        $client->expects($this->at(2))
-               ->method('hscan')
-               ->with('key:hash', 4, array())
-               ->will($this->returnValue(array(0, array(
-                    'field:1st' => 'value:1st', 'field:2nd' => 'value:2nd',
-               ))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('hscan')
+            ->with('key:hash', 0, array())
+            ->will($this->returnValue(
+                array(4, array())
+            ));
+        $client
+            ->expects($this->at(2))
+            ->method('hscan')
+            ->with('key:hash', 4, array())
+            ->will($this->returnValue(
+                array(0, array('field:1st' => 'value:1st', 'field:2nd' => 'value:2nd'))
+            ));
 
         $iterator = new HashKey($client, 'key:hash');
 
@@ -229,26 +242,31 @@ class HashKeyTest extends PredisTestCase
     public function testIterationOnMultipleFetchesAndHoleInMidFetch()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('hscan')
-               ->with('key:hash', 0, array())
-               ->will($this->returnValue(array(2, array(
-                    'field:1st' => 'value:1st', 'field:2nd' => 'value:2nd',
-               ))));
-        $client->expects($this->at(2))
-               ->method('hscan')
-               ->with('key:hash', 2, array())
-               ->will($this->returnValue(array(5, array())));
-        $client->expects($this->at(3))
-               ->method('hscan')
-               ->with('key:hash', 5, array())
-               ->will($this->returnValue(array(0, array(
-                    'field:3rd' => 'value:3rd',
-               ))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('hscan')
+            ->with('key:hash', 0, array())
+            ->will($this->returnValue(
+                array(2, array('field:1st' => 'value:1st', 'field:2nd' => 'value:2nd'))
+            ));
+        $client
+            ->expects($this->at(2))
+            ->method('hscan')
+            ->with('key:hash', 2, array())
+            ->will($this->returnValue(
+                array(5, array())
+            ));
+        $client
+            ->expects($this->at(3))
+            ->method('hscan')
+            ->with('key:hash', 5, array())
+            ->will($this->returnValue(
+                array(0, array('field:3rd' => 'value:3rd'))
+            ));
 
         $iterator = new HashKey($client, 'key:hash');
 
@@ -277,16 +295,17 @@ class HashKeyTest extends PredisTestCase
     public function testIterationWithOptionMatch()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('hscan')
-               ->with('key:hash', 0, array('MATCH' => 'field:*'))
-               ->will($this->returnValue(array(2, array(
-                    'field:1st' => 'value:1st', 'field:2nd' => 'value:2nd',
-               ))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('hscan')
+            ->with('key:hash', 0, array('MATCH' => 'field:*'))
+            ->will($this->returnValue(
+                array(2, array('field:1st' => 'value:1st', 'field:2nd' => 'value:2nd'))
+            ));
 
         $iterator = new HashKey($client, 'key:hash', 'field:*');
 
@@ -310,22 +329,24 @@ class HashKeyTest extends PredisTestCase
     public function testIterationWithOptionMatchOnMultipleFetches()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('hscan')
-               ->with('key:hash', 0, array('MATCH' => 'field:*'))
-               ->will($this->returnValue(array(1, array(
-                    'field:1st' => 'value:1st',
-                ))));
-        $client->expects($this->at(2))
-               ->method('hscan')
-               ->with('key:hash', 1, array('MATCH' => 'field:*'))
-               ->will($this->returnValue(array(0, array(
-                    'field:2nd' => 'value:2nd',
-                ))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('hscan')
+            ->with('key:hash', 0, array('MATCH' => 'field:*'))
+            ->will($this->returnValue(
+                array(1, array('field:1st' => 'value:1st'))
+            ));
+        $client
+            ->expects($this->at(2))
+            ->method('hscan')
+            ->with('key:hash', 1, array('MATCH' => 'field:*'))
+            ->will($this->returnValue(
+                array(0, array('field:2nd' => 'value:2nd'))
+            ));
 
         $iterator = new HashKey($client, 'key:hash', 'field:*');
 
@@ -349,16 +370,17 @@ class HashKeyTest extends PredisTestCase
     public function testIterationWithOptionCount()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('hscan')
-               ->with('key:hash', 0, array('COUNT' => 2))
-               ->will($this->returnValue(array(0, array(
-                    'field:1st' => 'value:1st', 'field:2nd' => 'value:2nd',
-               ))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('hscan')
+            ->with('key:hash', 0, array('COUNT' => 2))
+            ->will($this->returnValue(
+                array(0, array('field:1st' => 'value:1st', 'field:2nd' => 'value:2nd'))
+            ));
 
         $iterator = new HashKey($client, 'key:hash', null, 2);
 
@@ -382,22 +404,24 @@ class HashKeyTest extends PredisTestCase
     public function testIterationWithOptionCountOnMultipleFetches()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('hscan')
-               ->with('key:hash', 0, array('COUNT' => 1))
-               ->will($this->returnValue(array(1, array(
-                    'field:1st' => 'value:1st',
-                ))));
-        $client->expects($this->at(2))
-               ->method('hscan')
-               ->with('key:hash', 1, array('COUNT' => 1))
-               ->will($this->returnValue(array(0, array(
-                    'field:2nd' => 'value:2nd',
-                ))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('hscan')
+            ->with('key:hash', 0, array('COUNT' => 1))
+            ->will($this->returnValue(
+                array(1, array('field:1st' => 'value:1st'))
+            ));
+        $client
+            ->expects($this->at(2))
+            ->method('hscan')
+            ->with('key:hash', 1, array('COUNT' => 1))
+            ->will($this->returnValue(
+                array(0, array('field:2nd' => 'value:2nd'))
+            ));
 
         $iterator = new HashKey($client, 'key:hash', null, 1);
 
@@ -421,16 +445,17 @@ class HashKeyTest extends PredisTestCase
     public function testIterationWithOptionsMatchAndCount()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('hscan')
-               ->with('key:hash', 0, array('MATCH' => 'field:*', 'COUNT' => 2))
-               ->will($this->returnValue(array(0, array(
-                    'field:1st' => 'value:1st', 'field:2nd' => 'value:2nd',
-               ))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('hscan')
+            ->with('key:hash', 0, array('MATCH' => 'field:*', 'COUNT' => 2))
+            ->will($this->returnValue(
+                array(0, array('field:1st' => 'value:1st', 'field:2nd' => 'value:2nd'))
+            ));
 
         $iterator = new HashKey($client, 'key:hash', 'field:*', 2);
 
@@ -454,22 +479,24 @@ class HashKeyTest extends PredisTestCase
     public function testIterationWithOptionsMatchAndCountOnMultipleFetches()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('hscan')
-               ->with('key:hash', 0, array('MATCH' => 'field:*', 'COUNT' => 1))
-               ->will($this->returnValue(array(1, array(
-                    'field:1st' => 'value:1st',
-                ))));
-        $client->expects($this->at(2))
-               ->method('hscan')
-               ->with('key:hash', 1, array('MATCH' => 'field:*', 'COUNT' => 1))
-               ->will($this->returnValue(array(0, array(
-                    'field:2nd' => 'value:2nd',
-                ))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('hscan')
+            ->with('key:hash', 0, array('MATCH' => 'field:*', 'COUNT' => 1))
+            ->will($this->returnValue(
+                array(1, array('field:1st' => 'value:1st'))
+            ));
+        $client
+            ->expects($this->at(2))
+            ->method('hscan')
+            ->with('key:hash', 1, array('MATCH' => 'field:*', 'COUNT' => 1))
+            ->will($this->returnValue(
+                array(0, array('field:2nd' => 'value:2nd'))
+            ));
 
         $iterator = new HashKey($client, 'key:hash', 'field:*', 1);
 
@@ -493,16 +520,17 @@ class HashKeyTest extends PredisTestCase
     public function testIterationRewindable()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'hscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->exactly(2))
-               ->method('hscan')
-               ->with('key:hash', 0, array())
-               ->will($this->returnValue(array(0, array(
-                    'field:1st' => 'value:1st', 'field:2nd' => 'value:2nd',
-               ))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->exactly(2))
+            ->method('hscan')
+            ->with('key:hash', 0, array())
+            ->will($this->returnValue(
+                array(0, array('field:1st' => 'value:1st', 'field:2nd' => 'value:2nd'))
+            ));
 
         $iterator = new HashKey($client, 'key:hash');
 

+ 187 - 130
tests/Predis/Collection/Iterator/KeyspaceTest.php

@@ -26,14 +26,16 @@ class KeyspaceTest extends PredisTestCase
     public function testThrowsExceptionOnMissingCommand()
     {
         $commands = $this->getMock('Predis\Command\FactoryInterface');
-        $commands->expects($this->any())
-                 ->method('supportsCommand')
-                 ->will($this->returnValue(false));
+        $commands
+            ->expects($this->any())
+            ->method('supportsCommand')
+            ->will($this->returnValue(false));
 
         $client = $this->getMock('Predis\ClientInterface');
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($commands));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($commands));
 
         new Keyspace($client);
     }
@@ -44,14 +46,17 @@ class KeyspaceTest extends PredisTestCase
     public function testIterationWithNoResults()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'scan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->once())
-               ->method('scan')
-               ->with(0, array())
-               ->will($this->returnValue(array(0, array())));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->once())
+            ->method('scan')
+            ->with(0, array())
+            ->will($this->returnValue(
+                array(0, array())
+            ));
 
         $iterator = new Keyspace($client);
 
@@ -65,14 +70,17 @@ class KeyspaceTest extends PredisTestCase
     public function testIterationOnSingleFetch()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'scan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->once())
-               ->method('scan')
-               ->with(0, array())
-               ->will($this->returnValue(array(0, array('key:1st', 'key:2nd', 'key:3rd'))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->once())
+            ->method('scan')
+            ->with(0, array())
+            ->will($this->returnValue(
+                array(0, array('key:1st', 'key:2nd', 'key:3rd'))
+            ));
 
         $iterator = new Keyspace($client);
 
@@ -101,18 +109,24 @@ class KeyspaceTest extends PredisTestCase
     public function testIterationOnMultipleFetches()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'scan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('scan')
-               ->with(0, array())
-               ->will($this->returnValue(array(2, array('key:1st', 'key:2nd'))));
-        $client->expects($this->at(2))
-               ->method('scan')
-               ->with(2, array())
-               ->will($this->returnValue(array(0, array('key:3rd'))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('scan')
+            ->with(0, array())
+            ->will($this->returnValue(
+                array(2, array('key:1st', 'key:2nd'))
+            ));
+        $client
+            ->expects($this->at(2))
+            ->method('scan')
+            ->with(2, array())
+            ->will($this->returnValue(
+                array(0, array('key:3rd'))
+            ));
 
         $iterator = new Keyspace($client);
 
@@ -141,18 +155,24 @@ class KeyspaceTest extends PredisTestCase
     public function testIterationOnMultipleFetchesAndHoleInFirstFetch()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'scan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('scan')
-               ->with(0, array())
-               ->will($this->returnValue(array(4, array())));
-        $client->expects($this->at(2))
-               ->method('scan')
-               ->with(4, array())
-               ->will($this->returnValue(array(0, array('key:1st', 'key:2nd'))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('scan')
+            ->with(0, array())
+            ->will($this->returnValue(
+                array(4, array())
+            ));
+        $client
+            ->expects($this->at(2))
+            ->method('scan')
+            ->with(4, array())
+            ->will($this->returnValue(
+                array(0, array('key:1st', 'key:2nd'))
+            ));
 
         $iterator = new Keyspace($client);
 
@@ -176,22 +196,31 @@ class KeyspaceTest extends PredisTestCase
     public function testIterationOnMultipleFetchesAndHoleInMidFetch()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'scan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('scan')
-               ->with(0, array())
-               ->will($this->returnValue(array(2, array('key:1st', 'key:2nd'))));
-        $client->expects($this->at(2))
-               ->method('scan')
-               ->with(2, array())
-               ->will($this->returnValue(array(5, array())));
-        $client->expects($this->at(3))
-               ->method('scan')
-               ->with(5, array())
-               ->will($this->returnValue(array(0, array('key:3rd'))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('scan')
+            ->with(0, array())
+            ->will($this->returnValue(
+                array(2, array('key:1st', 'key:2nd'))
+            ));
+        $client
+            ->expects($this->at(2))
+            ->method('scan')
+            ->with(2, array())
+            ->will($this->returnValue(
+                array(5, array())
+            ));
+        $client
+            ->expects($this->at(3))
+            ->method('scan')
+            ->with(5, array())
+            ->will($this->returnValue(
+                array(0, array('key:3rd'))
+            ));
 
         $iterator = new Keyspace($client);
 
@@ -220,14 +249,17 @@ class KeyspaceTest extends PredisTestCase
     public function testIterationWithOptionMatch()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'scan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('scan')
-               ->with(0, array('MATCH' => 'key:*'))
-               ->will($this->returnValue(array(0, array('key:1st', 'key:2nd'))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('scan')
+            ->with(0, array('MATCH' => 'key:*'))
+            ->will($this->returnValue(
+                array(0, array('key:1st', 'key:2nd'))
+            ));
 
         $iterator = new Keyspace($client, 'key:*');
 
@@ -251,18 +283,24 @@ class KeyspaceTest extends PredisTestCase
     public function testIterationWithOptionMatchOnMultipleFetches()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'scan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('scan')
-               ->with(0, array('MATCH' => 'key:*'))
-               ->will($this->returnValue(array(1, array('key:1st'))));
-        $client->expects($this->at(2))
-               ->method('scan')
-               ->with(1, array('MATCH' => 'key:*'))
-               ->will($this->returnValue(array(0, array('key:2nd'))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('scan')
+            ->with(0, array('MATCH' => 'key:*'))
+            ->will($this->returnValue(
+                array(1, array('key:1st'))
+            ));
+        $client
+            ->expects($this->at(2))
+            ->method('scan')
+            ->with(1, array('MATCH' => 'key:*'))
+            ->will($this->returnValue(
+                array(0, array('key:2nd'))
+            ));
 
         $iterator = new Keyspace($client, 'key:*');
 
@@ -286,14 +324,17 @@ class KeyspaceTest extends PredisTestCase
     public function testIterationWithOptionCount()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'scan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('scan')
-               ->with(0, array('COUNT' => 2))
-               ->will($this->returnValue(array(0, array('key:1st', 'key:2nd'))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('scan')
+            ->with(0, array('COUNT' => 2))
+            ->will($this->returnValue(
+                array(0, array('key:1st', 'key:2nd'))
+            ));
 
         $iterator = new Keyspace($client, null, 2);
 
@@ -317,18 +358,22 @@ class KeyspaceTest extends PredisTestCase
     public function testIterationWithOptionCountOnMultipleFetches()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'scan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('scan')
-               ->with(0, array('COUNT' => 1))
-               ->will($this->returnValue(array(1, array('key:1st'))));
-        $client->expects($this->at(2))
-               ->method('scan')
-               ->with(1, array('COUNT' => 1))
-               ->will($this->returnValue(array(0, array('key:2nd'))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('scan')
+            ->with(0, array('COUNT' => 1))
+            ->will($this->returnValue(array(1, array('key:1st'))));
+        $client
+            ->expects($this->at(2))
+            ->method('scan')
+            ->with(1, array('COUNT' => 1))
+            ->will($this->returnValue(
+                array(0, array('key:2nd'))
+            ));
 
         $iterator = new Keyspace($client, null, 1);
 
@@ -352,14 +397,17 @@ class KeyspaceTest extends PredisTestCase
     public function testIterationWithOptionsMatchAndCount()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'scan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('scan')
-               ->with(0, array('MATCH' => 'key:*', 'COUNT' => 2))
-               ->will($this->returnValue(array(0, array('key:1st', 'key:2nd'))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('scan')
+            ->with(0, array('MATCH' => 'key:*', 'COUNT' => 2))
+            ->will($this->returnValue(
+                array(0, array('key:1st', 'key:2nd'))
+            ));
 
         $iterator = new Keyspace($client, 'key:*', 2);
 
@@ -383,18 +431,24 @@ class KeyspaceTest extends PredisTestCase
     public function testIterationWithOptionsMatchAndCountOnMultipleFetches()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'scan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('scan')
-               ->with(0, array('MATCH' => 'key:*', 'COUNT' => 1))
-               ->will($this->returnValue(array(1, array('key:1st'))));
-        $client->expects($this->at(2))
-               ->method('scan')
-               ->with(1, array('MATCH' => 'key:*', 'COUNT' => 1))
-               ->will($this->returnValue(array(0, array('key:2nd'))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('scan')
+            ->with(0, array('MATCH' => 'key:*', 'COUNT' => 1))
+            ->will($this->returnValue(
+                array(1, array('key:1st'))
+            ));
+        $client
+            ->expects($this->at(2))
+            ->method('scan')
+            ->with(1, array('MATCH' => 'key:*', 'COUNT' => 1))
+            ->will($this->returnValue(
+                array(0, array('key:2nd'))
+            ));
 
         $iterator = new Keyspace($client, 'key:*', 1);
 
@@ -418,14 +472,17 @@ class KeyspaceTest extends PredisTestCase
     public function testIterationRewindable()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'scan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->exactly(2))
-               ->method('scan')
-               ->with(0, array())
-               ->will($this->returnValue(array(0, array('key:1st', 'key:2nd'))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->exactly(2))
+            ->method('scan')
+            ->with(0, array())
+            ->will($this->returnValue(
+                array(0, array('key:1st', 'key:2nd'))
+            ));
 
         $iterator = new Keyspace($client);
 

+ 92 - 66
tests/Predis/Collection/Iterator/ListKeyTest.php

@@ -26,14 +26,16 @@ class ListKeyTest extends PredisTestCase
     public function testThrowsExceptionOnMissingCommand()
     {
         $commands = $this->getMock('Predis\Command\FactoryInterface');
-        $commands->expects($this->any())
-                 ->method('supportsCommand')
-                 ->will($this->returnValue(false));
+        $commands
+            ->expects($this->any())
+            ->method('supportsCommand')
+            ->will($this->returnValue(false));
 
         $client = $this->getMock('Predis\ClientInterface');
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($commands));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($commands));
 
         new ListKey($client, 'key:list');
     }
@@ -44,14 +46,17 @@ class ListKeyTest extends PredisTestCase
     public function testIterationWithNoResults()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'lrange'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->once())
-               ->method('lrange')
-               ->with('key:list', 0, 9)
-               ->will($this->returnValue(array()));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->once())
+            ->method('lrange')
+            ->with('key:list', 0, 9)
+            ->will($this->returnValue(
+                array()
+            ));
 
         $iterator = new ListKey($client, 'key:list');
 
@@ -65,14 +70,17 @@ class ListKeyTest extends PredisTestCase
     public function testIterationOnSingleFetch()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'lrange'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->once())
-               ->method('lrange')
-               ->with('key:list', 0, 9)
-               ->will($this->returnValue(array('item:1', 'item:2', 'item:3')));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->once())
+            ->method('lrange')
+            ->with('key:list', 0, 9)
+            ->will($this->returnValue(
+                array('item:1', 'item:2', 'item:3')
+            ));
 
         $iterator = new ListKey($client, 'key:list');
 
@@ -101,16 +109,20 @@ class ListKeyTest extends PredisTestCase
     public function testIterationOnMultipleFetches()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'lrange'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('lrange')
-               ->with('key:list', 0, 9)
-               ->will($this->returnValue(array(
-                    'item:1', 'item:2', 'item:3', 'item:4', 'item:5', 'item:6', 'item:7', 'item:8', 'item:9', 'item:10',
-               )));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('lrange')
+            ->with('key:list', 0, 9)
+            ->will($this->returnValue(
+                array(
+                    'item:1', 'item:2', 'item:3', 'item:4', 'item:5',
+                    'item:6', 'item:7', 'item:8', 'item:9', 'item:10',
+                )
+            ));
         $client->expects($this->at(2))
                ->method('lrange')
                ->with('key:list', 10, 19)
@@ -135,9 +147,10 @@ class ListKeyTest extends PredisTestCase
     public function testThrowsExceptionOnConstructorWithNonIntegerCountParameter()
     {
         $client = $this->getMock('Predis\ClientInterface');
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
 
         new ListKey($client, 'key:list', 'wrong');
     }
@@ -150,9 +163,10 @@ class ListKeyTest extends PredisTestCase
     public function testThrowsExceptionOnConstructorWithNegativeCountParameter()
     {
         $client = $this->getMock('Predis\ClientInterface');
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
 
         new ListKey($client, 'key:list', 'wrong');
     }
@@ -163,14 +177,17 @@ class ListKeyTest extends PredisTestCase
     public function testIterationWithCountParameter()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'lrange'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('lrange')
-               ->with('key:list', 0, 4)
-               ->will($this->returnValue(array('item:1', 'item:2')));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('lrange')
+            ->with('key:list', 0, 4)
+            ->will($this->returnValue(
+                array('item:1', 'item:2')
+            ));
 
         $iterator = new ListKey($client, 'key:list', 5);
 
@@ -194,18 +211,24 @@ class ListKeyTest extends PredisTestCase
     public function testIterationWithCountParameterOnMultipleFetches()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'lrange'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('lrange')
-               ->with('key:list', 0, 1)
-               ->will($this->returnValue(array('item:1', 'item:2')));
-        $client->expects($this->at(2))
-               ->method('lrange')
-               ->with('key:list', 2, 3)
-               ->will($this->returnValue(array('item:3')));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('lrange')
+            ->with('key:list', 0, 1)
+            ->will($this->returnValue(
+                array('item:1', 'item:2')
+            ));
+        $client
+            ->expects($this->at(2))
+            ->method('lrange')
+            ->with('key:list', 2, 3)
+            ->will($this->returnValue(
+                array('item:3')
+            ));
 
         $iterator = new ListKey($client, 'key:list', 2);
 
@@ -234,14 +257,17 @@ class ListKeyTest extends PredisTestCase
     public function testIterationRewindable()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'lrange'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->exactly(2))
-               ->method('lrange')
-               ->with('key:list', 0, 9)
-               ->will($this->returnValue(array('item:1', 'item:2')));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->exactly(2))
+            ->method('lrange')
+            ->with('key:list', 0, 9)
+            ->will($this->returnValue(
+                array('item:1', 'item:2')
+            ));
 
         $iterator = new ListKey($client, 'key:list');
 

+ 189 - 130
tests/Predis/Collection/Iterator/SetKeyTest.php

@@ -26,14 +26,16 @@ class SetKeyTest extends PredisTestCase
     public function testThrowsExceptionOnMissingCommand()
     {
         $commands = $this->getMock('Predis\Command\FactoryInterface');
-        $commands->expects($this->any())
-                 ->method('supportsCommand')
-                 ->will($this->returnValue(false));
+        $commands
+            ->expects($this->any())
+            ->method('supportsCommand')
+            ->will($this->returnValue(false));
 
         $client = $this->getMock('Predis\ClientInterface');
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($commands));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($commands));
 
         new SetKey($client, 'key:set');
     }
@@ -44,14 +46,17 @@ class SetKeyTest extends PredisTestCase
     public function testIterationWithNoResults()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'sscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->once())
-               ->method('sscan')
-               ->with('key:set', 0, array())
-               ->will($this->returnValue(array(0, array())));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->once())
+            ->method('sscan')
+            ->with('key:set', 0, array())
+            ->will($this->returnValue(
+                array(0, array())
+            ));
 
         $iterator = new SetKey($client, 'key:set');
 
@@ -65,14 +70,17 @@ class SetKeyTest extends PredisTestCase
     public function testIterationOnSingleFetch()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'sscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->once())
-               ->method('sscan')
-               ->with('key:set', 0, array())
-               ->will($this->returnValue(array(0, array('member:1st', 'member:2nd', 'member:3rd'))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->once())
+            ->method('sscan')
+            ->with('key:set', 0, array())
+            ->will($this->returnValue(
+                array(0, array('member:1st', 'member:2nd', 'member:3rd'))
+            ));
 
         $iterator = new SetKey($client, 'key:set');
 
@@ -101,18 +109,24 @@ class SetKeyTest extends PredisTestCase
     public function testIterationOnMultipleFetches()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'sscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('sscan')
-               ->with('key:set', 0, array())
-               ->will($this->returnValue(array(2, array('member:1st', 'member:2nd'))));
-        $client->expects($this->at(2))
-               ->method('sscan')
-               ->with('key:set', 2, array())
-               ->will($this->returnValue(array(0, array('member:3rd'))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('sscan')
+            ->with('key:set', 0, array())
+            ->will($this->returnValue(
+                array(2, array('member:1st', 'member:2nd'))
+            ));
+        $client
+            ->expects($this->at(2))
+            ->method('sscan')
+            ->with('key:set', 2, array())
+            ->will($this->returnValue(
+                array(0, array('member:3rd'))
+            ));
 
         $iterator = new SetKey($client, 'key:set');
 
@@ -141,18 +155,24 @@ class SetKeyTest extends PredisTestCase
     public function testIterationOnMultipleFetchesAndHoleInFirstFetch()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'sscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('sscan')
-               ->with('key:set', 0, array())
-               ->will($this->returnValue(array(4, array())));
-        $client->expects($this->at(2))
-               ->method('sscan')
-               ->with('key:set', 4, array())
-               ->will($this->returnValue(array(0, array('member:1st', 'member:2nd'))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('sscan')
+            ->with('key:set', 0, array())
+            ->will($this->returnValue(
+                array(4, array())
+            ));
+        $client
+            ->expects($this->at(2))
+            ->method('sscan')
+            ->with('key:set', 4, array())
+            ->will($this->returnValue(
+                array(0, array('member:1st', 'member:2nd'))
+            ));
 
         $iterator = new SetKey($client, 'key:set');
 
@@ -176,22 +196,31 @@ class SetKeyTest extends PredisTestCase
     public function testIterationOnMultipleFetchesAndHoleInMidFetch()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'sscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('sscan')
-               ->with('key:set', 0, array())
-               ->will($this->returnValue(array(2, array('member:1st', 'member:2nd'))));
-        $client->expects($this->at(2))
-               ->method('sscan')
-               ->with('key:set', 2, array())
-               ->will($this->returnValue(array(5, array())));
-        $client->expects($this->at(3))
-               ->method('sscan')
-               ->with('key:set', 5, array())
-               ->will($this->returnValue(array(0, array('member:3rd'))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('sscan')
+            ->with('key:set', 0, array())
+            ->will($this->returnValue(
+                array(2, array('member:1st', 'member:2nd'))
+            ));
+        $client
+            ->expects($this->at(2))
+            ->method('sscan')
+            ->with('key:set', 2, array())
+            ->will($this->returnValue(
+                array(5, array())
+            ));
+        $client
+            ->expects($this->at(3))
+            ->method('sscan')
+            ->with('key:set', 5, array())
+            ->will($this->returnValue(
+                array(0, array('member:3rd'))
+            ));
 
         $iterator = new SetKey($client, 'key:set');
 
@@ -220,14 +249,17 @@ class SetKeyTest extends PredisTestCase
     public function testIterationWithOptionMatch()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'sscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('sscan')
-               ->with('key:set', 0, array('MATCH' => 'member:*'))
-               ->will($this->returnValue(array(0, array('member:1st', 'member:2nd'))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('sscan')
+            ->with('key:set', 0, array('MATCH' => 'member:*'))
+            ->will($this->returnValue(
+                array(0, array('member:1st', 'member:2nd'))
+            ));
 
         $iterator = new SetKey($client, 'key:set', 'member:*');
 
@@ -251,18 +283,24 @@ class SetKeyTest extends PredisTestCase
     public function testIterationWithOptionMatchOnMultipleFetches()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'sscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('sscan')
-               ->with('key:set', 0, array('MATCH' => 'member:*'))
-               ->will($this->returnValue(array(1, array('member:1st'))));
-        $client->expects($this->at(2))
-               ->method('sscan')
-               ->with('key:set', 1, array('MATCH' => 'member:*'))
-               ->will($this->returnValue(array(0, array('member:2nd'))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('sscan')
+            ->with('key:set', 0, array('MATCH' => 'member:*'))
+            ->will($this->returnValue(
+                array(1, array('member:1st'))
+            ));
+        $client
+            ->expects($this->at(2))
+            ->method('sscan')
+            ->with('key:set', 1, array('MATCH' => 'member:*'))
+            ->will($this->returnValue(
+                array(0, array('member:2nd'))
+            ));
 
         $iterator = new SetKey($client, 'key:set', 'member:*');
 
@@ -286,14 +324,17 @@ class SetKeyTest extends PredisTestCase
     public function testIterationWithOptionCount()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'sscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('sscan')
-               ->with('key:set', 0, array('COUNT' => 2))
-               ->will($this->returnValue(array(0, array('member:1st', 'member:2nd'))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('sscan')
+            ->with('key:set', 0, array('COUNT' => 2))
+            ->will($this->returnValue(
+                array(0, array('member:1st', 'member:2nd'))
+            ));
 
         $iterator = new SetKey($client, 'key:set', null, 2);
 
@@ -317,18 +358,24 @@ class SetKeyTest extends PredisTestCase
     public function testIterationWithOptionCountOnMultipleFetches()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'sscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('sscan')
-               ->with('key:set', 0, array('COUNT' => 1))
-               ->will($this->returnValue(array(1, array('member:1st'))));
-        $client->expects($this->at(2))
-               ->method('sscan')
-               ->with('key:set', 1, array('COUNT' => 1))
-               ->will($this->returnValue(array(0, array('member:2nd'))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('sscan')
+            ->with('key:set', 0, array('COUNT' => 1))
+            ->will($this->returnValue(
+                array(1, array('member:1st'))
+            ));
+        $client
+            ->expects($this->at(2))
+            ->method('sscan')
+            ->with('key:set', 1, array('COUNT' => 1))
+            ->will($this->returnValue(
+                array(0, array('member:2nd'))
+            ));
 
         $iterator = new SetKey($client, 'key:set', null, 1);
 
@@ -352,14 +399,17 @@ class SetKeyTest extends PredisTestCase
     public function testIterationWithOptionsMatchAndCount()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'sscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('sscan')
-               ->with('key:set', 0, array('MATCH' => 'member:*', 'COUNT' => 2))
-               ->will($this->returnValue(array(0, array('member:1st', 'member:2nd'))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('sscan')
+            ->with('key:set', 0, array('MATCH' => 'member:*', 'COUNT' => 2))
+            ->will($this->returnValue(
+                array(0, array('member:1st', 'member:2nd'))
+            ));
 
         $iterator = new SetKey($client, 'key:set', 'member:*', 2);
 
@@ -383,18 +433,24 @@ class SetKeyTest extends PredisTestCase
     public function testIterationWithOptionsMatchAndCountOnMultipleFetches()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'sscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('sscan')
-               ->with('key:set', 0, array('MATCH' => 'member:*', 'COUNT' => 1))
-               ->will($this->returnValue(array(1, array('member:1st'))));
-        $client->expects($this->at(2))
-               ->method('sscan')
-               ->with('key:set', 1, array('MATCH' => 'member:*', 'COUNT' => 1))
-               ->will($this->returnValue(array(0, array('member:2nd'))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('sscan')
+            ->with('key:set', 0, array('MATCH' => 'member:*', 'COUNT' => 1))
+            ->will($this->returnValue(
+                array(1, array('member:1st'))
+            ));
+        $client
+            ->expects($this->at(2))
+            ->method('sscan')
+            ->with('key:set', 1, array('MATCH' => 'member:*', 'COUNT' => 1))
+            ->will($this->returnValue(
+                array(0, array('member:2nd'))
+            ));
 
         $iterator = new SetKey($client, 'key:set', 'member:*', 1);
 
@@ -418,14 +474,17 @@ class SetKeyTest extends PredisTestCase
     public function testIterationRewindable()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'sscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->exactly(2))
-               ->method('sscan')
-               ->with('key:set', 0, array())
-               ->will($this->returnValue(array(0, array('member:1st', 'member:2nd'))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->exactly(2))
+            ->method('sscan')
+            ->with('key:set', 0, array())
+            ->will($this->returnValue(
+                array(0, array('member:1st', 'member:2nd'))
+            ));
 
         $iterator = new SetKey($client, 'key:set');
 

+ 200 - 172
tests/Predis/Collection/Iterator/SortedSetKeyTest.php

@@ -26,14 +26,16 @@ class SortedSetKeyTest extends PredisTestCase
     public function testThrowsExceptionOnMissingCommand()
     {
         $commands = $this->getMock('Predis\Command\FactoryInterface');
-        $commands->expects($this->any())
-                 ->method('supportsCommand')
-                 ->will($this->returnValue(false));
+        $commands
+            ->expects($this->any())
+            ->method('supportsCommand')
+            ->will($this->returnValue(false));
 
         $client = $this->getMock('Predis\ClientInterface');
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($commands));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($commands));
 
         new SortedSetKey($client, 'key:zset');
     }
@@ -44,14 +46,17 @@ class SortedSetKeyTest extends PredisTestCase
     public function testIterationWithNoResults()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->once())
-               ->method('zscan')
-               ->with('key:zset', 0, array())
-               ->will($this->returnValue(array(0, array())));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->once())
+            ->method('zscan')
+            ->with('key:zset', 0, array())
+            ->will($this->returnValue(
+                array(0, array())
+            ));
 
         $iterator = new SortedSetKey($client, 'key:zset');
 
@@ -66,16 +71,17 @@ class SortedSetKeyTest extends PredisTestCase
     public function testIterationWithIntegerMembers()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->once())
-               ->method('zscan')
-               ->with('key:zset', 0, array())
-               ->will($this->returnValue(array(0, array(
-                    0 => 0, 101 => 1, 102 => 2,
-               ))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->once())
+            ->method('zscan')
+            ->with('key:zset', 0, array())
+            ->will($this->returnValue(
+                array(0, array(0 => 0, 101 => 1, 102 => 2))
+            ));
 
         $iterator = new SortedSetKey($client, 'key:zset');
 
@@ -104,16 +110,17 @@ class SortedSetKeyTest extends PredisTestCase
     public function testIterationOnSingleFetch()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->once())
-               ->method('zscan')
-               ->with('key:zset', 0, array())
-               ->will($this->returnValue(array(0, array(
-                    'member:1st' => 1.0, 'member:2nd' => 2.0, 'member:3rd' => 3.0,
-               ))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->once())
+            ->method('zscan')
+            ->with('key:zset', 0, array())
+            ->will($this->returnValue(
+                array(0, array('member:1st' => 1.0, 'member:2nd' => 2.0, 'member:3rd' => 3.0))
+            ));
 
         $iterator = new SortedSetKey($client, 'key:zset');
 
@@ -142,22 +149,24 @@ class SortedSetKeyTest extends PredisTestCase
     public function testIterationOnMultipleFetches()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('zscan')
-               ->with('key:zset', 0, array())
-               ->will($this->returnValue(array(2, array(
-                    'member:1st' => 1.0, 'member:2nd' => 2.0,
-               ))));
-        $client->expects($this->at(2))
-               ->method('zscan')
-               ->with('key:zset', 2, array())
-               ->will($this->returnValue(array(0, array(
-                    'member:3rd' => 3.0,
-               ))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('zscan')
+            ->with('key:zset', 0, array())
+            ->will($this->returnValue(
+                array(2, array('member:1st' => 1.0, 'member:2nd' => 2.0))
+            ));
+        $client
+            ->expects($this->at(2))
+            ->method('zscan')
+            ->with('key:zset', 2, array())
+            ->will($this->returnValue(
+                array(0, array('member:3rd' => 3.0))
+            ));
 
         $iterator = new SortedSetKey($client, 'key:zset');
 
@@ -186,20 +195,24 @@ class SortedSetKeyTest extends PredisTestCase
     public function testIterationOnMultipleFetchesAndHoleInFirstFetch()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('zscan')
-               ->with('key:zset', 0, array())
-               ->will($this->returnValue(array(4, array())));
-        $client->expects($this->at(2))
-               ->method('zscan')
-               ->with('key:zset', 4, array())
-               ->will($this->returnValue(array(0, array(
-                    'member:1st' => 1.0, 'member:2nd' => 2.0,
-               ))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('zscan')
+            ->with('key:zset', 0, array())
+            ->will($this->returnValue(
+                array(4, array())
+            ));
+        $client
+            ->expects($this->at(2))
+            ->method('zscan')
+            ->with('key:zset', 4, array())
+            ->will($this->returnValue(
+                array(0, array('member:1st' => 1.0, 'member:2nd' => 2.0))
+            ));
 
         $iterator = new SortedSetKey($client, 'key:zset');
 
@@ -223,26 +236,31 @@ class SortedSetKeyTest extends PredisTestCase
     public function testIterationOnMultipleFetchesAndHoleInMidFetch()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('zscan')
-               ->with('key:zset', 0, array())
-               ->will($this->returnValue(array(2, array(
-                    'member:1st' => 1.0, 'member:2nd' => 2.0,
-               ))));
-        $client->expects($this->at(2))
-               ->method('zscan')
-               ->with('key:zset', 2, array())
-               ->will($this->returnValue(array(5, array())));
-        $client->expects($this->at(3))
-               ->method('zscan')
-               ->with('key:zset', 5, array())
-               ->will($this->returnValue(array(0, array(
-                    'member:3rd' => 3.0,
-               ))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('zscan')
+            ->with('key:zset', 0, array())
+            ->will($this->returnValue(
+                array(2, array('member:1st' => 1.0, 'member:2nd' => 2.0))
+            ));
+        $client
+            ->expects($this->at(2))
+            ->method('zscan')
+            ->with('key:zset', 2, array())
+            ->will($this->returnValue(
+                array(5, array())
+            ));
+        $client
+            ->expects($this->at(3))
+            ->method('zscan')
+            ->with('key:zset', 5, array())
+            ->will($this->returnValue(
+                array(0, array('member:3rd' => 3.0))
+            ));
 
         $iterator = new SortedSetKey($client, 'key:zset');
 
@@ -271,16 +289,17 @@ class SortedSetKeyTest extends PredisTestCase
     public function testIterationWithOptionMatch()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('zscan')
-               ->with('key:zset', 0, array('MATCH' => 'member:*'))
-               ->will($this->returnValue(array(2, array(
-                    'member:1st' => 1.0, 'member:2nd' => 2.0,
-               ))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('zscan')
+            ->with('key:zset', 0, array('MATCH' => 'member:*'))
+            ->will($this->returnValue(
+                array(2, array('member:1st' => 1.0, 'member:2nd' => 2.0))
+            ));
 
         $iterator = new SortedSetKey($client, 'key:zset', 'member:*');
 
@@ -304,22 +323,24 @@ class SortedSetKeyTest extends PredisTestCase
     public function testIterationWithOptionMatchOnMultipleFetches()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('zscan')
-               ->with('key:zset', 0, array('MATCH' => 'member:*'))
-               ->will($this->returnValue(array(1, array(
-                    'member:1st' => 1.0,
-                ))));
-        $client->expects($this->at(2))
-               ->method('zscan')
-               ->with('key:zset', 1, array('MATCH' => 'member:*'))
-               ->will($this->returnValue(array(0, array(
-                    'member:2nd' => 2.0,
-                ))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('zscan')
+            ->with('key:zset', 0, array('MATCH' => 'member:*'))
+            ->will($this->returnValue(
+                array(1, array('member:1st' => 1.0))
+            ));
+        $client
+            ->expects($this->at(2))
+            ->method('zscan')
+            ->with('key:zset', 1, array('MATCH' => 'member:*'))
+            ->will($this->returnValue(
+                array(0, array('member:2nd' => 2.0))
+            ));
 
         $iterator = new SortedSetKey($client, 'key:zset', 'member:*');
 
@@ -343,16 +364,17 @@ class SortedSetKeyTest extends PredisTestCase
     public function testIterationWithOptionCount()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('zscan')
-               ->with('key:zset', 0, array('COUNT' => 2))
-               ->will($this->returnValue(array(0, array(
-                    'member:1st' => 1.0, 'member:2nd' => 2.0,
-               ))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('zscan')
+            ->with('key:zset', 0, array('COUNT' => 2))
+            ->will($this->returnValue(
+                array(0, array('member:1st' => 1.0, 'member:2nd' => 2.0))
+            ));
 
         $iterator = new SortedSetKey($client, 'key:zset', null, 2);
 
@@ -376,22 +398,24 @@ class SortedSetKeyTest extends PredisTestCase
     public function testIterationWithOptionCountOnMultipleFetches()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('zscan')
-               ->with('key:zset', 0, array('COUNT' => 1))
-               ->will($this->returnValue(array(1, array(
-                    'member:1st' => 1.0,
-                ))));
-        $client->expects($this->at(2))
-               ->method('zscan')
-               ->with('key:zset', 1, array('COUNT' => 1))
-               ->will($this->returnValue(array(0, array(
-                    'member:2nd' => 2.0,
-                ))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('zscan')
+            ->with('key:zset', 0, array('COUNT' => 1))
+            ->will($this->returnValue(
+                array(1, array('member:1st' => 1.0))
+            ));
+        $client
+            ->expects($this->at(2))
+            ->method('zscan')
+            ->with('key:zset', 1, array('COUNT' => 1))
+            ->will($this->returnValue(
+                array(0, array('member:2nd' => 2.0))
+            ));
 
         $iterator = new SortedSetKey($client, 'key:zset', null, 1);
 
@@ -415,16 +439,17 @@ class SortedSetKeyTest extends PredisTestCase
     public function testIterationWithOptionsMatchAndCount()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('zscan')
-               ->with('key:zset', 0, array('MATCH' => 'member:*', 'COUNT' => 2))
-               ->will($this->returnValue(array(0, array(
-                    'member:1st' => 1.0, 'member:2nd' => 2.0,
-               ))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('zscan')
+            ->with('key:zset', 0, array('MATCH' => 'member:*', 'COUNT' => 2))
+            ->will($this->returnValue(
+                array(0, array('member:1st' => 1.0, 'member:2nd' => 2.0))
+            ));
 
         $iterator = new SortedSetKey($client, 'key:zset', 'member:*', 2);
 
@@ -448,22 +473,24 @@ class SortedSetKeyTest extends PredisTestCase
     public function testIterationWithOptionsMatchAndCountOnMultipleFetches()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->at(1))
-               ->method('zscan')
-               ->with('key:zset', 0, array('MATCH' => 'member:*', 'COUNT' => 1))
-               ->will($this->returnValue(array(1, array(
-                    'member:1st' => 1.0,
-                ))));
-        $client->expects($this->at(2))
-               ->method('zscan')
-               ->with('key:zset', 1, array('MATCH' => 'member:*', 'COUNT' => 1))
-               ->will($this->returnValue(array(0, array(
-                    'member:2nd' => 2.0,
-                ))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->at(1))
+            ->method('zscan')
+            ->with('key:zset', 0, array('MATCH' => 'member:*', 'COUNT' => 1))
+            ->will($this->returnValue(
+                array(1, array('member:1st' => 1.0))
+            ));
+        $client
+            ->expects($this->at(2))
+            ->method('zscan')
+            ->with('key:zset', 1, array('MATCH' => 'member:*', 'COUNT' => 1))
+            ->will($this->returnValue(
+                array(0, array('member:2nd' => 2.0))
+            ));
 
         $iterator = new SortedSetKey($client, 'key:zset', 'member:*', 1);
 
@@ -487,16 +514,17 @@ class SortedSetKeyTest extends PredisTestCase
     public function testIterationRewindable()
     {
         $client = $this->getMock('Predis\Client', array('getCommandFactory', 'zscan'));
-
-        $client->expects($this->any())
-               ->method('getCommandFactory')
-               ->will($this->returnValue($this->getCommandFactory()));
-        $client->expects($this->exactly(2))
-               ->method('zscan')
-               ->with('key:zset', 0, array())
-               ->will($this->returnValue(array(0, array(
-                    'member:1st' => 1.0, 'member:2nd' => 2.0,
-               ))));
+        $client
+            ->expects($this->any())
+            ->method('getCommandFactory')
+            ->will($this->returnValue($this->getCommandFactory()));
+        $client
+            ->expects($this->exactly(2))
+            ->method('zscan')
+            ->with('key:zset', 0, array())
+            ->will($this->returnValue(
+                array(0, array('member:1st' => 1.0, 'member:2nd' => 2.0))
+            ));
 
         $iterator = new SortedSetKey($client, 'key:zset');
 

+ 12 - 8
tests/Predis/Command/RedisFactoryTest.php

@@ -226,12 +226,15 @@ class RedisFactoryTest extends PredisTestCase
         $argsRef = null;
 
         $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface');
-        $processor->expects($this->once())
-                  ->method('process')
-                  ->with($this->isInstanceOf('Predis\Command\CommandInterface'))
-                  ->will($this->returnCallback(function (CommandInterface $cmd) use (&$argsRef) {
-                        $cmd->setRawArguments($argsRef = array_map('strtoupper', $cmd->getArguments()));
-                    }));
+        $processor
+            ->expects($this->once())
+            ->method('process')
+            ->with($this->isInstanceOf('Predis\Command\CommandInterface'))
+            ->will($this->returnCallback(
+                function (CommandInterface $cmd) use (&$argsRef) {
+                    $cmd->setRawArguments($argsRef = array_map('strtoupper', $cmd->getArguments()));
+                }
+            ));
 
         $factory = new RedisFactory();
         $factory->setProcessor($processor);
@@ -246,8 +249,9 @@ class RedisFactoryTest extends PredisTestCase
     public function testChainOfProcessors()
     {
         $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface');
-        $processor->expects($this->exactly(2))
-                  ->method('process');
+        $processor
+            ->expects($this->exactly(2))
+            ->method('process');
 
         $chain = new ProcessorChain();
         $chain->add($processor);

+ 82 - 75
tests/Predis/Command/ScriptCommandTest.php

@@ -36,16 +36,17 @@ class ScriptCommandTest extends PredisTestCase
      */
     public function testGetScriptHash()
     {
-        $arguments = array('key1', 'key2', 'value1', 'value2');
-
         $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount'));
-        $command->expects($this->exactly(2))
-                ->method('getScript')
-                ->will($this->returnValue(self::LUA_SCRIPT));
-        $command->expects($this->once())
-                ->method('getKeysCount')
-                ->will($this->returnValue(2));
-        $command->setArguments($arguments);
+        $command
+            ->expects($this->exactly(2))
+            ->method('getScript')
+            ->will($this->returnValue(self::LUA_SCRIPT));
+        $command
+            ->expects($this->once())
+            ->method('getKeysCount')
+            ->will($this->returnValue(2));
+
+        $command->setArguments($arguments = array('key1', 'key2', 'value1', 'value2'));
 
         $this->assertSame(self::LUA_SCRIPT_SHA1, $command->getScriptHash());
     }
@@ -55,16 +56,17 @@ class ScriptCommandTest extends PredisTestCase
      */
     public function testGetKeys()
     {
-        $arguments = array('key1', 'key2', 'value1', 'value2');
-
         $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount'));
-        $command->expects($this->once())
-                ->method('getScript')
-                ->will($this->returnValue(self::LUA_SCRIPT));
-        $command->expects($this->exactly(2))
-                ->method('getKeysCount')
-                ->will($this->returnValue(2));
-        $command->setArguments($arguments);
+        $command
+            ->expects($this->once())
+            ->method('getScript')
+            ->will($this->returnValue(self::LUA_SCRIPT));
+        $command
+            ->expects($this->exactly(2))
+            ->method('getKeysCount')
+            ->will($this->returnValue(2));
+
+        $command->setArguments($arguments = array('key1', 'key2', 'value1', 'value2'));
 
         $this->assertSame(array('key1', 'key2'), $command->getKeys());
     }
@@ -74,13 +76,13 @@ class ScriptCommandTest extends PredisTestCase
      */
     public function testGetKeysWithZeroKeysCount()
     {
-        $arguments = array('value1', 'value2', 'value3');
-
         $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript'));
-        $command->expects($this->once())
-                ->method('getScript')
-                ->will($this->returnValue(self::LUA_SCRIPT));
-        $command->setArguments($arguments);
+        $command
+            ->expects($this->once())
+            ->method('getScript')
+            ->will($this->returnValue(self::LUA_SCRIPT));
+
+        $command->setArguments($arguments = array('value1', 'value2', 'value3'));
 
         $this->assertSame(array(), $command->getKeys());
     }
@@ -90,16 +92,17 @@ class ScriptCommandTest extends PredisTestCase
      */
     public function testGetKeysWithNegativeKeysCount()
     {
-        $arguments = array('key1', 'key2', 'value1', 'value2');
-
         $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount'));
-        $command->expects($this->once())
-                ->method('getScript')
-                ->will($this->returnValue(self::LUA_SCRIPT));
-        $command->expects($this->exactly(2))
-                ->method('getKeysCount')
-                ->will($this->returnValue(-2));
-        $command->setArguments($arguments);
+        $command
+            ->expects($this->once())
+            ->method('getScript')
+            ->will($this->returnValue(self::LUA_SCRIPT));
+        $command
+            ->expects($this->exactly(2))
+            ->method('getKeysCount')
+            ->will($this->returnValue(-2));
+
+        $command->setArguments($arguments = array('key1', 'key2', 'value1', 'value2'));
 
         $this->assertSame(array('key1', 'key2'), $command->getKeys());
     }
@@ -109,16 +112,17 @@ class ScriptCommandTest extends PredisTestCase
      */
     public function testGetArguments()
     {
-        $arguments = array('key1', 'key2', 'value1', 'value2');
-
         $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount'));
-        $command->expects($this->once())
-                ->method('getScript')
-                ->will($this->returnValue(self::LUA_SCRIPT));
-        $command->expects($this->once())
-                ->method('getKeysCount')
-                ->will($this->returnValue(2));
-        $command->setArguments($arguments);
+        $command
+            ->expects($this->once())
+            ->method('getScript')
+            ->will($this->returnValue(self::LUA_SCRIPT));
+        $command
+            ->expects($this->once())
+            ->method('getKeysCount')
+            ->will($this->returnValue(2));
+
+        $command->setArguments($arguments = array('key1', 'key2', 'value1', 'value2'));
 
         $this->assertSame(array_merge(array(self::LUA_SCRIPT_SHA1, 2), $arguments), $command->getArguments());
     }
@@ -128,13 +132,13 @@ class ScriptCommandTest extends PredisTestCase
      */
     public function testGetArgumentsWithZeroKeysCount()
     {
-        $arguments = array('value1', 'value2', 'value3');
-
         $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount'));
-        $command->expects($this->once())
-                ->method('getScript')
-                ->will($this->returnValue(self::LUA_SCRIPT));
-        $command->setArguments($arguments);
+        $command
+            ->expects($this->once())
+            ->method('getScript')
+            ->will($this->returnValue(self::LUA_SCRIPT));
+
+        $command->setArguments($arguments = array('key1', 'key2', 'value1', 'value2'));
 
         $this->assertSame(array_merge(array(self::LUA_SCRIPT_SHA1, 0), $arguments), $command->getArguments());
     }
@@ -144,16 +148,17 @@ class ScriptCommandTest extends PredisTestCase
      */
     public function testGetArgumentsWithNegativeKeysCount()
     {
-        $arguments = array('key1', 'key2', 'value1', 'value2');
-
         $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount'));
-        $command->expects($this->once())
-                ->method('getScript')
-                ->will($this->returnValue(self::LUA_SCRIPT));
-        $command->expects($this->once())
-                ->method('getKeysCount')
-                ->will($this->returnValue(-2));
-        $command->setArguments($arguments);
+        $command
+            ->expects($this->once())
+            ->method('getScript')
+            ->will($this->returnValue(self::LUA_SCRIPT));
+        $command
+            ->expects($this->once())
+            ->method('getKeysCount')
+            ->will($this->returnValue(-2));
+
+        $command->setArguments($arguments = array('key1', 'key2', 'value1', 'value2'));
 
         $this->assertSame(array_merge(array(self::LUA_SCRIPT_SHA1, 2), $arguments), $command->getArguments());
     }
@@ -163,16 +168,17 @@ class ScriptCommandTest extends PredisTestCase
      */
     public function testGetEvalArguments()
     {
-        $arguments = array('key1', 'key2', 'value1', 'value2');
-
         $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount'));
-        $command->expects($this->exactly(2))
-                ->method('getScript')
-                ->will($this->returnValue(self::LUA_SCRIPT));
-        $command->expects($this->once())
-                ->method('getKeysCount')
-                ->will($this->returnValue(2));
-        $command->setArguments($arguments);
+        $command
+            ->expects($this->exactly(2))
+            ->method('getScript')
+            ->will($this->returnValue(self::LUA_SCRIPT));
+        $command
+            ->expects($this->once())
+            ->method('getKeysCount')
+            ->will($this->returnValue(2));
+
+        $command->setArguments($arguments = array('key1', 'key2', 'value1', 'value2'));
 
         $this->assertSame(array_merge(array(self::LUA_SCRIPT, 2), $arguments), $command->getEvalArguments());
     }
@@ -182,16 +188,17 @@ class ScriptCommandTest extends PredisTestCase
      */
     public function testGetEvalCommand()
     {
-        $arguments = array('key1', 'key2', 'value1', 'value2');
-
         $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount'));
-        $command->expects($this->exactly(2))
-                ->method('getScript')
-                ->will($this->returnValue(self::LUA_SCRIPT));
-        $command->expects($this->once())
-                ->method('getKeysCount')
-                ->will($this->returnValue(2));
-        $command->setArguments($arguments);
+        $command
+            ->expects($this->exactly(2))
+            ->method('getScript')
+            ->will($this->returnValue(self::LUA_SCRIPT));
+        $command
+            ->expects($this->once())
+            ->method('getKeysCount')
+            ->will($this->returnValue(2));
+
+        $command->setArguments($arguments = array('key1', 'key2', 'value1', 'value2'));
 
         $evalCMD = new RawCommand('EVAL', array_merge(array(self::LUA_SCRIPT, 2), $arguments));
 

+ 10 - 8
tests/Predis/Configuration/Option/AggregateTest.php

@@ -41,10 +41,11 @@ class AggregateTest extends PredisTestCase
         $connection = $this->getMock('Predis\Connection\AggregateConnectionInterface');
 
         $callable = $this->getMock('stdClass', array('__invoke'));
-        $callable->expects($this->once())
-                 ->method('__invoke')
-                 ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
-                 ->will($this->returnValue($connection));
+        $callable
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
+            ->will($this->returnValue($connection));
 
         $this->assertInstanceOf('Closure', $initializer = $option->filter($options, $callable));
         $this->assertSame($connection, $initializer($parameters = array()));
@@ -63,10 +64,11 @@ class AggregateTest extends PredisTestCase
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
 
         $callable = $this->getMock('stdClass', array('__invoke'));
-        $callable->expects($this->once())
-                 ->method('__invoke')
-                 ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
-                 ->will($this->returnValue($connection));
+        $callable
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
+            ->will($this->returnValue($connection));
 
         $this->assertInstanceOf('Closure', $initializer = $option->filter($options, $callable));
 

+ 21 - 17
tests/Predis/Configuration/Option/ClusterTest.php

@@ -42,10 +42,11 @@ class ClusterTest extends PredisTestCase
         $connection = $this->getMock('Predis\Connection\AggregateConnectionInterface');
 
         $callable = $this->getMock('stdClass', array('__invoke'));
-        $callable->expects($this->once())
-                 ->method('__invoke')
-                 ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
-                 ->will($this->returnValue($connection));
+        $callable
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
+            ->will($this->returnValue($connection));
 
         $this->assertInstanceOf('Closure', $initializer = $option->filter($options, $callable));
         $this->assertSame($connection, $initializer($parameters = array()));
@@ -64,10 +65,11 @@ class ClusterTest extends PredisTestCase
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
 
         $callable = $this->getMock('stdClass', array('__invoke'));
-        $callable->expects($this->once())
-                 ->method('__invoke')
-                 ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
-                 ->will($this->returnValue($connection));
+        $callable
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
+            ->will($this->returnValue($connection));
 
         $this->assertInstanceOf('Closure', $initializer = $option->filter($options, $callable));
 
@@ -82,9 +84,10 @@ class ClusterTest extends PredisTestCase
         $option = new Cluster();
 
         $options = $this->getMock('Predis\Configuration\OptionsInterface');
-        $options->expects($this->never())
-                ->method('__get')
-                ->with('connections');
+        $options
+            ->expects($this->never())
+            ->method('__get')
+            ->with('connections');
 
         $this->assertInstanceOf('Closure', $initializer = $option->filter($options, 'predis'));
         $this->assertInstanceOf('Predis\Connection\Cluster\PredisCluster', $initializer($parameters = array()));
@@ -98,12 +101,13 @@ class ClusterTest extends PredisTestCase
         $option = new Cluster();
 
         $options = $this->getMock('Predis\Configuration\OptionsInterface');
-        $options->expects($this->once())
-                ->method('__get')
-                ->with('connections')
-                ->will($this->returnValue(
-                    $this->getMock('Predis\Connection\FactoryInterface')
-                ));
+        $options
+            ->expects($this->once())
+            ->method('__get')
+            ->with('connections')
+            ->will($this->returnValue(
+                $this->getMock('Predis\Connection\FactoryInterface')
+            ));
 
         $this->assertInstanceOf('Closure', $initializer = $option->filter($options, 'redis'));
         $this->assertInstanceOf('Predis\Connection\Cluster\RedisCluster', $initializer($parameters = array()));

+ 29 - 20
tests/Predis/Configuration/Option/CommandsTest.php

@@ -43,14 +43,18 @@ class CommandsTest extends PredisTestCase
         $option = new Commands();
 
         $options = $this->getMock('Predis\Configuration\OptionsInterface');
-        $options->expects($this->once())
-                ->method('__isset')
-                ->with('prefix')
-                ->will($this->returnValue(true));
-        $options->expects($this->once())
-                ->method('__get')
-                ->with('prefix')
-                ->will($this->returnValue(new KeyPrefixProcessor('prefix:')));
+        $options
+            ->expects($this->once())
+            ->method('__isset')
+            ->with('prefix')
+            ->will($this->returnValue(true));
+        $options
+            ->expects($this->once())
+            ->method('__get')
+            ->with('prefix')
+            ->will($this->returnValue(
+                new KeyPrefixProcessor('prefix:')
+            ));
 
         $commands = $option->getDefault($options);
 
@@ -108,10 +112,11 @@ class CommandsTest extends PredisTestCase
         $commands = $this->getMock('Predis\Command\FactoryInterface');
 
         $callable = $this->getMock('stdClass', array('__invoke'));
-        $callable->expects($this->once())
-                 ->method('__invoke')
-                 ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
-                 ->will($this->returnValue($commands));
+        $callable
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
+            ->will($this->returnValue($commands));
 
         $this->assertSame($commands, $option->filter($options, $callable));
     }
@@ -131,10 +136,11 @@ class CommandsTest extends PredisTestCase
         );
 
         $callable = $this->getMock('stdClass', array('__invoke'));
-        $callable->expects($this->once())
-                 ->method('__invoke')
-                 ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
-                 ->will($this->returnValue($dictionary));
+        $callable
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
+            ->will($this->returnValue($dictionary));
 
         $commands = $option->filter($options, $callable);
 
@@ -155,10 +161,13 @@ class CommandsTest extends PredisTestCase
         $options = $this->getMock('Predis\Configuration\OptionsInterface');
 
         $callable = $this->getMock('stdClass', array('__invoke'));
-        $callable->expects($this->once())
-                 ->method('__invoke')
-                 ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
-                 ->will($this->returnValue(new \stdClass()));
+        $callable
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
+            ->will($this->returnValue(
+                new \stdClass()
+            ));
 
         $option->filter($options, $callable);
     }

+ 30 - 23
tests/Predis/Configuration/Option/ConnectionsTest.php

@@ -41,15 +41,17 @@ class ConnectionsTest extends PredisTestCase
         $value = array('tcp' => $class, 'redis' => $class);
 
         $default = $this->getMock('Predis\Connection\FactoryInterface');
-        $default->expects($this->exactly(2))
-                ->method('define')
-                ->with($this->matchesRegularExpression('/^tcp|redis$/'), $class);
+        $default
+            ->expects($this->exactly(2))
+            ->method('define')
+            ->with($this->matchesRegularExpression('/^tcp|redis$/'), $class);
 
         $option = $this->getMock('Predis\Configuration\Option\Connections', array('getDefault'));
-        $option->expects($this->once())
-               ->method('getDefault')
-               ->with($options)
-               ->will($this->returnValue($default));
+        $option
+            ->expects($this->once())
+            ->method('getDefault')
+            ->with($options)
+            ->will($this->returnValue($default));
 
         $this->assertInstanceOf('Predis\Connection\FactoryInterface', $factory = $option->filter($options, $value));
         $this->assertSame($default, $factory);
@@ -63,17 +65,18 @@ class ConnectionsTest extends PredisTestCase
         $parameters = array('database' => 5, 'password' => 'mypassword');
 
         $default = $this->getMock('Predis\Connection\Factory');
-        $options = $this->getMock('Predis\Configuration\OptionsInterface');
-
-        $options->expects($this->once())
-                ->method('defined')
-                ->with('parameters')
-                ->will($this->returnValue(true));
 
-        $options->expects($this->once())
-                ->method('__get')
-                ->with('parameters')
-                ->will($this->returnValue($parameters));
+        $options = $this->getMock('Predis\Configuration\OptionsInterface');
+        $options
+            ->expects($this->once())
+            ->method('defined')
+            ->with('parameters')
+            ->will($this->returnValue(true));
+        $options
+            ->expects($this->once())
+            ->method('__get')
+            ->with('parameters')
+            ->will($this->returnValue($parameters));
 
         $option = new Connections();
         $factory = $option->getDefault($options);
@@ -87,7 +90,9 @@ class ConnectionsTest extends PredisTestCase
     public function testAcceptsConnectionFactoryInstance()
     {
         $option = $this->getMock('Predis\Configuration\Option\Connections', array('getDefault'));
-        $option->expects($this->never())->method('getDefault');
+        $option
+            ->expects($this->never())
+            ->method('getDefault');
 
         $options = $this->getMock('Predis\Configuration\OptionsInterface');
         $factory = $this->getMock('Predis\Connection\FactoryInterface');
@@ -103,13 +108,15 @@ class ConnectionsTest extends PredisTestCase
         $option = new Connections();
 
         $options = $this->getMock('Predis\Configuration\OptionsInterface');
-        $factory = $this->getMock('Predis\Connection\FactoryInterface');
 
         $callable = $this->getMock('stdClass', array('__invoke'));
-        $callable->expects($this->once())
-                 ->method('__invoke')
-                 ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
-                 ->will($this->returnValue($factory));
+        $callable
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
+            ->will($this->returnValue(
+                $factory = $this->getMock('Predis\Connection\FactoryInterface')
+            ));
 
         $this->assertSame($factory, $option->filter($options, $callable));
     }

+ 16 - 12
tests/Predis/Configuration/Option/PrefixTest.php

@@ -69,13 +69,15 @@ class PrefixTest extends PredisTestCase
         $option = new Prefix();
 
         $options = $this->getMock('Predis\Configuration\OptionsInterface');
-        $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface');
 
         $callable = $this->getMock('stdClass', array('__invoke'));
-        $callable->expects($this->once())
-                 ->method('__invoke')
-                 ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
-                 ->will($this->returnValue($processor));
+        $callable
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
+            ->will($this->returnValue(
+                $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface')
+            ));
 
         $prefix = $option->filter($options, $callable);
 
@@ -92,10 +94,11 @@ class PrefixTest extends PredisTestCase
         $options = $this->getMock('Predis\Configuration\OptionsInterface');
 
         $callable = $this->getMock('stdClass', array('__invoke'));
-        $callable->expects($this->once())
-                 ->method('__invoke')
-                 ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
-                 ->will($this->returnValue('pfx:'));
+        $callable
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
+            ->will($this->returnValue('pfx:'));
 
         $prefix = $option->filter($options, $callable);
 
@@ -114,9 +117,10 @@ class PrefixTest extends PredisTestCase
         $options = $this->getMock('Predis\Configuration\OptionsInterface');
 
         $input = $this->getMock('stdClass', array('__toString'));
-        $input->expects($this->once())
-              ->method('__toString')
-              ->will($this->returnValue('pfx:'));
+        $input
+            ->expects($this->once())
+            ->method('__toString')
+            ->will($this->returnValue('pfx:'));
 
         $prefix = $option->filter($options, $input);
 

+ 32 - 26
tests/Predis/Configuration/Option/ReplicationTest.php

@@ -41,14 +41,16 @@ class ReplicationTest extends PredisTestCase
         $connectionFactory = $this->getMock('Predis\Connection\FactoryInterface');
 
         $options = $this->getMock('Predis\Configuration\OptionsInterface');
-        $options->expects($this->at(0))
-                ->method('__get')
-                ->with('autodiscovery')
-                ->will($this->returnValue(true));
-        $options->expects($this->at(1))
-                ->method('__get')
-                ->with('connections')
-                ->will($this->returnValue($connectionFactory));
+        $options
+            ->expects($this->at(0))
+            ->method('__get')
+            ->with('autodiscovery')
+            ->will($this->returnValue(true));
+        $options
+            ->expects($this->at(1))
+            ->method('__get')
+            ->with('connections')
+            ->will($this->returnValue($connectionFactory));
 
         $this->assertInstanceOf('Closure', $initializer = $option->getDefault($options));
         $this->assertInstanceOf('Predis\Connection\Replication\MasterSlaveReplication', $connection = $initializer($options));
@@ -71,10 +73,11 @@ class ReplicationTest extends PredisTestCase
         $connection = $this->getMock('Predis\Connection\AggregateConnectionInterface');
 
         $callable = $this->getMock('stdClass', array('__invoke'));
-        $callable->expects($this->once())
-                 ->method('__invoke')
-                 ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
-                 ->will($this->returnValue($connection));
+        $callable
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
+            ->will($this->returnValue($connection));
 
         $this->assertInstanceOf('Closure', $initializer = $option->filter($options, $callable));
         $this->assertSame($connection, $initializer($parameters = array()));
@@ -93,10 +96,11 @@ class ReplicationTest extends PredisTestCase
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
 
         $callable = $this->getMock('stdClass', array('__invoke'));
-        $callable->expects($this->once())
-                 ->method('__invoke')
-                 ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
-                 ->will($this->returnValue($connection));
+        $callable
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
+            ->will($this->returnValue($connection));
 
         $this->assertInstanceOf('Closure', $initializer = $option->filter($options, $callable));
 
@@ -124,16 +128,18 @@ class ReplicationTest extends PredisTestCase
         $option = new Replication();
 
         $options = $this->getMock('Predis\Configuration\OptionsInterface');
-        $options->expects($this->at(0))
-                ->method('__get')
-                ->with('service')
-                ->will($this->returnValue('mymaster'));
-        $options->expects($this->at(1))
-                ->method('__get')
-                ->with('connections')
-                ->will($this->returnValue(
-                    $this->getMock('Predis\Connection\FactoryInterface')
-                ));
+        $options
+            ->expects($this->at(0))
+            ->method('__get')
+            ->with('service')
+            ->will($this->returnValue('mymaster'));
+        $options
+            ->expects($this->at(1))
+            ->method('__get')
+            ->with('connections')
+            ->will($this->returnValue(
+                $this->getMock('Predis\Connection\FactoryInterface')
+            ));
 
         $parameters = array(
             $this->getMock('Predis\Connection\NodeConnectionInterface'),

+ 18 - 13
tests/Predis/Configuration/OptionsTest.php

@@ -42,10 +42,11 @@ class OptionsTest extends PredisTestCase
         $connection = $this->getMock('Predis\Connection\AggregateConnectionInterface');
 
         $callable = $this->getMock('stdClass', array('__invoke'));
-        $callable->expects($this->any())
-                 ->method('__invoke')
-                 ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
-                 ->will($this->returnValue($connection));
+        $callable
+            ->expects($this->any())
+            ->method('__invoke')
+            ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
+            ->will($this->returnValue($connection));
 
         $options = new Options(array(
             'exceptions' => false,
@@ -160,10 +161,11 @@ class OptionsTest extends PredisTestCase
 
         // NOTE: closure values are covered by this test since they define __invoke().
         $callable = $this->getMock('stdClass', array('__invoke'));
-        $callable->expects($this->once())
-                 ->method('__invoke')
-                 ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
-                 ->will($this->returnValue($commands));
+        $callable
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
+            ->will($this->returnValue($commands));
 
         $options = new Options(array(
             'commands' => $callable,
@@ -182,10 +184,11 @@ class OptionsTest extends PredisTestCase
 
         // NOTE: closure values are covered by this test since they define __invoke().
         $callable = $this->getMock('stdClass', array('__invoke'));
-        $callable->expects($this->once())
-                 ->method('__invoke')
-                 ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
-                 ->will($this->returnValue($custom));
+        $callable
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
+            ->will($this->returnValue($custom));
 
         $options = new Options(array(
             'custom' => $callable,
@@ -201,7 +204,9 @@ class OptionsTest extends PredisTestCase
     public function testChecksForInvokeMagicMethodDoesNotTriggerAutoloader()
     {
         $trigger = $this->getMock('stdClass', array('autoload'));
-        $trigger->expects($this->never())->method('autoload');
+        $trigger
+            ->expects($this->never())
+            ->method('autoload');
 
         spl_autoload_register($autoload = function ($class) use ($trigger) {
             $trigger->autoload($class);

+ 66 - 22
tests/Predis/Connection/Cluster/PredisClusterTest.php

@@ -36,6 +36,7 @@ class PredisClusterTest extends PredisTestCase
         $connection2 = $this->getMockConnection();
 
         $cluster = new PredisCluster();
+
         $cluster->add($connection1);
         $cluster->add($connection2);
 
@@ -53,6 +54,7 @@ class PredisClusterTest extends PredisTestCase
         $connection2 = $this->getMockConnection('tcp://host1:7002?alias=node2');
 
         $cluster = new PredisCluster();
+
         $cluster->add($connection1);
         $cluster->add($connection2);
 
@@ -71,6 +73,7 @@ class PredisClusterTest extends PredisTestCase
         $connection3 = $this->getMockConnection();
 
         $cluster = new PredisCluster();
+
         $cluster->add($connection1);
         $cluster->add($connection2);
 
@@ -89,6 +92,7 @@ class PredisClusterTest extends PredisTestCase
         $connection3 = $this->getMockConnection('tcp://host1:7002?alias=node3');
 
         $cluster = new PredisCluster();
+
         $cluster->add($connection1);
         $cluster->add($connection2);
         $cluster->add($connection3);
@@ -105,12 +109,17 @@ class PredisClusterTest extends PredisTestCase
     public function testConnectForcesAllConnectionsToConnect()
     {
         $connection1 = $this->getMockConnection();
-        $connection1->expects($this->once())->method('connect');
+        $connection1
+            ->expects($this->once())
+            ->method('connect');
 
         $connection2 = $this->getMockConnection();
-        $connection2->expects($this->once())->method('connect');
+        $connection2
+            ->expects($this->once())
+            ->method('connect');
 
         $cluster = new PredisCluster();
+
         $cluster->add($connection1);
         $cluster->add($connection2);
 
@@ -123,12 +132,17 @@ class PredisClusterTest extends PredisTestCase
     public function testDisconnectForcesAllConnectionsToDisconnect()
     {
         $connection1 = $this->getMockConnection();
-        $connection1->expects($this->once())->method('disconnect');
+        $connection1
+            ->expects($this->once())
+            ->method('disconnect');
 
         $connection2 = $this->getMockConnection();
-        $connection2->expects($this->once())->method('disconnect');
+        $connection2
+            ->expects($this->once())
+            ->method('disconnect');
 
         $cluster = new PredisCluster();
+
         $cluster->add($connection1);
         $cluster->add($connection2);
 
@@ -141,16 +155,19 @@ class PredisClusterTest extends PredisTestCase
     public function testIsConnectedReturnsTrueIfAtLeastOneConnectionIsOpen()
     {
         $connection1 = $this->getMockConnection();
-        $connection1->expects($this->once())
-                    ->method('isConnected')
-                    ->will($this->returnValue(false));
+        $connection1
+            ->expects($this->once())
+            ->method('isConnected')
+            ->will($this->returnValue(false));
 
         $connection2 = $this->getMockConnection();
-        $connection2->expects($this->once())
-                    ->method('isConnected')
-                    ->will($this->returnValue(true));
+        $connection2
+            ->expects($this->once())
+            ->method('isConnected')
+            ->will($this->returnValue(true));
 
         $cluster = new PredisCluster();
+
         $cluster->add($connection1);
         $cluster->add($connection2);
 
@@ -163,16 +180,19 @@ class PredisClusterTest extends PredisTestCase
     public function testIsConnectedReturnsFalseIfAllConnectionsAreClosed()
     {
         $connection1 = $this->getMockConnection();
-        $connection1->expects($this->once())
-                    ->method('isConnected')
-                    ->will($this->returnValue(false));
+        $connection1
+            ->expects($this->once())
+            ->method('isConnected')
+            ->will($this->returnValue(false));
 
         $connection2 = $this->getMockConnection();
-        $connection2->expects($this->once())
-                    ->method('isConnected')
-                    ->will($this->returnValue(false));
+        $connection2
+            ->expects($this->once())
+            ->method('isConnected')
+            ->will($this->returnValue(false));
 
         $cluster = new PredisCluster();
+
         $cluster->add($connection1);
         $cluster->add($connection2);
 
@@ -188,6 +208,7 @@ class PredisClusterTest extends PredisTestCase
         $connection2 = $this->getMockConnection();
 
         $cluster = new PredisCluster();
+
         $cluster->add($connection1);
         $cluster->add($connection2);
 
@@ -207,6 +228,7 @@ class PredisClusterTest extends PredisTestCase
         $connection2 = $this->getMockConnection('tcp://host1:7002');
 
         $cluster = new PredisCluster();
+
         $cluster->add($connection1);
         $cluster->add($connection2);
 
@@ -227,6 +249,7 @@ class PredisClusterTest extends PredisTestCase
         $connection2 = $this->getMockConnection('tcp://host1:7002');
 
         $cluster = new PredisCluster();
+
         $cluster->add($connection1);
         $cluster->add($connection2);
 
@@ -261,6 +284,7 @@ class PredisClusterTest extends PredisTestCase
         $ping = $this->getCommandFactory()->createCommand('ping');
 
         $cluster = new PredisCluster();
+
         $cluster->add($this->getMockConnection());
 
         $cluster->getConnection($ping);
@@ -277,6 +301,7 @@ class PredisClusterTest extends PredisTestCase
         $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380');
 
         $cluster = new PredisCluster();
+
         $cluster->add($connection1);
         $cluster->add($connection2);
 
@@ -299,12 +324,18 @@ class PredisClusterTest extends PredisTestCase
         $command = $this->getCommandFactory()->createCommand('get', array('node01:5431'));
 
         $connection1 = $this->getMockConnection('tcp://host1:7001');
-        $connection1->expects($this->once())->method('writeRequest')->with($command);
+        $connection1
+            ->expects($this->once())
+            ->method('writeRequest')
+            ->with($command);
 
         $connection2 = $this->getMockConnection('tcp://host1:7002');
-        $connection2->expects($this->never())->method('writeRequest');
+        $connection2
+            ->expects($this->never())
+            ->method('writeRequest');
 
         $cluster = new PredisCluster();
+
         $cluster->add($connection1);
         $cluster->add($connection2);
 
@@ -319,12 +350,18 @@ class PredisClusterTest extends PredisTestCase
         $command = $this->getCommandFactory()->createCommand('get', array('node02:3212'));
 
         $connection1 = $this->getMockConnection('tcp://host1:7001');
-        $connection1->expects($this->never())->method('readResponse');
+        $connection1
+            ->expects($this->never())
+            ->method('readResponse');
 
         $connection2 = $this->getMockConnection('tcp://host1:7002');
-        $connection2->expects($this->once())->method('readResponse')->with($command);
+        $connection2
+            ->expects($this->once())
+            ->method('readResponse')
+            ->with($command);
 
         $cluster = new PredisCluster();
+
         $cluster->add($connection1);
         $cluster->add($connection2);
 
@@ -339,12 +376,18 @@ class PredisClusterTest extends PredisTestCase
         $command = $this->getCommandFactory()->createCommand('get', array('node01:5431'));
 
         $connection1 = $this->getMockConnection('tcp://host1:7001');
-        $connection1->expects($this->once())->method('executeCommand')->with($command);
+        $connection1
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($command);
 
         $connection2 = $this->getMockConnection('tcp://host1:7002');
-        $connection2->expects($this->never())->method('executeCommand');
+        $connection2
+            ->expects($this->never())
+            ->method('executeCommand');
 
         $cluster = new PredisCluster();
+
         $cluster->add($connection1);
         $cluster->add($connection2);
 
@@ -360,6 +403,7 @@ class PredisClusterTest extends PredisTestCase
         $connection2 = $this->getMockConnection('tcp://host2?alias=second');
 
         $cluster = new PredisCluster();
+
         $cluster->add($connection1);
         $cluster->add($connection2);
 

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 390 - 264
tests/Predis/Connection/Cluster/RedisClusterTest.php


+ 11 - 10
tests/Predis/Connection/CompositeStreamConnectionTest.php

@@ -30,16 +30,17 @@ class CompositeStreamConnectionTest extends PredisConnectionTestCase
     {
         $cmdSelect = RawCommand::create('SELECT', '1000');
 
-        $connection = $this->getMockBuilder(static::CONNECTION_CLASS)
-                           ->setMethods(array('executeCommand', 'createResource'))
-                           ->setConstructorArgs(array(new Parameters()))
-                           ->getMock();
-
-        $connection->method('executeCommand')
-                   ->with($cmdSelect)
-                   ->will($this->returnValue(
-                       new ErrorResponse('ERR invalid DB index')
-                   ));
+        $connection = $this
+            ->getMockBuilder(static::CONNECTION_CLASS)
+            ->setMethods(array('executeCommand', 'createResource'))
+            ->setConstructorArgs(array(new Parameters()))
+            ->getMock();
+        $connection
+            ->method('executeCommand')
+            ->with($cmdSelect)
+            ->will($this->returnValue(
+                new ErrorResponse('ERR invalid DB index')
+            ));
 
         $connection->method('createResource');
 

+ 44 - 29
tests/Predis/Connection/FactoryTest.php

@@ -269,7 +269,9 @@ class FactoryTest extends PredisTestCase
     public function testCreateConnectionWithoutInitializationCommands()
     {
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->never())->method('addConnectCommand');
+        $connection
+            ->expects($this->never())
+            ->method('addConnectCommand');
 
         $parameters = new Parameters(array('scheme' => 'test'));
 
@@ -294,15 +296,18 @@ class FactoryTest extends PredisTestCase
         ));
 
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->once())
-                   ->method('getParameters')
-                   ->will($this->returnValue($parameters));
-        $connection->expects($this->at(1))
-                   ->method('addConnectCommand')
-                   ->with($this->isRedisCommand('AUTH', array('foobar')));
-        $connection->expects($this->at(2))
-                   ->method('addConnectCommand')
-                   ->with($this->isRedisCommand('SELECT', array(0)));
+        $connection
+            ->expects($this->once())
+            ->method('getParameters')
+            ->will($this->returnValue($parameters));
+        $connection
+            ->expects($this->at(1))
+            ->method('addConnectCommand')
+            ->with($this->isRedisCommand('AUTH', array('foobar')));
+        $connection
+            ->expects($this->at(2))
+            ->method('addConnectCommand')
+            ->with($this->isRedisCommand('SELECT', array(0)));
 
         $factory = new Factory();
 
@@ -353,13 +358,15 @@ class FactoryTest extends PredisTestCase
         };
 
         $initializerMock = $this->getMock('stdClass', array('__invoke'));
-        $initializerMock->expects($this->exactly(2))
-                        ->method('__invoke')
-                        ->with($parameters)
-                        ->will($this->returnCallback($initializer));
+        $initializerMock
+            ->expects($this->exactly(2))
+            ->method('__invoke')
+            ->with($parameters)
+            ->will($this->returnCallback($initializer));
 
         $factory = new Factory();
         $factory->define($parameters->scheme, $initializerMock);
+
         $connection1 = $factory->create($parameters);
         $connection2 = $factory->create($parameters);
 
@@ -428,13 +435,15 @@ class FactoryTest extends PredisTestCase
         list(, $connectionClass) = $this->getMockConnectionClass();
 
         $cluster = $this->getMock('Predis\Connection\Cluster\ClusterInterface');
-        $cluster->expects($this->exactly(2))
-                ->method('add')
-                ->with($this->isInstanceOf('Predis\Connection\NodeConnectionInterface'));
+        $cluster
+            ->expects($this->exactly(2))
+            ->method('add')
+            ->with($this->isInstanceOf('Predis\Connection\NodeConnectionInterface'));
 
         $factory = $this->getMock('Predis\Connection\Factory', array('create'));
-        $factory->expects($this->never())
-                ->method('create');
+        $factory
+            ->expects($this->never())
+            ->method('create');
 
         $factory->aggregate($cluster, array(new $connectionClass(), new $connectionClass()));
     }
@@ -447,16 +456,18 @@ class FactoryTest extends PredisTestCase
         list(, $connectionClass) = $this->getMockConnectionClass();
 
         $cluster = $this->getMock('Predis\Connection\Cluster\ClusterInterface');
-        $cluster->expects($this->exactly(4))
-                ->method('add')
-                ->with($this->isInstanceOf('Predis\Connection\NodeConnectionInterface'));
+        $cluster
+            ->expects($this->exactly(4))
+            ->method('add')
+            ->with($this->isInstanceOf('Predis\Connection\NodeConnectionInterface'));
 
         $factory = $this->getMock('Predis\Connection\Factory', array('create'));
-        $factory->expects($this->exactly(3))
-                ->method('create')
-                ->will($this->returnCallback(function ($_) use ($connectionClass) {
-                    return new $connectionClass();
-                }));
+        $factory
+            ->expects($this->exactly(3))
+            ->method('create')
+            ->will($this->returnCallback(function ($_) use ($connectionClass) {
+                return new $connectionClass();
+            }));
 
         $factory->aggregate($cluster, array(null, 'tcp://127.0.0.1', array('scheme' => 'tcp'), new $connectionClass()));
     }
@@ -467,10 +478,14 @@ class FactoryTest extends PredisTestCase
     public function testAggregateConnectionWithEmptyListOfParameters()
     {
         $cluster = $this->getMock('Predis\Connection\Cluster\ClusterInterface');
-        $cluster->expects($this->never())->method('add');
+        $cluster
+            ->expects($this->never())
+            ->method('add');
 
         $factory = $this->getMock('Predis\Connection\Factory', array('create'));
-        $factory->expects($this->never())->method('create');
+        $factory
+            ->expects($this->never())
+            ->method('create');
 
         $factory->aggregate($cluster, array());
     }

+ 11 - 10
tests/Predis/Connection/PhpiredisSocketConnectionTest.php

@@ -55,16 +55,17 @@ class PhpiredisSocketConnectionTest extends PredisConnectionTestCase
     {
         $cmdSelect = RawCommand::create('SELECT', '1000');
 
-        $connection = $this->getMockBuilder(static::CONNECTION_CLASS)
-                           ->setMethods(array('executeCommand', 'createResource'))
-                           ->setConstructorArgs(array(new Parameters()))
-                           ->getMock();
-
-        $connection->method('executeCommand')
-                   ->with($cmdSelect)
-                   ->will($this->returnValue(
-                       new ErrorResponse('ERR invalid DB index')
-                   ));
+        $connection = $this
+            ->getMockBuilder(static::CONNECTION_CLASS)
+            ->setMethods(array('executeCommand', 'createResource'))
+            ->setConstructorArgs(array(new Parameters()))
+            ->getMock();
+        $connection
+            ->method('executeCommand')
+            ->with($cmdSelect)
+            ->will($this->returnValue(
+                new ErrorResponse('ERR invalid DB index')
+            ));
 
         $connection->method('createResource');
 

+ 11 - 10
tests/Predis/Connection/PhpiredisStreamConnectionTest.php

@@ -55,16 +55,17 @@ class PhpiredisStreamConnectionTest extends PredisConnectionTestCase
     {
         $cmdSelect = RawCommand::create('SELECT', '1000');
 
-        $connection = $this->getMockBuilder(static::CONNECTION_CLASS)
-                           ->setMethods(array('executeCommand', 'createResource'))
-                           ->setConstructorArgs(array(new Parameters()))
-                           ->getMock();
-
-        $connection->method('executeCommand')
-                   ->with($cmdSelect)
-                   ->will($this->returnValue(
-                       new ErrorResponse('ERR invalid DB index')
-                   ));
+        $connection = $this
+            ->getMockBuilder(static::CONNECTION_CLASS)
+            ->setMethods(array('executeCommand', 'createResource'))
+            ->setConstructorArgs(array(new Parameters()))
+            ->getMock();
+        $connection
+            ->method('executeCommand')
+            ->with($cmdSelect)
+            ->will($this->returnValue(
+                new ErrorResponse('ERR invalid DB index')
+            ));
 
         $connection->method('createResource');
 

+ 337 - 162
tests/Predis/Connection/Replication/MasterSlaveReplicationTest.php

@@ -97,10 +97,14 @@ class MasterSlaveReplicationTest extends PredisTestCase
     public function testConnectsToOneOfSlaves()
     {
         $master = $this->getMockConnection('tcp://host1?alias=master');
-        $master->expects($this->never())->method('connect');
+        $master
+            ->expects($this->never())
+            ->method('connect');
 
         $slave = $this->getMockConnection('tcp://host2?alias=slave1');
-        $slave->expects($this->once())->method('connect');
+        $slave
+            ->expects($this->once())
+            ->method('connect');
 
         $replication = new MasterSlaveReplication();
         $replication->add($master);
@@ -129,10 +133,16 @@ class MasterSlaveReplicationTest extends PredisTestCase
     public function testIsConnectedReturnsTrueIfAtLeastOneConnectionIsOpen()
     {
         $master = $this->getMockConnection('tcp://host1?alias=master');
-        $master->expects($this->never())->method('isConnected')->will($this->returnValue(false));
+        $master
+            ->expects($this->never())
+            ->method('isConnected')
+            ->will($this->returnValue(false));
 
         $slave = $this->getMockConnection('tcp://host2?alias=slave1');
-        $slave->expects($this->once())->method('isConnected')->will($this->returnValue(true));
+        $slave
+            ->expects($this->once())
+            ->method('isConnected')
+            ->will($this->returnValue(true));
 
         $replication = new MasterSlaveReplication();
         $replication->add($master);
@@ -148,10 +158,16 @@ class MasterSlaveReplicationTest extends PredisTestCase
     public function testIsConnectedReturnsFalseIfAllConnectionsAreClosed()
     {
         $master = $this->getMockConnection('tcp://host1?alias=master');
-        $master->expects($this->any())->method('isConnected')->will($this->returnValue(false));
+        $master
+            ->expects($this->any())
+            ->method('isConnected')
+            ->will($this->returnValue(false));
 
         $slave = $this->getMockConnection('tcp://host2?alias=slave1');
-        $slave->expects($this->any())->method('isConnected')->will($this->returnValue(false));
+        $slave
+            ->expects($this->any())
+            ->method('isConnected')
+            ->will($this->returnValue(false));
 
         $replication = new MasterSlaveReplication();
         $replication->add($master);
@@ -171,10 +187,14 @@ class MasterSlaveReplicationTest extends PredisTestCase
     public function testDisconnectForcesCurrentConnectionToDisconnect()
     {
         $master = $this->getMockConnection('tcp://host1?alias=master');
-        $master->expects($this->once())->method('disconnect');
+        $master
+            ->expects($this->once())
+            ->method('disconnect');
 
         $slave = $this->getMockConnection('tcp://host2?alias=slave1');
-        $slave->expects($this->once())->method('disconnect');
+        $slave
+            ->expects($this->once())
+            ->method('disconnect');
 
         $replication = new MasterSlaveReplication();
         $replication->add($master);
@@ -199,6 +219,7 @@ class MasterSlaveReplicationTest extends PredisTestCase
 
         $replication->switchTo('master');
         $this->assertSame($master, $replication->getCurrent());
+
         $replication->switchTo('slave1');
         $this->assertSame($slave1, $replication->getCurrent());
     }
@@ -211,6 +232,7 @@ class MasterSlaveReplicationTest extends PredisTestCase
     public function testThrowsErrorWhenSwitchingToUnknownConnectionByAlias()
     {
         $replication = new MasterSlaveReplication();
+
         $replication->add($this->getMockConnection('tcp://host1?alias=master'));
         $replication->add($this->getMockConnection('tcp://host2?alias=slave1'));
 
@@ -233,6 +255,7 @@ class MasterSlaveReplicationTest extends PredisTestCase
 
         $replication->switchTo($master);
         $this->assertSame($master, $replication->getCurrent());
+
         $replication->switchTo($slave1);
         $this->assertSame($slave1, $replication->getCurrent());
     }
@@ -245,6 +268,7 @@ class MasterSlaveReplicationTest extends PredisTestCase
     public function testThrowsErrorWhenSwitchingToUnknownConnectionByInstance()
     {
         $replication = new MasterSlaveReplication();
+
         $replication->add($this->getMockConnection('tcp://host1?alias=master'));
         $replication->add($this->getMockConnection('tcp://host2?alias=slave1'));
 
@@ -263,6 +287,7 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $slave2 = $this->getMockConnection('tcp://host3?alias=slave2');
 
         $replication = new MasterSlaveReplication();
+
         $replication->add($master);
         $replication->add($slave1);
         $replication->add($slave2);
@@ -283,6 +308,7 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $slave1 = $this->getMockConnection('tcp://host2?alias=slave1');
 
         $replication = new MasterSlaveReplication();
+
         $replication->add($slave1);
 
         $replication->switchToMaster();
@@ -299,6 +325,7 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $slave1 = $this->getMockConnection('tcp://host2?alias=slave1');
 
         $replication = new MasterSlaveReplication();
+
         $replication->add($master);
         $replication->add($slave1);
 
@@ -318,6 +345,7 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $master = $this->getMockConnection('tcp://host1?alias=master');
 
         $replication = new MasterSlaveReplication();
+
         $replication->add($master);
 
         $replication->switchToSlave();
@@ -334,6 +362,7 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $slave1 = $this->getMockConnection('tcp://host2?alias=slave1');
 
         $replication = new MasterSlaveReplication();
+
         $replication->add($master);
         $replication->add($slave1);
 
@@ -355,6 +384,7 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $slave1 = $this->getMockConnection('tcp://host2?alias=slave1');
 
         $replication = new MasterSlaveReplication();
+
         $replication->add($master);
         $replication->add($slave1);
 
@@ -375,6 +405,7 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $master = $this->getMockConnection('tcp://host1?alias=master');
 
         $replication = new MasterSlaveReplication();
+
         $replication->add($master);
 
         $cmd = $commands->createCommand('exists', array('foo'));
@@ -395,6 +426,7 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $slave1 = $this->getMockConnection('tcp://host2?alias=slave1');
 
         $replication = new MasterSlaveReplication();
+
         $replication->add($master);
         $replication->add($slave1);
 
@@ -418,10 +450,16 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $cmdSet = $commands->createCommand('set', array('foo', 'bar'));
 
         $master = $this->getMockConnection('tcp://host1?alias=master');
-        $master->expects($this->once())->method('writeRequest')->with($cmdSet);
+        $master
+            ->expects($this->once())
+            ->method('writeRequest')
+            ->with($cmdSet);
 
         $slave1 = $this->getMockConnection('tcp://host2?alias=slave1');
-        $slave1->expects($this->once())->method('writeRequest')->with($cmdExists);
+        $slave1
+            ->expects($this->once())
+            ->method('writeRequest')
+            ->with($cmdExists);
 
         $replication = new MasterSlaveReplication();
         $replication->add($master);
@@ -441,12 +479,19 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $cmdSet = $commands->createCommand('set', array('foo', 'bar'));
 
         $master = $this->getMockConnection('tcp://host1?alias=master');
-        $master->expects($this->once())->method('readResponse')->with($cmdSet);
+        $master
+            ->expects($this->once())
+            ->method('readResponse')
+            ->with($cmdSet);
 
         $slave1 = $this->getMockConnection('tcp://host2?alias=slave1');
-        $slave1->expects($this->once())->method('readResponse')->with($cmdExists);
+        $slave1
+            ->expects($this->once())
+            ->method('readResponse')
+            ->with($cmdExists);
 
         $replication = new MasterSlaveReplication();
+
         $replication->add($master);
         $replication->add($slave1);
 
@@ -464,12 +509,19 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $cmdSet = $commands->createCommand('set', array('foo', 'bar'));
 
         $master = $this->getMockConnection('tcp://host1?alias=master');
-        $master->expects($this->once())->method('executeCommand')->with($cmdSet);
+        $master
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdSet);
 
         $slave1 = $this->getMockConnection('tcp://host2?alias=slave1');
-        $slave1->expects($this->once())->method('executeCommand')->with($cmdExists);
+        $slave1
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdExists);
 
         $replication = new MasterSlaveReplication();
+
         $replication->add($master);
         $replication->add($slave1);
 
@@ -486,12 +538,18 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $cmdWatch = $commands->createCommand('watch', array('foo'));
 
         $master = $this->getMockConnection('tcp://host1?alias=master');
-        $master->expects($this->once())->method('executeCommand')->with($cmdWatch);
+        $master
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdWatch);
 
         $slave1 = $this->getMockConnection('tcp://host2?alias=slave1');
-        $slave1->expects($this->never())->method('executeCommand');
+        $slave1
+            ->expects($this->never())
+            ->method('executeCommand');
 
         $replication = new MasterSlaveReplication();
+
         $replication->add($master);
         $replication->add($slave1);
 
@@ -507,12 +565,18 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $cmdMulti = $commands->createCommand('multi');
 
         $master = $this->getMockConnection('tcp://host1?alias=master');
-        $master->expects($this->once())->method('executeCommand')->with($cmdMulti);
+        $master
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdMulti);
 
         $slave1 = $this->getMockConnection('tcp://host2?alias=slave1');
-        $slave1->expects($this->never())->method('executeCommand');
+        $slave1
+            ->expects($this->never())
+            ->method('executeCommand');
 
         $replication = new MasterSlaveReplication();
+
         $replication->add($master);
         $replication->add($slave1);
 
@@ -528,12 +592,18 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $cmdEval = $commands->createCommand('eval', array("return redis.call('info')"));
 
         $master = $this->getMockConnection('tcp://host1?alias=master');
-        $master->expects($this->once())->method('executeCommand')->with($cmdEval);
+        $master
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdEval);
 
         $slave1 = $this->getMockConnection('tcp://host2?alias=slave1');
-        $slave1->expects($this->never())->method('executeCommand');
+        $slave1
+            ->expects($this->never())
+            ->method('executeCommand');
 
         $replication = new MasterSlaveReplication();
+
         $replication->add($master);
         $replication->add($slave1);
 
@@ -550,12 +620,19 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $cmdSortStore = $commands->createCommand('sort', array('key', array('store' => 'key:store')));
 
         $master = $this->getMockConnection('tcp://host1?alias=master');
-        $master->expects($this->once())->method('executeCommand')->with($cmdSortStore);
+        $master
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdSortStore);
 
         $slave1 = $this->getMockConnection('tcp://host2?alias=slave1');
-        $slave1->expects($this->once())->method('executeCommand')->with($cmdSortNormal);
+        $slave1
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdSortNormal);
 
         $replication = new MasterSlaveReplication();
+
         $replication->add($master);
         $replication->add($slave1);
 
@@ -572,19 +649,25 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $cmdExists = $commands->createCommand('exists', array('key'));
 
         $master = $this->getMockConnection('tcp://host1?alias=master');
-        $master->expects($this->never())->method('executeCommand');
+        $master
+            ->expects($this->never())
+            ->method('executeCommand');
 
         $slave1 = $this->getMockConnection('tcp://host2?alias=slave1');
-        $slave1->expects($this->once())
-               ->method('executeCommand')
-               ->with($cmdExists)
-               ->will($this->throwException(new Connection\ConnectionException($slave1)));
+        $slave1
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdExists)
+            ->will($this->throwException(
+                new Connection\ConnectionException($slave1)
+            ));
 
         $slave2 = $this->getMockConnection('tcp://host3?alias=slave2');
-        $slave2->expects($this->once())
-               ->method('executeCommand')
-               ->with($cmdExists)
-               ->will($this->returnValue(1));
+        $slave2
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdExists)
+            ->will($this->returnValue(1));
 
         $replication = new MasterSlaveReplication();
 
@@ -610,22 +693,27 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $cmdExists = $commands->createCommand('exists', array('key'));
 
         $master = $this->getMockConnection('tcp://host1?alias=master');
-        $master->expects($this->once())
-               ->method('executeCommand')
-               ->with($cmdExists)
-               ->will($this->returnValue(1));
+        $master
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdExists)
+            ->will($this->returnValue(1));
 
         $slave1 = $this->getMockConnection('tcp://host2?alias=slave1');
-        $slave1->expects($this->once())
-               ->method('executeCommand')
-               ->with($cmdExists)
-               ->will($this->throwException(new Connection\ConnectionException($slave1)));
+        $slave1
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdExists)
+            ->will($this->throwException(new Connection\ConnectionException($slave1)));
 
         $slave2 = $this->getMockConnection('tcp://host3?alias=slave2');
-        $slave2->expects($this->once())
-               ->method('executeCommand')
-               ->with($cmdExists)
-               ->will($this->throwException(new Connection\ConnectionException($slave2)));
+        $slave2
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdExists)
+            ->will($this->throwException(
+                new Connection\ConnectionException($slave2)
+            ));
 
         $replication = new MasterSlaveReplication();
 
@@ -651,12 +739,14 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $cmdExists = $commands->createCommand('exists', array('key'));
 
         $slave1 = $this->getMockConnection('tcp://host1?alias=slave1');
-        $slave1->expects($this->once())
-               ->method('executeCommand')
-               ->with($cmdExists)
-               ->will($this->returnValue(1));
+        $slave1
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdExists)
+            ->will($this->returnValue(1));
 
         $replication = new MasterSlaveReplication();
+
         $replication->add($slave1);
 
         $response = $replication->executeCommand($cmdExists);
@@ -675,9 +765,12 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $cmdSet = $commands->createCommand('set', array('key', 'value'));
 
         $slave1 = $this->getMockConnection('tcp://host1?alias=slave1');
-        $slave1->expects($this->never())->method('executeCommand');
+        $slave1
+            ->expects($this->never())
+            ->method('executeCommand');
 
         $replication = new MasterSlaveReplication();
+
         $replication->add($slave1);
 
         $replication->executeCommand($cmdSet);
@@ -693,22 +786,24 @@ class MasterSlaveReplicationTest extends PredisTestCase
                ->method('executeCommand');
 
         $slave1 = $this->getMockConnection('tcp://host2?alias=slave1');
-        $slave1->expects($this->once())
-               ->method('executeCommand')
-               ->with($this->isRedisCommand(
-                   'EXISTS', array('key')
-               ))
-               ->will($this->returnValue(
-                   new Response\Error('LOADING')
-               ));
+        $slave1
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($this->isRedisCommand(
+                'EXISTS', array('key')
+            ))
+            ->will($this->returnValue(
+                new Response\Error('LOADING')
+            ));
 
         $slave2 = $this->getMockConnection('tcp://host3?alias=slave2');
-        $slave2->expects($this->once())
-               ->method('executeCommand')
-               ->with($this->isRedisCommand(
-                   'EXISTS', array('key')
-               ))
-               ->will($this->returnValue(1));
+        $slave2
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($this->isRedisCommand(
+                'EXISTS', array('key')
+            ))
+            ->will($this->returnValue(1));
 
         $replication = new MasterSlaveReplication();
 
@@ -737,14 +832,18 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $cmdSet = $commands->createCommand('set', array('key', 'value'));
 
         $master = $this->getMockConnection('tcp://host1?alias=master');
-        $master->expects($this->once())
-               ->method('executeCommand')
-               ->with($cmdSet)
-               ->will($this->throwException(new Connection\ConnectionException($master)));
+        $master
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdSet)
+            ->will($this->throwException(
+                new Connection\ConnectionException($master)
+            ));
 
         $slave1 = $this->getMockConnection('tcp://host2?alias=slave1');
-        $slave1->expects($this->never())
-               ->method('executeCommand');
+        $slave1
+            ->expects($this->never())
+            ->method('executeCommand');
 
         $replication = new MasterSlaveReplication();
 
@@ -764,6 +863,7 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $cmd = $this->getCommandFactory()->createCommand('info');
 
         $replication = new MasterSlaveReplication();
+
         $replication->add($this->getMockConnection('tcp://host1?alias=master'));
         $replication->add($this->getMockConnection('tcp://host2?alias=slave1'));
 
@@ -780,12 +880,19 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $cmdGet = $commands->createCommand('get', array('foo'));
 
         $master = $this->getMockConnection('tcp://host1?alias=master');
-        $master->expects($this->once())->method('executeCommand')->with($cmdGet);
+        $master
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdGet);
 
         $slave1 = $this->getMockConnection('tcp://host2?alias=slave1');
-        $slave1->expects($this->once())->method('executeCommand')->with($cmdSet);
+        $slave1
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdSet);
 
         $replication = new MasterSlaveReplication();
+
         $replication->add($master);
         $replication->add($slave1);
 
@@ -806,20 +913,29 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $cmdExistsBar = $commands->createCommand('exists', array('bar'));
 
         $master = $this->getMockConnection('tcp://host1?alias=master');
-        $master->expects($this->once())->method('executeCommand')->with($cmdExistsBar);
+        $master
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdExistsBar);
 
         $slave1 = $this->getMockConnection('tcp://host2?alias=slave1');
-        $slave1->expects($this->once())->method('executeCommand')->with($cmdExistsFoo);
+        $slave1
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdExistsFoo);
 
         $replication = new MasterSlaveReplication();
+
         $replication->add($master);
         $replication->add($slave1);
 
-        $replication->getReplicationStrategy()->setCommandReadOnly('exists', function ($cmd) {
-            list($arg1) = $cmd->getArguments();
+        $replication
+            ->getReplicationStrategy()
+            ->setCommandReadOnly('exists', function ($cmd) {
+                list($arg1) = $cmd->getArguments();
 
-            return $arg1 === 'foo';
-        });
+                return $arg1 === 'foo';
+            });
 
         $replication->executeCommand($cmdExistsFoo);
         $replication->executeCommand($cmdExistsBar);
@@ -836,18 +952,26 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $cmdEvalSha = $commands->createCommand('evalsha', array($scriptSHA1 = sha1($script)));
 
         $master = $this->getMockConnection('tcp://host1?alias=master');
-        $master->expects($this->never())->method('executeCommand');
+        $master
+            ->expects($this->never())
+            ->method('executeCommand');
 
         $slave1 = $this->getMockConnection('tcp://host2?alias=slave1');
-        $slave1->expects($this->exactly(2))
-               ->method('executeCommand')
-               ->with($this->logicalOr($cmdEval, $cmdEvalSha));
+        $slave1
+            ->expects($this->exactly(2))
+            ->method('executeCommand')
+            ->with(
+                $this->logicalOr($cmdEval, $cmdEvalSha)
+            );
 
         $replication = new MasterSlaveReplication();
+
         $replication->add($master);
         $replication->add($slave1);
 
-        $replication->getReplicationStrategy()->setScriptReadOnly($script);
+        $replication
+            ->getReplicationStrategy()
+            ->setScriptReadOnly($script);
 
         $replication->executeCommand($cmdEval);
         $replication->executeCommand($cmdEvalSha);
@@ -860,10 +984,9 @@ class MasterSlaveReplicationTest extends PredisTestCase
      */
     public function testDiscoveryRequiresConnectionFactory()
     {
-        $master = $this->getMockConnection('tcp://host1?alias=master');
-
         $replication = new MasterSlaveReplication();
-        $replication->add($master);
+
+        $replication->add($this->getMockConnection('tcp://host1?alias=master'));
 
         $replication->discover();
     }
@@ -877,10 +1000,11 @@ class MasterSlaveReplicationTest extends PredisTestCase
         $cmdInfo = Command\RawCommand::create('INFO', 'REPLICATION');
 
         $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master');
-        $master->expects($this->once())
-               ->method('executeCommand')
-               ->with($cmdInfo)
-               ->will($this->returnValue('
+        $master
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdInfo)
+            ->will($this->returnValue('
 # Replication
 role:master
 connected_slaves:2
@@ -891,7 +1015,8 @@ repl_backlog_active:1
 repl_backlog_size:1048576
 repl_backlog_first_byte_offset:2
 repl_backlog_histlen:12978
-'));
+'
+            ));
 
         $replication = new MasterSlaveReplication();
         $replication->setConnectionFactory($connFactory);
@@ -920,23 +1045,37 @@ repl_backlog_histlen:12978
         $slave2 = $this->getMockConnection('tcp://127.0.0.1:6383?alias=slave2');
 
         $connFactory = $this->getMock('Predis\Connection\Factory');
-        $connFactory->expects($this->at(0))
-                    ->method('create')
-                    ->with(array('host' => '127.0.0.1', 'port' => '6381', 'alias' => 'master'))
-                    ->will($this->returnValue($master));
-        $connFactory->expects($this->at(1))
-                    ->method('create')
-                    ->with(array('host' => '127.0.0.1', 'port' => '6382'))
-                    ->will($this->returnValue($slave1));
-        $connFactory->expects($this->at(2))
-                    ->method('create')
-                    ->with(array('host' => '127.0.0.1', 'port' => '6383'))
-                    ->will($this->returnValue($slave2));
-
-        $slave1->expects($this->once())
-               ->method('executeCommand')
-               ->with($cmdInfo)
-               ->will($this->returnValue('
+        $connFactory
+            ->expects($this->at(0))
+            ->method('create')
+            ->with(array(
+                'host' => '127.0.0.1',
+                'port' => '6381',
+                'alias' => 'master',
+            ))
+            ->will($this->returnValue($master));
+        $connFactory
+            ->expects($this->at(1))
+            ->method('create')
+            ->with(array(
+                'host' => '127.0.0.1',
+                'port' => '6382',
+            ))
+            ->will($this->returnValue($slave1));
+        $connFactory
+            ->expects($this->at(2))
+            ->method('create')
+            ->with(array(
+                'host' => '127.0.0.1',
+                'port' => '6383',
+            ))
+            ->will($this->returnValue($slave2));
+
+        $slave1
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdInfo)
+            ->will($this->returnValue('
 # Replication
 role:slave
 master_host:127.0.0.1
@@ -953,12 +1092,14 @@ repl_backlog_active:0
 repl_backlog_size:1048576
 repl_backlog_first_byte_offset:0
 repl_backlog_histlen:0
-'));
-
-        $master->expects($this->once())
-               ->method('executeCommand')
-               ->with($cmdInfo)
-               ->will($this->returnValue('
+'
+            ));
+
+        $master
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdInfo)
+            ->will($this->returnValue('
 # Replication
 role:master
 connected_slaves:2
@@ -969,7 +1110,8 @@ repl_backlog_active:1
 repl_backlog_size:1048576
 repl_backlog_first_byte_offset:2
 repl_backlog_histlen:12978
-'));
+'
+            ));
 
         $replication = new MasterSlaveReplication();
         $replication->setConnectionFactory($connFactory);
@@ -999,28 +1141,45 @@ repl_backlog_histlen:12978
         $slave2 = $this->getMockConnection('tcp://127.0.0.1:6383?alias=slave2');
 
         $connFactory = $this->getMock('Predis\Connection\Factory');
-        $connFactory->expects($this->at(0))
-                    ->method('create')
-                    ->with(array('host' => '127.0.0.1', 'port' => '6381', 'alias' => 'master'))
-                    ->will($this->returnValue($master));
-        $connFactory->expects($this->at(1))
-                    ->method('create')
-                    ->with(array('host' => '127.0.0.1', 'port' => '6382'))
-                    ->will($this->returnValue($slave1));
-        $connFactory->expects($this->at(2))
-                    ->method('create')
-                    ->with(array('host' => '127.0.0.1', 'port' => '6383'))
-                    ->will($this->returnValue($slave2));
-
-        $masterKO->expects($this->once())
-               ->method('executeCommand')
-               ->with($cmdInfo)
-               ->will($this->throwException(new Connection\ConnectionException($masterKO)));
-
-        $slave1->expects($this->once())
-               ->method('executeCommand')
-               ->with($cmdInfo)
-               ->will($this->returnValue('
+        $connFactory
+            ->expects($this->at(0))
+            ->method('create')
+            ->with(array(
+                'host' => '127.0.0.1',
+                'port' => '6381',
+                'alias' => 'master',
+            ))
+            ->will($this->returnValue($master));
+        $connFactory
+            ->expects($this->at(1))
+            ->method('create')
+            ->with(array(
+                'host' => '127.0.0.1',
+                'port' => '6382',
+            ))
+            ->will($this->returnValue($slave1));
+        $connFactory
+            ->expects($this->at(2))
+            ->method('create')
+            ->with(array(
+                'host' => '127.0.0.1',
+                'port' => '6383',
+            ))
+            ->will($this->returnValue($slave2));
+
+        $masterKO
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdInfo)
+            ->will($this->throwException(
+                new Connection\ConnectionException($masterKO)
+            ));
+
+        $slave1
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdInfo)
+            ->will($this->returnValue('
 # Replication
 role:slave
 master_host:127.0.0.1
@@ -1037,12 +1196,14 @@ repl_backlog_active:0
 repl_backlog_size:1048576
 repl_backlog_first_byte_offset:0
 repl_backlog_histlen:0
-'));
-
-        $master->expects($this->once())
-               ->method('executeCommand')
-               ->with($cmdInfo)
-               ->will($this->returnValue('
+'
+            ));
+
+        $master
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdInfo)
+            ->will($this->returnValue('
 # Replication
 role:master
 connected_slaves:2
@@ -1053,7 +1214,8 @@ repl_backlog_active:1
 repl_backlog_size:1048576
 repl_backlog_first_byte_offset:2
 repl_backlog_histlen:12978
-'));
+'
+            ));
 
         $replication = new MasterSlaveReplication();
         $replication->setConnectionFactory($connFactory);
@@ -1081,6 +1243,7 @@ repl_backlog_histlen:12978
         $master = $this->getMockConnection('tcp://host1?alias=master');
 
         $replication = new MasterSlaveReplication();
+
         $replication->add($master);
 
         $replication->setAutoDiscovery(true);
@@ -1099,25 +1262,34 @@ repl_backlog_histlen:12978
         $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1');
 
         $connFactory = $this->getMock('Predis\Connection\Factory');
-        $connFactory->expects($this->once())
-                    ->method('create')
-                    ->with(array('host' => '127.0.0.1', 'port' => '6382'))
-                    ->will($this->returnValue($slave1));
-
-        $slaveKO->expects($this->once())
-                ->method('executeCommand')
-                ->with($cmdExists)
-                ->will($this->throwException(new Connection\ConnectionException($slaveKO)));
-
-        $slave1->expects($this->once())
-               ->method('executeCommand')
-               ->with($cmdExists)
-               ->will($this->returnValue(1));
-
-        $master->expects($this->once())
-               ->method('executeCommand')
-               ->with($cmdInfo)
-               ->will($this->returnValue('
+        $connFactory
+            ->expects($this->once())
+            ->method('create')
+            ->with(array(
+                'host' => '127.0.0.1',
+                'port' => '6382',
+            ))
+            ->will($this->returnValue($slave1));
+
+        $slaveKO
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdExists)
+            ->will($this->throwException(
+                new Connection\ConnectionException($slaveKO)
+            ));
+
+        $slave1
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdExists)
+            ->will($this->returnValue(1));
+
+        $master
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdInfo)
+            ->will($this->returnValue('
 # Replication
 role:master
 connected_slaves:2
@@ -1127,7 +1299,8 @@ repl_backlog_active:1
 repl_backlog_size:1048576
 repl_backlog_first_byte_offset:2
 repl_backlog_histlen:12978
-'));
+'
+            ));
 
         $replication = new MasterSlaveReplication();
         $replication->setConnectionFactory($connFactory);
@@ -1149,6 +1322,7 @@ repl_backlog_histlen:12978
 
         $strategy = new ReplicationStrategy();
         $replication = new MasterSlaveReplication($strategy);
+
         $this->assertSame($strategy, $replication->getReplicationStrategy());
     }
 
@@ -1161,6 +1335,7 @@ repl_backlog_histlen:12978
         $slave1 = $this->getMockConnection('tcp://host2?alias=slave1');
 
         $replication = new MasterSlaveReplication();
+
         $replication->add($master);
         $replication->add($slave1);
 

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 449 - 367
tests/Predis/Connection/Replication/SentinelReplicationTest.php


+ 11 - 10
tests/Predis/Connection/StreamConnectionTest.php

@@ -30,16 +30,17 @@ class StreamConnectionTest extends PredisConnectionTestCase
     {
         $cmdSelect = RawCommand::create('SELECT', '1000');
 
-        $connection = $this->getMockBuilder(static::CONNECTION_CLASS)
-                           ->setMethods(array('executeCommand', 'createResource'))
-                           ->setConstructorArgs(array(new Parameters()))
-                           ->getMock();
-
-        $connection->method('executeCommand')
-                   ->with($cmdSelect)
-                   ->will($this->returnValue(
-                       new ErrorResponse('ERR invalid DB index')
-                   ));
+        $connection = $this
+            ->getMockBuilder(static::CONNECTION_CLASS)
+            ->setMethods(array('executeCommand', 'createResource'))
+            ->setConstructorArgs(array(new Parameters()))
+            ->getMock();
+        $connection
+            ->method('executeCommand')
+            ->with($cmdSelect)
+            ->will($this->returnValue(
+                new ErrorResponse('ERR invalid DB index')
+            ));
 
         $connection->method('createResource');
 

+ 34 - 22
tests/Predis/Monitor/ConsumerTest.php

@@ -28,10 +28,11 @@ class ConsumerTest extends PredisTestCase
     public function testMonitorConsumerRequireMonitorCommand()
     {
         $commands = $this->getMock('Predis\Command\FactoryInterface');
-        $commands->expects($this->once())
-                 ->method('supportsCommand')
-                 ->with('MONITOR')
-                 ->will($this->returnValue(false));
+        $commands
+            ->expects($this->once())
+            ->method('supportsCommand')
+            ->with('MONITOR')
+            ->will($this->returnValue(false));
 
         $client = new Client(null, array('commands' => $commands));
 
@@ -57,17 +58,18 @@ class ConsumerTest extends PredisTestCase
     public function testConstructorStartsConsumer()
     {
         $cmdMonitor = $this->getCommandFactory()->createCommand('monitor');
-
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
 
         $client = $this->getMock('Predis\Client', array('createCommand', 'executeCommand'), array($connection));
-        $client->expects($this->once())
-               ->method('createCommand')
-               ->with('MONITOR', array())
-               ->will($this->returnValue($cmdMonitor));
-        $client->expects($this->once())
-               ->method('executeCommand')
-               ->with($cmdMonitor);
+        $client
+            ->expects($this->once())
+            ->method('createCommand')
+            ->with('MONITOR', array())
+            ->will($this->returnValue($cmdMonitor));
+        $client
+            ->expects($this->once())
+            ->method('executeCommand')
+            ->with($cmdMonitor);
 
         new MonitorConsumer($client);
     }
@@ -84,9 +86,12 @@ class ConsumerTest extends PredisTestCase
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
 
         $client = $this->getMock('Predis\Client', array('disconnect'), array($connection));
-        $client->expects($this->exactly(2))->method('disconnect');
+        $client
+            ->expects($this->exactly(2))
+            ->method('disconnect');
 
         $monitor = new MonitorConsumer($client);
+
         $monitor->stop();
     }
 
@@ -98,9 +103,12 @@ class ConsumerTest extends PredisTestCase
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
 
         $client = $this->getMock('Predis\Client', array('disconnect'), array($connection));
-        $client->expects($this->once())->method('disconnect');
+        $client
+            ->expects($this->once())
+            ->method('disconnect');
 
         $monitor = new MonitorConsumer($client);
+
         unset($monitor);
     }
 
@@ -112,14 +120,16 @@ class ConsumerTest extends PredisTestCase
         $message = '1323367530.939137 (db 15) "MONITOR"';
 
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->once())
-                   ->method('read')
-                   ->will($this->returnValue($message));
+        $connection
+            ->expects($this->once())
+            ->method('read')
+            ->will($this->returnValue($message));
 
         $client = new Client($connection);
-        $monitor = new MonitorConsumer($client);
 
+        $monitor = new MonitorConsumer($client);
         $payload = $monitor->current();
+
         $this->assertSame(1323367530, (int) $payload->timestamp);
         $this->assertSame(15, $payload->database);
         $this->assertNull($payload->client);
@@ -135,14 +145,16 @@ class ConsumerTest extends PredisTestCase
         $message = '1323367530.939137 [15 127.0.0.1:37265] "MONITOR"';
 
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->once())
-                   ->method('read')
-                   ->will($this->returnValue($message));
+        $connection
+            ->expects($this->once())
+            ->method('read')
+            ->will($this->returnValue($message));
 
         $client = new Client($connection);
-        $monitor = new MonitorConsumer($client);
 
+        $monitor = new MonitorConsumer($client);
         $payload = $monitor->current();
+
         $this->assertSame(1323367530, (int) $payload->timestamp);
         $this->assertSame(15, $payload->database);
         $this->assertSame('127.0.0.1:37265', $payload->client);

+ 40 - 29
tests/Predis/Pipeline/AtomicTest.php

@@ -29,14 +29,17 @@ class AtomicTest extends PredisTestCase
         $queued = new Response\Status('QUEUED');
 
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->exactly(2))
-                   ->method('executeCommand')
-                   ->will($this->onConsecutiveCalls(true, array($pong, $pong, $pong)));
-        $connection->expects($this->exactly(3))
-                   ->method('writeRequest');
-        $connection->expects($this->at(3))
-                   ->method('readResponse')
-                   ->will($this->onConsecutiveCalls($queued, $queued, $queued));
+        $connection
+            ->expects($this->exactly(2))
+            ->method('executeCommand')
+            ->will($this->onConsecutiveCalls(true, array($pong, $pong, $pong)));
+        $connection
+            ->expects($this->exactly(3))
+            ->method('writeRequest');
+        $connection
+            ->expects($this->at(3))
+            ->method('readResponse')
+            ->will($this->onConsecutiveCalls($queued, $queued, $queued));
 
         $pipeline = new Atomic(new Client($connection));
 
@@ -55,9 +58,10 @@ class AtomicTest extends PredisTestCase
     public function testThrowsExceptionOnAbortedTransaction()
     {
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->exactly(2))
-                   ->method('executeCommand')
-                   ->will($this->onConsecutiveCalls(true, null));
+        $connection
+            ->expects($this->exactly(2))
+            ->method('executeCommand')
+            ->will($this->onConsecutiveCalls(true, null));
 
         $pipeline = new Atomic(new Client($connection));
 
@@ -79,15 +83,18 @@ class AtomicTest extends PredisTestCase
         $error = new Response\Error('ERR Test error');
 
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->at(0))
-                   ->method('executeCommand')
-                   ->will($this->returnValue(true));
-        $connection->expects($this->exactly(3))
-                   ->method('readResponse')
-                   ->will($this->onConsecutiveCalls($queued, $queued, $error));
-        $connection->expects($this->at(7))
-                   ->method('executeCommand')
-                   ->with($this->isRedisCommand('DISCARD'));
+        $connection
+            ->expects($this->at(0))
+            ->method('executeCommand')
+            ->will($this->returnValue(true));
+        $connection
+            ->expects($this->exactly(3))
+            ->method('readResponse')
+            ->will($this->onConsecutiveCalls($queued, $queued, $error));
+        $connection
+            ->expects($this->at(7))
+            ->method('executeCommand')
+            ->with($this->isRedisCommand('DISCARD'));
 
         $pipeline = new Atomic(new Client($connection));
 
@@ -108,9 +115,10 @@ class AtomicTest extends PredisTestCase
         $error = new Response\Error('ERR Test error');
 
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->once())
-                   ->method('readResponse')
-                   ->will($this->returnValue($error));
+        $connection
+            ->expects($this->once())
+            ->method('readResponse')
+            ->will($this->returnValue($error));
 
         $pipeline = new Atomic(new Client($connection));
 
@@ -130,12 +138,14 @@ class AtomicTest extends PredisTestCase
         $error = new Response\Error('ERR Test error');
 
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->exactly(3))
-                   ->method('readResponse')
-                   ->will($this->onConsecutiveCalls($queued, $queued, $queued));
-        $connection->expects($this->at(7))
-                   ->method('executeCommand')
-                   ->will($this->returnValue(array($pong, $pong, $error)));
+        $connection
+            ->expects($this->exactly(3))
+            ->method('readResponse')
+            ->will($this->onConsecutiveCalls($queued, $queued, $queued));
+        $connection
+            ->expects($this->at(7))
+            ->method('executeCommand')
+            ->will($this->returnValue(array($pong, $pong, $error)));
 
         $pipeline = new Atomic(new Client($connection, array('exceptions' => false)));
 
@@ -154,6 +164,7 @@ class AtomicTest extends PredisTestCase
     public function testExecutorWithAggregateConnection()
     {
         $connection = $this->getMock('Predis\Connection\AggregateConnectionInterface');
+
         $pipeline = new Atomic(new Client($connection));
 
         $pipeline->ping();

+ 15 - 8
tests/Predis/Pipeline/FireAndForgetTest.php

@@ -25,8 +25,12 @@ class FireAndForgetTest extends PredisTestCase
     public function testPipelineWithSingleConnection()
     {
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->exactly(3))->method('writeRequest');
-        $connection->expects($this->never())->method('readResponse');
+        $connection
+            ->expects($this->exactly(3))
+            ->method('writeRequest');
+        $connection
+            ->expects($this->never())
+            ->method('readResponse');
 
         $pipeline = new FireAndForget(new Client($connection));
 
@@ -43,12 +47,15 @@ class FireAndForgetTest extends PredisTestCase
     public function testSwitchesToMasterWithReplicationConnection()
     {
         $connection = $this->getMock('Predis\Connection\Replication\ReplicationInterface');
-        $connection->expects($this->once())
-                   ->method('switchToMaster');
-        $connection->expects($this->exactly(3))
-                   ->method('writeRequest');
-        $connection->expects($this->never())
-                   ->method('readResponse');
+        $connection
+            ->expects($this->once())
+            ->method('switchToMaster');
+        $connection
+            ->expects($this->exactly(3))
+            ->method('writeRequest');
+        $connection
+            ->expects($this->never())
+            ->method('readResponse');
 
         $pipeline = new FireAndForget(new Client($connection));
 

+ 84 - 53
tests/Predis/Pipeline/PipelineTest.php

@@ -38,8 +38,12 @@ class PipelineTest extends PredisTestCase
     public function testCallDoesNotSendCommandsWithoutExecute()
     {
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->never())->method('writeRequest');
-        $connection->expects($this->never())->method('readResponse');
+        $connection
+            ->expects($this->never())
+            ->method('writeRequest');
+        $connection
+            ->expects($this->never())
+            ->method('readResponse');
 
         $pipeline = new Pipeline(new Client($connection));
 
@@ -54,8 +58,12 @@ class PipelineTest extends PredisTestCase
     public function testCallReturnsPipelineForFluentInterface()
     {
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->never())->method('writeRequest');
-        $connection->expects($this->never())->method('readResponse');
+        $connection
+            ->expects($this->never())
+            ->method('writeRequest');
+        $connection
+            ->expects($this->never())
+            ->method('readResponse');
 
         $pipeline = new Pipeline(new Client($connection));
 
@@ -71,9 +79,10 @@ class PipelineTest extends PredisTestCase
         $object = $this->getMock('Predis\Response\ResponseInterface');
 
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->once())
-                   ->method('readResponse')
-                   ->will($this->returnValue($object));
+        $connection
+            ->expects($this->once())
+            ->method('readResponse')
+            ->will($this->returnValue($object));
 
         $pipeline = new Pipeline(new Client($connection));
 
@@ -92,9 +101,10 @@ class PipelineTest extends PredisTestCase
         $error = new Response\Error('ERR Test error');
 
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->once())
-                   ->method('readResponse')
-                   ->will($this->returnValue($error));
+        $connection
+            ->expects($this->once())
+            ->method('readResponse')
+            ->will($this->returnValue($error));
 
         $pipeline = new Pipeline(new Client($connection));
 
@@ -112,9 +122,10 @@ class PipelineTest extends PredisTestCase
         $error = $this->getMock('Predis\Response\ErrorInterface');
 
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->exactly(2))
-                   ->method('readResponse')
-                   ->will($this->returnValue($error));
+        $connection
+            ->expects($this->exactly(2))
+            ->method('readResponse')
+            ->will($this->returnValue($error));
 
         $client = new Client($connection, array('exceptions' => false));
 
@@ -131,10 +142,10 @@ class PipelineTest extends PredisTestCase
      */
     public function testExecuteReturnsPipelineForFluentInterface()
     {
-        $commands = $this->getCommandFactory();
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
+        $command = $this->getCommandFactory()->createCommand('echo', array('one'));
+
         $pipeline = new Pipeline(new Client($connection));
-        $command = $commands->createCommand('echo', array('one'));
 
         $this->assertSame($pipeline, $pipeline->executeCommand($command));
     }
@@ -144,11 +155,15 @@ class PipelineTest extends PredisTestCase
      */
     public function testExecuteCommandDoesNotSendCommandsWithoutExecute()
     {
-        $commands = $this->getCommandFactory();
-
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->never())->method('writeRequest');
-        $connection->expects($this->never())->method('readResponse');
+        $connection
+            ->expects($this->never())
+            ->method('writeRequest');
+        $connection
+            ->expects($this->never())
+            ->method('readResponse');
+
+        $commands = $this->getCommandFactory();
 
         $pipeline = new Pipeline(new Client($connection));
 
@@ -163,8 +178,12 @@ class PipelineTest extends PredisTestCase
     public function testExecuteWithEmptyBuffer()
     {
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->never())->method('writeRequest');
-        $connection->expects($this->never())->method('readResponse');
+        $connection
+            ->expects($this->never())
+            ->method('writeRequest');
+        $connection
+            ->expects($this->never())
+            ->method('readResponse');
 
         $pipeline = new Pipeline(new Client($connection));
 
@@ -177,11 +196,13 @@ class PipelineTest extends PredisTestCase
     public function testExecuteWithFilledBuffer()
     {
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->exactly(3))
-                   ->method('writeRequest');
-        $connection->expects($this->exactly(3))
-                   ->method('readResponse')
-                   ->will($this->returnCallback($this->getReadCallback()));
+        $connection
+            ->expects($this->exactly(3))
+            ->method('writeRequest');
+        $connection
+            ->expects($this->exactly(3))
+            ->method('readResponse')
+            ->will($this->returnCallback($this->getReadCallback()));
 
         $pipeline = new Pipeline(new Client($connection));
 
@@ -216,11 +237,13 @@ class PipelineTest extends PredisTestCase
     public function testFlushHandlesPartialBuffers()
     {
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->exactly(4))
-                   ->method('writeRequest');
-        $connection->expects($this->exactly(4))
-                   ->method('readResponse')
-                   ->will($this->returnCallback($this->getReadCallback()));
+        $connection
+            ->expects($this->exactly(4))
+            ->method('writeRequest');
+        $connection
+            ->expects($this->exactly(4))
+            ->method('readResponse')
+            ->will($this->returnCallback($this->getReadCallback()));
 
         $pipeline = new Pipeline(new Client($connection));
 
@@ -241,13 +264,16 @@ class PipelineTest extends PredisTestCase
         $pong = new Response\Status('PONG');
 
         $connection = $this->getMock('Predis\Connection\Replication\ReplicationInterface');
-        $connection->expects($this->once())
-                   ->method('switchToMaster');
-        $connection->expects($this->exactly(3))
-                   ->method('writeRequest');
-        $connection->expects($this->exactly(3))
-                   ->method('readResponse')
-                   ->will($this->returnValue($pong));
+        $connection
+            ->expects($this->once())
+            ->method('switchToMaster');
+        $connection
+            ->expects($this->exactly(3))
+            ->method('writeRequest');
+        $connection
+            ->expects($this->exactly(3))
+            ->method('readResponse')
+            ->will($this->returnValue($pong));
 
         $pipeline = new Pipeline(new Client($connection));
 
@@ -305,11 +331,13 @@ class PipelineTest extends PredisTestCase
     public function testExecuteWithCallableArgumentRunsPipelineInCallable()
     {
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->exactly(4))
-                   ->method('writeRequest');
-        $connection->expects($this->exactly(4))
-                   ->method('readResponse')
-                   ->will($this->returnCallback($this->getReadCallback()));
+        $connection
+            ->expects($this->exactly(4))
+            ->method('writeRequest');
+        $connection
+            ->expects($this->exactly(4))
+            ->method('readResponse')
+            ->will($this->returnCallback($this->getReadCallback()));
 
         $pipeline = new Pipeline(new Client($connection));
 
@@ -328,17 +356,19 @@ class PipelineTest extends PredisTestCase
      */
     public function testExecuteWithCallableArgumentHandlesExceptions()
     {
-        $exception = null;
-
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->never())->method('writeRequest');
-        $connection->expects($this->never())->method('readResponse');
-
-        $pipeline = new Pipeline(new Client($connection));
+        $connection
+            ->expects($this->never())
+            ->method('writeRequest');
+        $connection
+            ->expects($this->never())
+            ->method('readResponse');
 
         $exception = null;
         $responses = null;
 
+        $pipeline = new Pipeline(new Client($connection));
+
         try {
             $responses = $pipeline->execute(function ($pipe) {
                 $pipe->echo('one');
@@ -365,10 +395,11 @@ class PipelineTest extends PredisTestCase
     {
         $pipeline = $this->getClient()->pipeline();
 
-        $results = $pipeline->echo('one')
-                            ->echo('two')
-                            ->echo('three')
-                            ->execute();
+        $results = $pipeline
+            ->echo('one')
+            ->echo('two')
+            ->echo('three')
+            ->execute();
 
         $this->assertSame(array('one', 'two', 'three'), $results);
     }

+ 16 - 17
tests/Predis/Protocol/Text/CompositeProtocolProcessorTest.php

@@ -25,12 +25,8 @@ class CompositeProtocolProcessorTest extends PredisTestCase
     {
         $protocol = new CompositeProtocolProcessor();
 
-        $this->assertInstanceOf(
-            'Predis\Protocol\Text\RequestSerializer', $protocol->getRequestSerializer()
-        );
-        $this->assertInstanceOf(
-            'Predis\Protocol\Text\ResponseReader', $protocol->getResponseReader()
-        );
+        $this->assertInstanceOf('Predis\Protocol\Text\RequestSerializer', $protocol->getRequestSerializer());
+        $this->assertInstanceOf('Predis\Protocol\Text\ResponseReader', $protocol->getResponseReader());
     }
 
     /**
@@ -86,14 +82,16 @@ class CompositeProtocolProcessorTest extends PredisTestCase
 
         $protocol = new CompositeProtocolProcessor($serializer);
 
-        $connection->expects($this->once())
-                   ->method('writeBuffer')
-                   ->with($this->equalTo($serialized));
+        $connection
+            ->expects($this->once())
+            ->method('writeBuffer')
+            ->with($this->equalTo($serialized));
 
-        $serializer->expects($this->once())
-                   ->method('serialize')
-                   ->with($command)
-                   ->will($this->returnValue($serialized));
+        $serializer
+            ->expects($this->once())
+            ->method('serialize')
+            ->with($command)
+            ->will($this->returnValue($serialized));
 
         $protocol->write($connection, $command);
     }
@@ -108,10 +106,11 @@ class CompositeProtocolProcessorTest extends PredisTestCase
 
         $protocol = new CompositeProtocolProcessor(null, $reader);
 
-        $reader->expects($this->once())
-                   ->method('read')
-                   ->with($connection)
-                   ->will($this->returnValue('bulk'));
+        $reader
+            ->expects($this->once())
+            ->method('read')
+            ->with($connection)
+            ->will($this->returnValue('bulk'));
 
         $this->assertSame('bulk', $protocol->read($connection));
     }

+ 39 - 26
tests/Predis/Protocol/Text/Handler/BulkResponseTest.php

@@ -23,15 +23,17 @@ class BulkResponseTest extends PredisTestCase
      */
     public function testZeroLengthBulk()
     {
-        $handler = new Handler\BulkResponse();
-
         $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface');
+        $connection
+            ->expects($this->never())
+            ->method('readLine');
+        $connection
+            ->expects($this->once())
+            ->method('readBuffer')
+            ->with($this->equalTo(2))
+            ->will($this->returnValue("\r\n"));
 
-        $connection->expects($this->never())->method('readLine');
-        $connection->expects($this->once())
-                   ->method('readBuffer')
-                   ->with($this->equalTo(2))
-                   ->will($this->returnValue("\r\n"));
+        $handler = new Handler\BulkResponse();
 
         $this->assertSame('', $handler->handle($connection, '0'));
     }
@@ -44,15 +46,17 @@ class BulkResponseTest extends PredisTestCase
         $bulk = 'This is a bulk string.';
         $bulkLengh = strlen($bulk);
 
-        $handler = new Handler\BulkResponse();
-
         $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface');
+        $connection
+            ->expects($this->never())
+            ->method('readLine');
+        $connection
+            ->expects($this->once())
+            ->method('readBuffer')
+            ->with($this->equalTo($bulkLengh + 2))
+            ->will($this->returnValue("$bulk\r\n"));
 
-        $connection->expects($this->never())->method('readLine');
-        $connection->expects($this->once())
-                   ->method('readBuffer')
-                   ->with($this->equalTo($bulkLengh + 2))
-                   ->will($this->returnValue("$bulk\r\n"));
+        $handler = new Handler\BulkResponse();
 
         $this->assertSame($bulk, $handler->handle($connection, (string) $bulkLengh));
     }
@@ -62,12 +66,15 @@ class BulkResponseTest extends PredisTestCase
      */
     public function testNull()
     {
-        $handler = new Handler\BulkResponse();
-
         $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface');
+        $connection
+            ->expects($this->never())
+            ->method('readLine');
+        $connection
+            ->expects($this->never())
+            ->method('readBuffer');
 
-        $connection->expects($this->never())->method('readLine');
-        $connection->expects($this->never())->method('readBuffer');
+        $handler = new Handler\BulkResponse();
 
         $this->assertNull($handler->handle($connection, '-1'));
     }
@@ -79,12 +86,15 @@ class BulkResponseTest extends PredisTestCase
      */
     public function testInvalidLengthString()
     {
-        $handler = new Handler\BulkResponse();
-
         $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379');
+        $connection
+            ->expects($this->never())
+            ->method('readLine');
+        $connection
+            ->expects($this->never())
+            ->method('readBuffer');
 
-        $connection->expects($this->never())->method('readLine');
-        $connection->expects($this->never())->method('readBuffer');
+        $handler = new Handler\BulkResponse();
 
         $handler->handle($connection, 'invalid');
     }
@@ -96,12 +106,15 @@ class BulkResponseTest extends PredisTestCase
      */
     public function testInvalidLengthInteger()
     {
-        $handler = new Handler\BulkResponse();
-
         $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379');
+        $connection
+            ->expects($this->never())
+            ->method('readLine');
+        $connection
+            ->expects($this->never())
+            ->method('readBuffer');
 
-        $connection->expects($this->never())->method('readLine');
-        $connection->expects($this->never())->method('readBuffer');
+        $handler = new Handler\BulkResponse();
 
         $handler->handle($connection, '-5');
     }

+ 8 - 5
tests/Predis/Protocol/Text/Handler/ErrorResponseTest.php

@@ -23,14 +23,17 @@ class ErrorResponseTest extends PredisTestCase
      */
     public function testOk()
     {
-        $handler = new Handler\ErrorResponse();
+        $message = 'ERR Operation against a key holding the wrong kind of value';
 
         $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
+        $connection
+            ->expects($this->never())
+            ->method('readLine');
+        $connection
+            ->expects($this->never())
+            ->method('readBuffer');
 
-        $connection->expects($this->never())->method('readLine');
-        $connection->expects($this->never())->method('readBuffer');
-
-        $message = 'ERR Operation against a key holding the wrong kind of value';
+        $handler = new Handler\ErrorResponse();
         $response = $handler->handle($connection, $message);
 
         $this->assertInstanceOf('Predis\Response\Error', $response);

+ 21 - 12
tests/Predis/Protocol/Text/Handler/IntegerResponseTest.php

@@ -23,12 +23,15 @@ class IntegerResponseTest extends PredisTestCase
      */
     public function testInteger()
     {
-        $handler = new Handler\IntegerResponse();
-
         $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
+        $connection
+            ->expects($this->never())
+            ->method('readLine');
+        $connection
+            ->expects($this->never())
+            ->method('readBuffer');
 
-        $connection->expects($this->never())->method('readLine');
-        $connection->expects($this->never())->method('readBuffer');
+        $handler = new Handler\IntegerResponse();
 
         $this->assertSame(0, $handler->handle($connection, '0'));
         $this->assertSame(1, $handler->handle($connection, '1'));
@@ -41,12 +44,15 @@ class IntegerResponseTest extends PredisTestCase
      */
     public function testNull()
     {
-        $handler = new Handler\IntegerResponse();
-
         $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
+        $connection
+            ->expects($this->never())
+            ->method('readLine');
+        $connection
+            ->expects($this->never())
+            ->method('readBuffer');
 
-        $connection->expects($this->never())->method('readLine');
-        $connection->expects($this->never())->method('readBuffer');
+        $handler = new Handler\IntegerResponse();
 
         $this->assertNull($handler->handle($connection, 'nil'));
     }
@@ -58,12 +64,15 @@ class IntegerResponseTest extends PredisTestCase
      */
     public function testInvalid()
     {
-        $handler = new Handler\IntegerResponse();
-
         $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379');
+        $connection
+            ->expects($this->never())
+            ->method('readLine');
+        $connection
+            ->expects($this->never())
+            ->method('readBuffer');
 
-        $connection->expects($this->never())->method('readLine');
-        $connection->expects($this->never())->method('readBuffer');
+        $handler = new Handler\IntegerResponse();
 
         $handler->handle($connection, 'invalid');
     }

+ 35 - 29
tests/Predis/Protocol/Text/Handler/MultiBulkResponseTest.php

@@ -23,29 +23,29 @@ class MultiBulkResponseTest extends PredisTestCase
      */
     public function testMultiBulk()
     {
-        $handler = new Handler\MultiBulkResponse();
-
         $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
+        $connection
+            ->expects($this->once())
+            ->method('getProtocol')
+            ->will($this->returnValue(new CompositeProtocolProcessor()));
+        $connection
+            ->expects($this->at(1))
+            ->method('readLine')
+            ->will($this->returnValue('$3'));
+        $connection
+            ->expects($this->at(2))
+            ->method('readBuffer')
+            ->will($this->returnValue("foo\r\n"));
+        $connection
+            ->expects($this->at(3))
+            ->method('readLine')
+            ->will($this->returnValue('$3'));
+        $connection
+            ->expects($this->at(4))
+            ->method('readBuffer')
+            ->will($this->returnValue("bar\r\n"));
 
-        $connection->expects($this->once())
-                   ->method('getProtocol')
-                   ->will($this->returnValue(new CompositeProtocolProcessor()));
-
-        $connection->expects($this->at(1))
-                   ->method('readLine')
-                   ->will($this->returnValue('$3'));
-
-        $connection->expects($this->at(2))
-                   ->method('readBuffer')
-                   ->will($this->returnValue("foo\r\n"));
-
-        $connection->expects($this->at(3))
-                   ->method('readLine')
-                   ->will($this->returnValue('$3'));
-
-        $connection->expects($this->at(4))
-                   ->method('readBuffer')
-                   ->will($this->returnValue("bar\r\n"));
+        $handler = new Handler\MultiBulkResponse();
 
         $this->assertSame(array('foo', 'bar'), $handler->handle($connection, '2'));
     }
@@ -55,12 +55,15 @@ class MultiBulkResponseTest extends PredisTestCase
      */
     public function testNull()
     {
-        $handler = new Handler\MultiBulkResponse();
-
         $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
+        $connection
+            ->expects($this->never())
+            ->method('readLine');
+        $connection
+            ->expects($this->never())
+            ->method('readBuffer');
 
-        $connection->expects($this->never())->method('readLine');
-        $connection->expects($this->never())->method('readBuffer');
+        $handler = new Handler\MultiBulkResponse();
 
         $this->assertNull($handler->handle($connection, '-1'));
     }
@@ -72,12 +75,15 @@ class MultiBulkResponseTest extends PredisTestCase
      */
     public function testInvalid()
     {
-        $handler = new Handler\MultiBulkResponse();
-
         $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379');
+        $connection
+            ->expects($this->never())
+            ->method('readLine');
+        $connection
+            ->expects($this->never())
+            ->method('readBuffer');
 
-        $connection->expects($this->never())->method('readLine');
-        $connection->expects($this->never())->method('readBuffer');
+        $handler = new Handler\MultiBulkResponse();
 
         $handler->handle($connection, 'invalid');
     }

+ 21 - 15
tests/Predis/Protocol/Text/Handler/StatusResponseTest.php

@@ -23,13 +23,15 @@ class StatusResponseTest extends PredisTestCase
      */
     public function testOk()
     {
-        $handler = new Handler\StatusResponse();
-
         $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
+        $connection
+            ->expects($this->never())
+            ->method('readLine');
+        $connection
+            ->expects($this->never())
+            ->method('readBuffer');
 
-        $connection->expects($this->never())->method('readLine');
-        $connection->expects($this->never())->method('readBuffer');
-
+        $handler = new Handler\StatusResponse();
         $response = $handler->handle($connection, 'OK');
 
         $this->assertInstanceOf('Predis\Response\Status', $response);
@@ -41,13 +43,15 @@ class StatusResponseTest extends PredisTestCase
      */
     public function testQueued()
     {
-        $handler = new Handler\StatusResponse();
-
         $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
+        $connection
+            ->expects($this->never())
+            ->method('readLine');
+        $connection
+            ->expects($this->never())
+            ->method('readBuffer');
 
-        $connection->expects($this->never())->method('readLine');
-        $connection->expects($this->never())->method('readBuffer');
-
+        $handler = new Handler\StatusResponse();
         $response = $handler->handle($connection, 'QUEUED');
 
         $this->assertInstanceOf('Predis\Response\Status', $response);
@@ -59,13 +63,15 @@ class StatusResponseTest extends PredisTestCase
      */
     public function testPlainString()
     {
-        $handler = new Handler\StatusResponse();
-
         $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
+        $connection
+            ->expects($this->never())
+            ->method('readLine');
+        $connection
+            ->expects($this->never())
+            ->method('readBuffer');
 
-        $connection->expects($this->never())->method('readLine');
-        $connection->expects($this->never())->method('readBuffer');
-
+        $handler = new Handler\StatusResponse();
         $response = $handler->handle($connection, 'Background saving started');
 
         $this->assertInstanceOf('Predis\Response\Status', $response);

+ 14 - 8
tests/Predis/Protocol/Text/Handler/StreamableMultiBulkResponseTest.php

@@ -23,12 +23,15 @@ class StreamableMultiBulkResponseTest extends PredisTestCase
      */
     public function testOk()
     {
-        $handler = new Handler\StreamableMultiBulkResponse();
-
         $connection = $this->getMock('Predis\Connection\CompositeConnectionInterface');
+        $connection
+            ->expects($this->never())
+            ->method('readLine');
+        $connection
+            ->expects($this->never())
+            ->method('readBuffer');
 
-        $connection->expects($this->never())->method('readLine');
-        $connection->expects($this->never())->method('readBuffer');
+        $handler = new Handler\StreamableMultiBulkResponse();
 
         $this->assertInstanceOf('Predis\Response\Iterator\MultiBulk', $handler->handle($connection, '1'));
     }
@@ -40,12 +43,15 @@ class StreamableMultiBulkResponseTest extends PredisTestCase
      */
     public function testInvalid()
     {
-        $handler = new Handler\StreamableMultiBulkResponse();
-
         $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379');
+        $connection
+            ->expects($this->never())
+            ->method('readLine');
+        $connection
+            ->expects($this->never())
+            ->method('readBuffer');
 
-        $connection->expects($this->never())->method('readLine');
-        $connection->expects($this->never())->method('readBuffer');
+        $handler = new Handler\StreamableMultiBulkResponse();
 
         $handler->handle($connection, 'invalid');
     }

+ 40 - 40
tests/Predis/Protocol/Text/ProtocolProcessorTest.php

@@ -27,20 +27,20 @@ class ProtocolProcessorTest extends PredisTestCase
         $protocol = new ProtocolProcessor();
 
         $command = $this->getMock('Predis\Command\CommandInterface');
-
-        $command->expects($this->once())
-                ->method('getId')
-                ->will($this->returnValue('PING'));
-
-        $command->expects($this->once())
-                ->method('getArguments')
-                ->will($this->returnValue(array()));
+        $command
+            ->expects($this->once())
+            ->method('getId')
+            ->will($this->returnValue('PING'));
+        $command
+            ->expects($this->once())
+            ->method('getArguments')
+            ->will($this->returnValue(array()));
 
         $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface');
-
-        $connection->expects($this->once())
-                   ->method('writeBuffer')
-                   ->with($this->equalTo($serialized));
+        $connection
+            ->expects($this->once())
+            ->method('writeBuffer')
+            ->with($this->equalTo($serialized));
 
         $protocol->write($connection, $command);
     }
@@ -53,26 +53,26 @@ class ProtocolProcessorTest extends PredisTestCase
         $protocol = new ProtocolProcessor();
 
         $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface');
-
-        $connection->expects($this->at(0))
-                   ->method('readLine')
-                   ->will($this->returnValue('+OK'));
-
-        $connection->expects($this->at(1))
-                   ->method('readLine')
-                   ->will($this->returnValue('-ERR error message'));
-
-        $connection->expects($this->at(2))
-                   ->method('readLine')
-                   ->will($this->returnValue(':2'));
-
-        $connection->expects($this->at(3))
-                   ->method('readLine')
-                   ->will($this->returnValue('$-1'));
-
-        $connection->expects($this->at(4))
-                   ->method('readLine')
-                   ->will($this->returnValue('*-1'));
+        $connection
+            ->expects($this->at(0))
+            ->method('readLine')
+            ->will($this->returnValue('+OK'));
+        $connection
+            ->expects($this->at(1))
+            ->method('readLine')
+            ->will($this->returnValue('-ERR error message'));
+        $connection
+            ->expects($this->at(2))
+            ->method('readLine')
+            ->will($this->returnValue(':2'));
+        $connection
+            ->expects($this->at(3))
+            ->method('readLine')
+            ->will($this->returnValue('$-1'));
+        $connection
+            ->expects($this->at(4))
+            ->method('readLine')
+            ->will($this->returnValue('*-1'));
 
         $this->assertEquals('OK', $protocol->read($connection));
         $this->assertEquals('ERR error message', $protocol->read($connection));
@@ -90,10 +90,10 @@ class ProtocolProcessorTest extends PredisTestCase
         $protocol->useIterableMultibulk(true);
 
         $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface');
-
-        $connection->expects($this->once(4))
-                   ->method('readLine')
-                   ->will($this->returnValue('*1'));
+        $connection
+            ->expects($this->once(4))
+            ->method('readLine')
+            ->will($this->returnValue('*1'));
 
         $this->assertInstanceOf('Predis\Response\Iterator\MultiBulk', $protocol->read($connection));
     }
@@ -108,10 +108,10 @@ class ProtocolProcessorTest extends PredisTestCase
         $protocol = new ProtocolProcessor();
 
         $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379');
-
-        $connection->expects($this->once())
-                   ->method('readLine')
-                   ->will($this->returnValue('!'));
+        $connection
+            ->expects($this->once())
+            ->method('readLine')
+            ->will($this->returnValue('!'));
 
         $protocol->read($connection);
     }

+ 24 - 24
tests/Predis/Protocol/Text/RequestSerializerTest.php

@@ -26,14 +26,14 @@ class RequestSerializerTest extends PredisTestCase
         $serializer = new RequestSerializer();
 
         $command = $this->getMock('Predis\Command\CommandInterface');
-
-        $command->expects($this->once())
-                ->method('getId')
-                ->will($this->returnValue('PING'));
-
-        $command->expects($this->once())
-                ->method('getArguments')
-                ->will($this->returnValue(array()));
+        $command
+            ->expects($this->once())
+            ->method('getId')
+            ->will($this->returnValue('PING'));
+        $command
+            ->expects($this->once())
+            ->method('getArguments')
+            ->will($this->returnValue(array()));
 
         $result = $serializer->serialize($command);
 
@@ -48,14 +48,14 @@ class RequestSerializerTest extends PredisTestCase
         $serializer = new RequestSerializer();
 
         $command = $this->getMock('Predis\Command\CommandInterface');
-
-        $command->expects($this->once())
-                ->method('getId')
-                ->will($this->returnValue('SET'));
-
-        $command->expects($this->once())
-                ->method('getArguments')
-                ->will($this->returnValue(array('key', 'value')));
+        $command
+            ->expects($this->once())
+            ->method('getId')
+            ->will($this->returnValue('SET'));
+        $command
+            ->expects($this->once())
+            ->method('getArguments')
+            ->will($this->returnValue(array('key', 'value')));
 
         $result = $serializer->serialize($command);
 
@@ -70,14 +70,14 @@ class RequestSerializerTest extends PredisTestCase
         $serializer = new RequestSerializer();
 
         $command = $this->getMock('Predis\Command\CommandInterface');
-
-        $command->expects($this->once())
-                ->method('getId')
-                ->will($this->returnValue('DEL'));
-
-        $command->expects($this->once())
-                ->method('getArguments')
-                ->will($this->returnValue(array(0 => 'key:1', 2 => 'key:2')));
+        $command
+            ->expects($this->once())
+            ->method('getId')
+            ->will($this->returnValue('DEL'));
+        $command
+            ->expects($this->once())
+            ->method('getArguments')
+            ->will($this->returnValue(array(0 => 'key:1', 2 => 'key:2')));
 
         $result = $serializer->serialize($command);
 

+ 31 - 35
tests/Predis/Protocol/Text/ResponseReaderTest.php

@@ -52,32 +52,29 @@ class ResponseReaderTest extends PredisTestCase
      */
     public function testReadResponse()
     {
-        $reader = new ResponseReader();
-
-        $protocol = new CompositeProtocolProcessor();
-        $protocol->setResponseReader($reader);
-
         $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface');
+        $connection
+            ->expects($this->at(0))
+            ->method('readLine')
+            ->will($this->returnValue('+OK'));
+        $connection
+            ->expects($this->at(1))
+            ->method('readLine')
+            ->will($this->returnValue('-ERR error message'));
+        $connection
+            ->expects($this->at(2))
+            ->method('readLine')
+            ->will($this->returnValue(':2'));
+        $connection
+            ->expects($this->at(3))
+            ->method('readLine')
+            ->will($this->returnValue('$-1'));
+        $connection
+            ->expects($this->at(4))
+            ->method('readLine')
+            ->will($this->returnValue('*-1'));
 
-        $connection->expects($this->at(0))
-                   ->method('readLine')
-                   ->will($this->returnValue('+OK'));
-
-        $connection->expects($this->at(1))
-                   ->method('readLine')
-                   ->will($this->returnValue('-ERR error message'));
-
-        $connection->expects($this->at(2))
-                   ->method('readLine')
-                   ->will($this->returnValue(':2'));
-
-        $connection->expects($this->at(3))
-                   ->method('readLine')
-                   ->will($this->returnValue('$-1'));
-
-        $connection->expects($this->at(4))
-                   ->method('readLine')
-                   ->will($this->returnValue('*-1'));
+        $reader = new ResponseReader();
 
         $this->assertEquals('OK', $reader->read($connection));
         $this->assertEquals('ERR error message', $reader->read($connection));
@@ -93,14 +90,13 @@ class ResponseReaderTest extends PredisTestCase
      */
     public function testEmptyResponseHeader()
     {
-        $reader = new ResponseReader();
-
         $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379');
+        $connection
+            ->expects($this->once())
+            ->method('readLine')
+            ->will($this->returnValue(''));
 
-        $connection->expects($this->once())
-                   ->method('readLine')
-                   ->will($this->returnValue(''));
-
+        $reader = new ResponseReader();
         $reader->read($connection);
     }
     /**
@@ -110,14 +106,14 @@ class ResponseReaderTest extends PredisTestCase
      */
     public function testUnknownResponsePrefix()
     {
-        $reader = new ResponseReader();
 
         $connection = $this->getMockConnectionOfType('Predis\Connection\CompositeConnectionInterface', 'tcp://127.0.0.1:6379');
+        $connection
+            ->expects($this->once())
+            ->method('readLine')
+            ->will($this->returnValue('!'));
 
-        $connection->expects($this->once())
-                   ->method('readLine')
-                   ->will($this->returnValue('!'));
-
+        $reader = new ResponseReader();
         $reader->read($connection);
     }
 }

+ 49 - 23
tests/Predis/PubSub/ConsumerTest.php

@@ -28,9 +28,10 @@ class ConsumerTest extends PredisTestCase
     public function testPubSubConsumerRequirePubSubRelatedCommand()
     {
         $commands = $this->getMock('Predis\Command\FactoryInterface');
-        $commands->expects($this->any())
-                ->method('supportsCommands')
-                ->will($this->returnValue(false));
+        $commands
+            ->expects($this->any())
+            ->method('supportsCommands')
+            ->will($this->returnValue(false));
 
         $client = new Client(null, array('commands' => $commands));
 
@@ -74,12 +75,13 @@ class ConsumerTest extends PredisTestCase
         $connection->expects($this->exactly(2))->method('writeRequest');
 
         $client = $this->getMock('Predis\Client', array('createCommand', 'writeRequest'), array($connection));
-        $client->expects($this->exactly(2))
-               ->method('createCommand')
-               ->with($this->logicalOr($this->equalTo('subscribe'), $this->equalTo('psubscribe')))
-               ->will($this->returnCallback(function ($id, $args) use ($commands) {
-                   return $commands->createCommand($id, $args);
-               }));
+        $client
+            ->expects($this->exactly(2))
+            ->method('createCommand')
+            ->with($this->logicalOr($this->equalTo('subscribe'), $this->equalTo('psubscribe')))
+            ->will($this->returnCallback(function ($id, $args) use ($commands) {
+                return $commands->createCommand($id, $args);
+            }));
 
         $options = array('subscribe' => 'channel:foo', 'psubscribe' => 'channels:*');
 
@@ -94,7 +96,9 @@ class ConsumerTest extends PredisTestCase
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
 
         $client = $this->getMock('Predis\Client', array('disconnect'), array($connection));
-        $client->expects($this->exactly(1))->method('disconnect');
+        $client
+            ->expects($this->once())
+            ->method('disconnect');
 
         $pubsub = new PubSubConsumer($client, array('subscribe' => 'channel:foo'));
 
@@ -119,12 +123,13 @@ class ConsumerTest extends PredisTestCase
         $options = array('subscribe' => 'channel:foo', 'psubscribe' => 'channels:*');
         $pubsub = new PubSubConsumer($client, $options);
 
-        $connection->expects($this->exactly(2))
-                   ->method('writeRequest')
-                   ->with($this->logicalOr(
-                       $this->isInstanceOf($classUnsubscribe),
-                       $this->isInstanceOf($classPunsubscribe)
-                   ));
+        $connection
+            ->expects($this->exactly(2))
+            ->method('writeRequest')
+            ->with($this->logicalOr(
+                $this->isInstanceOf($classUnsubscribe),
+                $this->isInstanceOf($classPunsubscribe)
+            ));
 
         $pubsub->stop(false);
     }
@@ -151,7 +156,10 @@ class ConsumerTest extends PredisTestCase
         $rawmessage = array('pong', '');
 
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->once())->method('read')->will($this->returnValue($rawmessage));
+        $connection
+            ->expects($this->once())
+            ->method('read')
+            ->will($this->returnValue($rawmessage));
 
         $client = new Client($connection);
         $pubsub = new PubSubConsumer($client, array('subscribe' => 'channel:foo'));
@@ -169,7 +177,10 @@ class ConsumerTest extends PredisTestCase
         $rawmessage = array('pong', 'foobar');
 
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->once())->method('read')->will($this->returnValue($rawmessage));
+        $connection
+            ->expects($this->once())
+            ->method('read')
+            ->will($this->returnValue($rawmessage));
 
         $client = new Client($connection);
         $pubsub = new PubSubConsumer($client, array('subscribe' => 'channel:foo'));
@@ -187,7 +198,10 @@ class ConsumerTest extends PredisTestCase
         $rawmessage = array('message', 'channel:foo', 'message from channel');
 
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->once())->method('read')->will($this->returnValue($rawmessage));
+        $connection
+            ->expects($this->once())
+            ->method('read')
+            ->will($this->returnValue($rawmessage));
 
         $client = new Client($connection);
         $pubsub = new PubSubConsumer($client, array('subscribe' => 'channel:foo'));
@@ -206,7 +220,10 @@ class ConsumerTest extends PredisTestCase
         $rawmessage = array('pmessage', 'channel:*', 'channel:foo', 'message from channel');
 
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->once())->method('read')->will($this->returnValue($rawmessage));
+        $connection
+            ->expects($this->once())
+            ->method('read')
+            ->will($this->returnValue($rawmessage));
 
         $client = new Client($connection);
         $pubsub = new PubSubConsumer($client, array('psubscribe' => 'channel:*'));
@@ -226,7 +243,10 @@ class ConsumerTest extends PredisTestCase
         $rawmessage = array('subscribe', 'channel:foo', 1);
 
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->once())->method('read')->will($this->returnValue($rawmessage));
+        $connection
+            ->expects($this->once())
+            ->method('read')
+            ->will($this->returnValue($rawmessage));
 
         $client = new Client($connection);
         $pubsub = new PubSubConsumer($client, array('subscribe' => 'channel:foo'));
@@ -245,7 +265,10 @@ class ConsumerTest extends PredisTestCase
         $rawmessage = array('unsubscribe', 'channel:foo', 1);
 
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->once())->method('read')->will($this->returnValue($rawmessage));
+        $connection
+            ->expects($this->once())
+            ->method('read')
+            ->will($this->returnValue($rawmessage));
 
         $client = new Client($connection);
         $pubsub = new PubSubConsumer($client, array('subscribe' => 'channel:foo'));
@@ -264,7 +287,10 @@ class ConsumerTest extends PredisTestCase
         $rawmessage = array('unsubscribe', 'channel:foo', 0);
 
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->once())->method('read')->will($this->returnValue($rawmessage));
+        $connection
+            ->expects($this->once())
+            ->method('read')
+            ->will($this->returnValue($rawmessage));
 
         $client = new Client($connection);
         $pubsub = new PubSubConsumer($client, array('subscribe' => 'channel:foo'));

+ 26 - 22
tests/Predis/PubSub/DispatcherLoopTest.php

@@ -47,26 +47,29 @@ class DispatcherLoopTest extends PredisTestCase
         $dispatcher = new DispatcherLoop($pubsub);
 
         $function01 = $this->getMock('stdClass', array('__invoke'));
-        $function01->expects($this->exactly(2))
-                   ->method('__invoke')
-                   ->with($this->logicalOr(
-                       $this->equalTo('01:argument'),
-                       $this->equalTo('01:quit')
-                   ), $dispatcher)
-                   ->will($this->returnCallback(function ($arg, $dispatcher) {
-                       if ($arg === '01:quit') {
-                           $dispatcher->stop();
-                       }
-                   }));
+        $function01
+            ->expects($this->exactly(2))
+            ->method('__invoke')
+            ->with($this->logicalOr(
+                $this->equalTo('01:argument'),
+                $this->equalTo('01:quit')
+            ), $dispatcher)
+            ->will($this->returnCallback(function ($arg, $dispatcher) {
+                if ($arg === '01:quit') {
+                    $dispatcher->stop();
+                }
+            }));
 
         $function02 = $this->getMock('stdClass', array('__invoke'));
-        $function02->expects($this->once())
-                   ->method('__invoke')
-                   ->with('02:argument');
+        $function02
+            ->expects($this->once())
+            ->method('__invoke')
+            ->with('02:argument');
 
         $function03 = $this->getMock('stdClass', array('__invoke'));
-        $function03->expects($this->never())
-                   ->method('__invoke');
+        $function03
+            ->expects($this->never())
+            ->method('__invoke');
 
         $dispatcher->attachCallback('function:01', $function01);
         $dispatcher->attachCallback('function:02', $function02);
@@ -107,12 +110,13 @@ class DispatcherLoopTest extends PredisTestCase
         $dispatcher = new DispatcherLoop($pubsub);
 
         $callback = $this->getMock('stdClass', array('__invoke'));
-        $callback->expects($this->exactly(1))
-                 ->method('__invoke')
-                 ->with($this->equalTo('arg:prefixed'), $dispatcher)
-                 ->will($this->returnCallback(function ($arg, $dispatcher) {
-                     $dispatcher->stop();
-                 }));
+        $callback
+            ->expects($this->exactly(1))
+            ->method('__invoke')
+            ->with($this->equalTo('arg:prefixed'), $dispatcher)
+            ->will($this->returnCallback(function ($arg, $dispatcher) {
+                $dispatcher->stop();
+            }));
 
         $dispatcher->attachCallback('callback', $callback);
 

+ 20 - 15
tests/Predis/Replication/ReplicationStrategyTest.php

@@ -214,9 +214,10 @@ class ReplicationStrategyTest extends PredisTestCase
         $strategy = new ReplicationStrategy();
 
         $command = $this->getMock('Predis\Command\CommandInterface');
-        $command->expects($this->any())
-                ->method('getId')
-                ->will($this->returnValue('CMDTEST'));
+        $command
+            ->expects($this->any())
+            ->method('getId')
+            ->will($this->returnValue('CMDTEST'));
 
         $this->assertFalse($strategy->isReadOperation($command));
     }
@@ -229,9 +230,10 @@ class ReplicationStrategyTest extends PredisTestCase
         $strategy = new ReplicationStrategy();
 
         $command = $this->getMock('Predis\Command\CommandInterface');
-        $command->expects($this->any())
-                ->method('getId')
-                ->will($this->returnValue('CMDTEST'));
+        $command
+            ->expects($this->any())
+            ->method('getId')
+            ->will($this->returnValue('CMDTEST'));
 
         $strategy->setCommandReadOnly('CMDTEST', true);
         $this->assertTrue($strategy->isReadOperation($command));
@@ -245,9 +247,10 @@ class ReplicationStrategyTest extends PredisTestCase
         $strategy = new ReplicationStrategy();
 
         $command = $this->getMock('Predis\Command\CommandInterface');
-        $command->expects($this->any())
-                ->method('getId')
-                ->will($this->returnValue('CMDTEST'));
+        $command
+            ->expects($this->any())
+            ->method('getId')
+            ->will($this->returnValue('CMDTEST'));
 
         $strategy->setCommandReadOnly('CMDTEST', false);
         $this->assertFalse($strategy->isReadOperation($command));
@@ -307,9 +310,10 @@ class ReplicationStrategyTest extends PredisTestCase
         $strategy = new ReplicationStrategy();
 
         $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript'));
-        $command->expects($this->any())
-                ->method('getScript')
-                ->will($this->returnValue($script = 'return true'));
+        $command
+            ->expects($this->any())
+            ->method('getScript')
+            ->will($this->returnValue($script = 'return true'));
 
         $strategy->setScriptReadOnly($script, function ($command) {
             return $command->getArgument(2) === true;
@@ -330,9 +334,10 @@ class ReplicationStrategyTest extends PredisTestCase
         $strategy = new ReplicationStrategy();
 
         $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript'));
-        $command->expects($this->any())
-                ->method('getScript')
-                ->will($this->returnValue($script = 'return true'));
+        $command
+            ->expects($this->any())
+            ->method('getScript')
+            ->will($this->returnValue($script = 'return true'));
 
         $command->setArguments(array('trigger', false));
 

+ 2 - 0
tests/Predis/Response/Iterator/MultiBulkTupleTest.php

@@ -29,6 +29,7 @@ class MultiBulkTupleTest extends PredisTestCase
     public function testInitiatedMultiBulkIteratorsAreNotValid()
     {
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
+
         $iterator = new MultiBulk($connection, 2);
         $iterator->next();
 
@@ -43,6 +44,7 @@ class MultiBulkTupleTest extends PredisTestCase
     public function testMultiBulkWithOddSizesAreInvalid()
     {
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
+
         $iterator = new MultiBulk($connection, 3);
 
         new MultiBulkTuple($iterator);

+ 40 - 32
tests/Predis/Transaction/MultiExecTest.php

@@ -29,10 +29,11 @@ class MultiExecTest extends PredisTestCase
     public function testThrowsExceptionOnUnsupportedMultiExecInCommandFactory()
     {
         $commands = $this->getMock('Predis\Command\FactoryInterface');
-        $commands->expects($this->once())
-                 ->method('supportsCommands')
-                 ->with(array('MULTI', 'EXEC', 'DISCARD'))
-                 ->will($this->returnValue(false));
+        $commands
+            ->expects($this->once())
+            ->method('supportsCommands')
+            ->with(array('MULTI', 'EXEC', 'DISCARD'))
+            ->will($this->returnValue(false));
 
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
         $client = new Client($connection, array('commands' => $commands));
@@ -48,14 +49,16 @@ class MultiExecTest extends PredisTestCase
     public function testThrowsExceptionOnUnsupportedWatchInCommandFactory()
     {
         $commands = $this->getMock('Predis\Command\FactoryInterface');
-        $commands->expects($this->once())
-                 ->method('supportsCommands')
-                 ->with(array('MULTI', 'EXEC', 'DISCARD'))
-                 ->will($this->returnValue(true));
-        $commands->expects($this->once())
-                 ->method('supportsCommand')
-                 ->with('WATCH')
-                 ->will($this->returnValue(false));
+        $commands
+            ->expects($this->once())
+            ->method('supportsCommands')
+            ->with(array('MULTI', 'EXEC', 'DISCARD'))
+            ->will($this->returnValue(true));
+        $commands
+            ->expects($this->once())
+            ->method('supportsCommand')
+            ->with('WATCH')
+            ->will($this->returnValue(false));
 
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
         $client = new Client($connection, array('commands' => $commands));
@@ -72,14 +75,16 @@ class MultiExecTest extends PredisTestCase
     public function testThrowsExceptionOnUnsupportedUnwatchInCommandFactory()
     {
         $commands = $this->getMock('Predis\Command\FactoryInterface');
-        $commands->expects($this->once())
-                 ->method('supportsCommands')
-                 ->with(array('MULTI', 'EXEC', 'DISCARD'))
-                 ->will($this->returnValue(true));
-        $commands->expects($this->once())
-                 ->method('supportsCommand')
-                 ->with('UNWATCH')
-                 ->will($this->returnValue(false));
+        $commands
+            ->expects($this->once())
+            ->method('supportsCommands')
+            ->with(array('MULTI', 'EXEC', 'DISCARD'))
+            ->will($this->returnValue(true));
+        $commands
+            ->expects($this->once())
+            ->method('supportsCommand')
+            ->with('UNWATCH')
+            ->will($this->returnValue(false));
 
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
         $client = new Client($connection, array('commands' => $commands));
@@ -312,10 +317,11 @@ class MultiExecTest extends PredisTestCase
         $this->assertSame('DUMMY_RESPONSE', $tx->get('foo'));
         $this->assertSame('DUMMY_RESPONSE', $tx->get('hoge'));
 
-        $responses = $tx->multi()
-                        ->get('foo')
-                        ->get('hoge')
-                        ->execute();
+        $responses = $tx
+            ->multi()
+            ->get('foo')
+            ->get('hoge')
+            ->execute();
 
         $this->assertSame($responses, $expected);
         $this->assertSame(array('WATCH', 'WATCH', 'GET', 'GET'), self::commandsToIDs($casCommands));
@@ -577,11 +583,12 @@ class MultiExecTest extends PredisTestCase
         $client = new Client($connection, array('exceptions' => true));
         $tx = new MultiExec($client, array('exceptions' => false));
 
-        $result = $tx->multi()
-                     ->echo('before')
-                     ->echo('ERROR PLEASE!')
-                     ->echo('after')
-                     ->exec();
+        $result = $tx
+            ->multi()
+            ->echo('before')
+            ->echo('ERROR PLEASE!')
+            ->echo('after')
+            ->exec();
 
         $this->assertSame($expected, $result);
     }
@@ -812,9 +819,10 @@ class MultiExecTest extends PredisTestCase
     protected function getMockedConnection($executeCallback)
     {
         $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
-        $connection->expects($this->any())
-                   ->method('executeCommand')
-                   ->will($this->returnCallback($executeCallback));
+        $connection
+            ->expects($this->any())
+            ->method('executeCommand')
+            ->will($this->returnCallback($executeCallback));
 
         return $connection;
     }

Algunos archivos no se mostraron porque demasiados archivos cambiaron en este cambio