diff --git a/tests/PHPUnit/PredisConnectionTestCase.php b/tests/PHPUnit/PredisConnectionTestCase.php index ef075c9a..fb3445a1 100644 --- a/tests/PHPUnit/PredisConnectionTestCase.php +++ b/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); diff --git a/tests/PHPUnit/PredisTestCase.php b/tests/PHPUnit/PredisTestCase.php index 71d039bd..2e251c23 100644 --- a/tests/PHPUnit/PredisTestCase.php +++ b/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; diff --git a/tests/Predis/ClientTest.php b/tests/Predis/ClientTest.php index 96ddab6d..3c60c7d8 100644 --- a/tests/Predis/ClientTest.php +++ b/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); + $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')); + 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; } diff --git a/tests/Predis/Cluster/Distributor/HashRingTest.php b/tests/Predis/Cluster/Distributor/HashRingTest.php index 33f9378f..1d89aae8 100644 --- a/tests/Predis/Cluster/Distributor/HashRingTest.php +++ b/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); diff --git a/tests/Predis/Cluster/Distributor/KetamaRingTest.php b/tests/Predis/Cluster/Distributor/KetamaRingTest.php index 8d08f214..b7494a26 100644 --- a/tests/Predis/Cluster/Distributor/KetamaRingTest.php +++ b/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); diff --git a/tests/Predis/Cluster/PredisStrategyTest.php b/tests/Predis/Cluster/PredisStrategyTest.php index 2d44d5ea..8b95a980 100644 --- a/tests/Predis/Cluster/PredisStrategyTest.php +++ b/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); diff --git a/tests/Predis/Cluster/RedisStrategyTest.php b/tests/Predis/Cluster/RedisStrategyTest.php index fc939174..280d5cb0 100644 --- a/tests/Predis/Cluster/RedisStrategyTest.php +++ b/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); diff --git a/tests/Predis/Collection/Iterator/HashKeyTest.php b/tests/Predis/Collection/Iterator/HashKeyTest.php index 080c8455..03bb63b5 100644 --- a/tests/Predis/Collection/Iterator/HashKeyTest.php +++ b/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'); diff --git a/tests/Predis/Collection/Iterator/KeyspaceTest.php b/tests/Predis/Collection/Iterator/KeyspaceTest.php index 8437bb18..c39bda11 100644 --- a/tests/Predis/Collection/Iterator/KeyspaceTest.php +++ b/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); diff --git a/tests/Predis/Collection/Iterator/ListKeyTest.php b/tests/Predis/Collection/Iterator/ListKeyTest.php index 915becf0..07e19758 100644 --- a/tests/Predis/Collection/Iterator/ListKeyTest.php +++ b/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'); diff --git a/tests/Predis/Collection/Iterator/SetKeyTest.php b/tests/Predis/Collection/Iterator/SetKeyTest.php index 4a709e98..9e63f081 100644 --- a/tests/Predis/Collection/Iterator/SetKeyTest.php +++ b/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'); diff --git a/tests/Predis/Collection/Iterator/SortedSetKeyTest.php b/tests/Predis/Collection/Iterator/SortedSetKeyTest.php index a0c3df2f..882f7fe6 100644 --- a/tests/Predis/Collection/Iterator/SortedSetKeyTest.php +++ b/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'); diff --git a/tests/Predis/Command/RedisFactoryTest.php b/tests/Predis/Command/RedisFactoryTest.php index af24ebc0..5187b4f1 100644 --- a/tests/Predis/Command/RedisFactoryTest.php +++ b/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); diff --git a/tests/Predis/Command/ScriptCommandTest.php b/tests/Predis/Command/ScriptCommandTest.php index 042638eb..7b95a8a0 100644 --- a/tests/Predis/Command/ScriptCommandTest.php +++ b/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)); diff --git a/tests/Predis/Configuration/Option/AggregateTest.php b/tests/Predis/Configuration/Option/AggregateTest.php index 350e8945..7c84e665 100644 --- a/tests/Predis/Configuration/Option/AggregateTest.php +++ b/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)); diff --git a/tests/Predis/Configuration/Option/ClusterTest.php b/tests/Predis/Configuration/Option/ClusterTest.php index ff740b9e..847225f4 100644 --- a/tests/Predis/Configuration/Option/ClusterTest.php +++ b/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())); diff --git a/tests/Predis/Configuration/Option/CommandsTest.php b/tests/Predis/Configuration/Option/CommandsTest.php index 49035201..0683e9b8 100644 --- a/tests/Predis/Configuration/Option/CommandsTest.php +++ b/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); } diff --git a/tests/Predis/Configuration/Option/ConnectionsTest.php b/tests/Predis/Configuration/Option/ConnectionsTest.php index 17eaf164..7edc3c3a 100644 --- a/tests/Predis/Configuration/Option/ConnectionsTest.php +++ b/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 + ->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)); } diff --git a/tests/Predis/Configuration/Option/PrefixTest.php b/tests/Predis/Configuration/Option/PrefixTest.php index 835fc743..5d354df2 100644 --- a/tests/Predis/Configuration/Option/PrefixTest.php +++ b/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); diff --git a/tests/Predis/Configuration/Option/ReplicationTest.php b/tests/Predis/Configuration/Option/ReplicationTest.php index d9af6bee..28e8db8d 100644 --- a/tests/Predis/Configuration/Option/ReplicationTest.php +++ b/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'), diff --git a/tests/Predis/Configuration/OptionsTest.php b/tests/Predis/Configuration/OptionsTest.php index e80e4f6c..e1cdad97 100644 --- a/tests/Predis/Configuration/OptionsTest.php +++ b/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); diff --git a/tests/Predis/Connection/Cluster/PredisClusterTest.php b/tests/Predis/Connection/Cluster/PredisClusterTest.php index 260cf866..37136bfa 100644 --- a/tests/Predis/Connection/Cluster/PredisClusterTest.php +++ b/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); diff --git a/tests/Predis/Connection/Cluster/RedisClusterTest.php b/tests/Predis/Connection/Cluster/RedisClusterTest.php index cd4df4c3..5fde599d 100644 --- a/tests/Predis/Connection/Cluster/RedisClusterTest.php +++ b/tests/Predis/Connection/Cluster/RedisClusterTest.php @@ -63,6 +63,7 @@ class RedisClusterTest extends PredisTestCase $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380'); $cluster = new RedisCluster(new Connection\Factory()); + $cluster->add($connection1); $cluster->add($connection2); @@ -81,6 +82,7 @@ class RedisClusterTest extends PredisTestCase $connection3 = $this->getMockConnection('tcp://127.0.0.1:6371'); $cluster = new RedisCluster(new Connection\Factory()); + $cluster->add($connection1); $cluster->add($connection2); @@ -98,6 +100,7 @@ class RedisClusterTest extends PredisTestCase $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380'); $cluster = new RedisCluster(new Connection\Factory()); + $cluster->add($connection1); $cluster->add($connection2); @@ -116,6 +119,7 @@ class RedisClusterTest extends PredisTestCase $connection3 = $this->getMockConnection('tcp://127.0.0.1:6381'); $cluster = new RedisCluster(new Connection\Factory()); + $cluster->add($connection1); $cluster->add($connection2); $cluster->add($connection3); @@ -136,30 +140,35 @@ class RedisClusterTest extends PredisTestCase $connect2 = false; $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379'); - $connection1->expects($this->any()) - ->method('connect') - ->will($this->returnCallback(function () use (&$connect1) { - $connect1 = true; - })); - $connection1->expects($this->any()) - ->method('isConnected') - ->will($this->returnCallback(function () use (&$connect1) { - return $connect1; - })); + $connection1 + ->expects($this->any()) + ->method('connect') + ->will($this->returnCallback(function () use (&$connect1) { + $connect1 = true; + })); + $connection1 + ->expects($this->any()) + ->method('isConnected') + ->will($this->returnCallback(function () use (&$connect1) { + return $connect1; + })); $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380'); - $connection2->expects($this->any()) - ->method('connect') - ->will($this->returnCallback(function () use (&$connect2) { - $connect2 = true; - })); - $connection2->expects($this->any()) - ->method('isConnected') - ->will($this->returnCallback(function () use (&$connect2) { - return $connect2; - })); + $connection2 + ->expects($this->any()) + ->method('connect') + ->will($this->returnCallback(function () use (&$connect2) { + $connect2 = true; + })); + $connection2 + ->expects($this->any()) + ->method('isConnected') + ->will($this->returnCallback(function () use (&$connect2) { + return $connect2; + })); $cluster = new RedisCluster(new Connection\Factory()); + $cluster->add($connection1); $cluster->add($connection2); @@ -182,12 +191,17 @@ class RedisClusterTest extends PredisTestCase public function testDisconnectForcesAllConnectionsToDisconnect() { $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379'); - $connection1->expects($this->once())->method('disconnect'); + $connection1 + ->expects($this->once()) + ->method('disconnect'); $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380'); - $connection2->expects($this->once())->method('disconnect'); + $connection2 + ->expects($this->once()) + ->method('disconnect'); $cluster = new RedisCluster(new Connection\Factory()); + $cluster->add($connection1); $cluster->add($connection2); @@ -200,16 +214,19 @@ class RedisClusterTest extends PredisTestCase public function testIsConnectedReturnsTrueIfAtLeastOneConnectionIsOpen() { $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379'); - $connection1->expects($this->once()) - ->method('isConnected') - ->will($this->returnValue(false)); + $connection1 + ->expects($this->once()) + ->method('isConnected') + ->will($this->returnValue(false)); $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380'); - $connection2->expects($this->once()) - ->method('isConnected') - ->will($this->returnValue(true)); + $connection2 + ->expects($this->once()) + ->method('isConnected') + ->will($this->returnValue(true)); $cluster = new RedisCluster(new Connection\Factory()); + $cluster->add($connection1); $cluster->add($connection2); @@ -222,16 +239,19 @@ class RedisClusterTest extends PredisTestCase public function testIsConnectedReturnsFalseIfAllConnectionsAreClosed() { $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379'); - $connection1->expects($this->once()) - ->method('isConnected') - ->will($this->returnValue(false)); + $connection1 + ->expects($this->once()) + ->method('isConnected') + ->will($this->returnValue(false)); $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380'); - $connection2->expects($this->once()) - ->method('isConnected') - ->will($this->returnValue(false)); + $connection2 + ->expects($this->once()) + ->method('isConnected') + ->will($this->returnValue(false)); $cluster = new RedisCluster(new Connection\Factory()); + $cluster->add($connection1); $cluster->add($connection2); @@ -249,7 +269,6 @@ class RedisClusterTest extends PredisTestCase $connection4 = $this->getMockConnection('tcp://127.0.0.1:6384'); $cluster = new RedisCluster(new Connection\Factory()); - $cluster->useClusterSlots(false); $cluster->add($connection1); @@ -278,32 +297,42 @@ class RedisClusterTest extends PredisTestCase ); $connection1 = $this->getMockConnection('tcp://127.0.0.1:6381?slots=0-5460'); - $connection1->expects($this->once()) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'CLUSTER', array('SLOTS') - )) - ->will($this->returnValue($slotsmap)); + $connection1 + ->expects($this->once()) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'CLUSTER', array('SLOTS') + )) + ->will($this->returnValue($slotsmap)); $connection2 = $this->getMockConnection('tcp://127.0.0.1:6382?slots=5461-10921'); $connection3 = $this->getMockConnection('tcp://127.0.0.1:6383'); $connection4 = $this->getMockConnection('tcp://127.0.0.1:6384'); $factory = $this->getMock('Predis\Connection\FactoryInterface'); - $factory->expects($this->at(0)) - ->method('create') - ->with(array('host' => '127.0.0.1', 'port' => '6383')) - ->will($this->returnValue($connection3)); - $factory->expects($this->at(1)) - ->method('create') - ->with(array('host' => '127.0.0.1', 'port' => '6384')) - ->will($this->returnValue($connection4)); + $factory + ->expects($this->at(0)) + ->method('create') + ->with(array( + 'host' => '127.0.0.1', + 'port' => '6383', + )) + ->will($this->returnValue($connection3)); + $factory + ->expects($this->at(1)) + ->method('create') + ->with(array( + 'host' => '127.0.0.1', + 'port' => '6384', + )) + ->will($this->returnValue($connection4)); // TODO: I'm not sure about mocking a protected method, but it'll do for now $cluster = $this->getMock('Predis\Connection\Cluster\RedisCluster', array('getRandomConnection'), array($factory)); - $cluster->expects($this->exactly(1)) - ->method('getRandomConnection') - ->will($this->returnValue($connection1)); + $cluster + ->expects($this->once()) + ->method('getRandomConnection') + ->will($this->returnValue($connection1)); $cluster->add($connection1); $cluster->add($connection2); @@ -329,6 +358,7 @@ class RedisClusterTest extends PredisTestCase $connection3 = $this->getMockConnection('tcp://127.0.0.1:6381'); $cluster = new RedisCluster(new Connection\Factory()); + $cluster->add($connection1); $cluster->add($connection2); $cluster->add($connection3); @@ -355,6 +385,7 @@ class RedisClusterTest extends PredisTestCase $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380'); $cluster = new RedisCluster(new Connection\Factory()); + $cluster->add($connection1); $cluster->setSlots(0, 4095, '127.0.0.1:6379'); @@ -374,6 +405,7 @@ class RedisClusterTest extends PredisTestCase $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380'); $cluster = new RedisCluster(new Connection\Factory()); + $cluster->add($connection1); $cluster->add($connection2); @@ -401,6 +433,7 @@ class RedisClusterTest extends PredisTestCase $connection3 = $this->getMockConnection('tcp://127.0.0.1:6381?slots=10922-16383'); $cluster = new RedisCluster(new Connection\Factory()); + $cluster->add($connection1); $cluster->add($connection2); $cluster->add($connection3); @@ -429,6 +462,7 @@ class RedisClusterTest extends PredisTestCase $connection3 = $this->getMockConnection('tcp://127.0.0.1:6381?slots=10922-10999,11001-16383'); $cluster = new RedisCluster(new Connection\Factory()); + $cluster->add($connection1); $cluster->add($connection2); $cluster->add($connection3); @@ -461,6 +495,7 @@ class RedisClusterTest extends PredisTestCase $connection3 = $this->getMockConnection('tcp://127.0.0.1:6381'); $cluster = new RedisCluster(new Connection\Factory()); + $cluster->add($connection1); $cluster->add($connection2); $cluster->add($connection3); @@ -485,6 +520,7 @@ class RedisClusterTest extends PredisTestCase $connection3 = $this->getMockConnection('tcp://127.0.0.1:6381'); $cluster = new RedisCluster(new Connection\Factory()); + $cluster->add($connection1); $cluster->add($connection2); $cluster->add($connection3); @@ -513,13 +549,19 @@ class RedisClusterTest extends PredisTestCase $command = $this->getCommandFactory()->createCommand('get', array('node:1001')); $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379'); - $connection1->expects($this->once())->method('writeRequest')->with($command); + $connection1 + ->expects($this->once()) + ->method('writeRequest') + ->with($command); $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380'); - $connection2->expects($this->never())->method('writeRequest'); + $connection2 + ->expects($this->never()) + ->method('writeRequest'); $cluster = new RedisCluster(new Connection\Factory()); $cluster->useClusterSlots(false); + $cluster->add($connection1); $cluster->add($connection2); @@ -534,13 +576,19 @@ class RedisClusterTest extends PredisTestCase $command = $this->getCommandFactory()->createCommand('get', array('node:1050')); $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379'); - $connection1->expects($this->never())->method('readResponse'); + $connection1 + ->expects($this->never()) + ->method('readResponse'); $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380'); - $connection2->expects($this->once())->method('readResponse')->with($command); + $connection2 + ->expects($this->once()) + ->method('readResponse') + ->with($command); $cluster = new RedisCluster(new Connection\Factory()); $cluster->useClusterSlots(false); + $cluster->add($connection1); $cluster->add($connection2); @@ -559,53 +607,59 @@ class RedisClusterTest extends PredisTestCase ); $connection1 = $this->getMockConnection('tcp://127.0.0.1:6381?slots=0-5460'); - $connection1->expects($this->once()) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'GET', array('node:1001') - )) - ->will($this->throwException( - new Connection\ConnectionException($connection1, 'Unknown connection error [127.0.0.1:6381]') - )); + $connection1 + ->expects($this->once()) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'GET', array('node:1001') + )) + ->will($this->throwException( + new Connection\ConnectionException($connection1, 'Unknown connection error [127.0.0.1:6381]') + )); $connection2 = $this->getMockConnection('tcp://127.0.0.1:6382?slots=5461-10921'); - $connection2->expects($this->any()) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'CLUSTER', array('SLOTS') - )) - ->will($this->returnValue($slotsmap)); + $connection2 + ->expects($this->any()) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'CLUSTER', array('SLOTS') + )) + ->will($this->returnValue($slotsmap)); $connection3 = $this->getMockConnection('tcp://127.0.0.1:6383?slots=10922-16383'); - $connection3->expects($this->any()) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'CLUSTER', array('SLOTS') - )) - ->will($this->returnValue($slotsmap)); + $connection3 + ->expects($this->any()) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'CLUSTER', array('SLOTS') + )) + ->will($this->returnValue($slotsmap)); $connection4 = $this->getMockConnection('tcp://127.0.0.1:9381'); - $connection4->expects($this->at(0)) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'GET', array('node:1001') - )) - ->will($this->returnValue('value:1001')); - $connection4->expects($this->at(1)) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'GET', array('node:5001') - )) - ->will($this->returnValue('value:5001')); + $connection4 + ->expects($this->at(0)) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'GET', array('node:1001') + )) + ->will($this->returnValue('value:1001')); + $connection4 + ->expects($this->at(1)) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'GET', array('node:5001') + )) + ->will($this->returnValue('value:5001')); $factory = $this->getMock('Predis\Connection\FactoryInterface'); - $factory->expects($this->once()) - ->method('create') - ->with(array( - 'host' => '127.0.0.1', - 'port' => '9381', - )) - ->will($this->returnValue($connection4)); + $factory + ->expects($this->once()) + ->method('create') + ->with(array( + 'host' => '127.0.0.1', + 'port' => '9381', + )) + ->will($this->returnValue($connection4)); $cluster = new RedisCluster($factory); @@ -628,50 +682,56 @@ class RedisClusterTest extends PredisTestCase public function testRetriesExecutingCommandOnConnectionFailureButDoNotAskSlotsMapWhenDisabled() { $connection1 = $this->getMockConnection('tcp://127.0.0.1:6381?slots=0-5500'); - $connection1->expects($this->once()) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'GET', array('node:1001') - )) - ->will($this->throwException( - new Connection\ConnectionException($connection1, 'Unknown connection error [127.0.0.1:6381]') - )); + $connection1 + ->expects($this->once()) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'GET', array('node:1001') + )) + ->will($this->throwException( + new Connection\ConnectionException($connection1, 'Unknown connection error [127.0.0.1:6381]') + )); $connection2 = $this->getMockConnection('tcp://127.0.0.1:6382?slots=5501-11000'); - $connection2->expects($this->once()) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'GET', array('node:1001') - )) - ->will($this->returnValue( - new Response\Error('MOVED 1970 127.0.0.1:9381') - )); + $connection2 + ->expects($this->once()) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'GET', array('node:1001') + )) + ->will($this->returnValue( + new Response\Error('MOVED 1970 127.0.0.1:9381') + )); $connection3 = $this->getMockConnection('tcp://127.0.0.1:6383?slots=11101-16383'); - $connection3->expects($this->never()) - ->method('executeCommand'); + $connection3 + ->expects($this->never()) + ->method('executeCommand'); $connection4 = $this->getMockConnection('tcp://127.0.0.1:9381'); - $connection4->expects($this->once()) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'GET', array('node:1001') - )) - ->will($this->returnValue('value:1001')); + $connection4 + ->expects($this->once()) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'GET', array('node:1001') + )) + ->will($this->returnValue('value:1001')); $factory = $this->getMock('Predis\Connection\FactoryInterface'); - $factory->expects($this->once()) - ->method('create') - ->with(array( - 'host' => '127.0.0.1', - 'port' => '9381', - )) - ->will($this->returnValue($connection4)); + $factory + ->expects($this->once()) + ->method('create') + ->with(array( + 'host' => '127.0.0.1', + 'port' => '9381', + )) + ->will($this->returnValue($connection4)); // TODO: I'm not sure about mocking a protected method, but it'll do for now $cluster = $this->getMock('Predis\Connection\Cluster\RedisCluster', array('getRandomConnection'), array($factory)); - $cluster->expects($this->never()) - ->method('getRandomConnection'); + $cluster + ->expects($this->never()) + ->method('getRandomConnection'); $cluster->useClusterSlots(false); @@ -692,11 +752,15 @@ class RedisClusterTest extends PredisTestCase public function testThrowsClientExceptionWhenExecutingCommandWithEmptyPool() { $factory = $this->getMock('Predis\Connection\FactoryInterface'); - $factory->expects($this->never())->method('create'); + $factory + ->expects($this->never()) + ->method('create'); $cluster = new RedisCluster($factory); - $cluster->executeCommand(Command\RawCommand::create('get', 'node:1001')); + $cluster->executeCommand( + Command\RawCommand::create('get', 'node:1001') + ); } /** @@ -705,7 +769,9 @@ class RedisClusterTest extends PredisTestCase public function testAskSlotsMapReturnEmptyArrayOnEmptyConnectionsPool() { $factory = $this->getMock('Predis\Connection\FactoryInterface'); - $factory->expects($this->never())->method('create'); + $factory + ->expects($this->never()) + ->method('create'); $cluster = new RedisCluster($factory); @@ -724,41 +790,47 @@ class RedisClusterTest extends PredisTestCase ); $connection1 = $this->getMockConnection('tcp://127.0.0.1:6381?slots=0-5460'); - $connection1->expects($this->once()) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'CLUSTER', array('SLOTS') - )) - ->will($this->throwException( - new Connection\ConnectionException($connection1, 'Unknown connection error [127.0.0.1:6381]') - )); + $connection1 + ->expects($this->once()) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'CLUSTER', array('SLOTS') + )) + ->will($this->throwException( + new Connection\ConnectionException($connection1, 'Unknown connection error [127.0.0.1:6381]') + )); $connection2 = $this->getMockConnection('tcp://127.0.0.1:6382?slots=5461-10921'); - $connection2->expects($this->once()) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'CLUSTER', array('SLOTS') - )) - ->will($this->throwException( - new Connection\ConnectionException($connection2, 'Unknown connection error [127.0.0.1:6383]') - )); + $connection2 + ->expects($this->once()) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'CLUSTER', array('SLOTS') + )) + ->will($this->throwException( + new Connection\ConnectionException($connection2, 'Unknown connection error [127.0.0.1:6383]') + )); $connection3 = $this->getMockConnection('tcp://127.0.0.1:6383?slots=10922-16383'); - $connection3->expects($this->once()) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'CLUSTER', array('SLOTS') - )) - ->will($this->returnValue($slotsmap)); + $connection3 + ->expects($this->once()) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'CLUSTER', array('SLOTS') + )) + ->will($this->returnValue($slotsmap)); $factory = $this->getMock('Predis\Connection\FactoryInterface'); - $factory->expects($this->never())->method('create'); + $factory + ->expects($this->never()) + ->method('create'); // TODO: I'm not sure about mocking a protected method, but it'll do for now $cluster = $this->getMock('Predis\Connection\Cluster\RedisCluster', array('getRandomConnection'), array($factory)); - $cluster->expects($this->exactly(3)) - ->method('getRandomConnection') - ->will($this->onConsecutiveCalls($connection1, $connection2, $connection3)); + $cluster + ->expects($this->exactly(3)) + ->method('getRandomConnection') + ->will($this->onConsecutiveCalls($connection1, $connection2, $connection3)); $cluster->add($connection1); $cluster->add($connection2); @@ -781,37 +853,43 @@ class RedisClusterTest extends PredisTestCase ); $connection1 = $this->getMockConnection('tcp://127.0.0.1:6381?slots=0-5460'); - $connection1->expects($this->any()) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'CLUSTER', array('SLOTS') - )) - ->will($this->throwException( - new Connection\ConnectionException($connection1, 'Unknown connection error [127.0.0.1:6381]') - )); + $connection1 + ->expects($this->any()) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'CLUSTER', array('SLOTS') + )) + ->will($this->throwException( + new Connection\ConnectionException($connection1, 'Unknown connection error [127.0.0.1:6381]') + )); $connection2 = $this->getMockConnection('tcp://127.0.0.1:6382?slots=5461-10921'); - $connection2->expects($this->any()) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'CLUSTER', array('SLOTS') - )) - ->will($this->throwException( - new Connection\ConnectionException($connection2, 'Unknown connection error [127.0.0.1:6382]') - )); + $connection2 + ->expects($this->any()) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'CLUSTER', array('SLOTS') + )) + ->will($this->throwException( + new Connection\ConnectionException($connection2, 'Unknown connection error [127.0.0.1:6382]') + )); $connection3 = $this->getMockConnection('tcp://127.0.0.1:6383?slots=10922-16383'); - $connection3->expects($this->never()) - ->method('executeCommand'); + $connection3 + ->expects($this->never()) + ->method('executeCommand'); $factory = $this->getMock('Predis\Connection\FactoryInterface'); - $factory->expects($this->never())->method('create'); + $factory + ->expects($this->never()) + ->method('create'); // TODO: I'm not sure about mocking a protected method, but it'll do for now $cluster = $this->getMock('Predis\Connection\Cluster\RedisCluster', array('getRandomConnection'), array($factory)); - $cluster->expects($this->exactly(2)) - ->method('getRandomConnection') - ->will($this->onConsecutiveCalls($connection1, $connection2)); + $cluster + ->expects($this->exactly(2)) + ->method('getRandomConnection') + ->will($this->onConsecutiveCalls($connection1, $connection2)); $cluster->add($connection1); $cluster->add($connection2); @@ -833,6 +911,7 @@ class RedisClusterTest extends PredisTestCase $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380'); $cluster = new RedisCluster(new Connection\Factory()); + $cluster->add($connection1); $cluster->add($connection2); @@ -857,25 +936,31 @@ class RedisClusterTest extends PredisTestCase $command = $this->getCommandFactory()->createCommand('get', array('node:1001')); $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379'); - $connection1->expects($this->exactly(2)) - ->method('executeCommand') - ->with($command) - ->will($this->onConsecutiveCalls($askResponse, 'foobar')); + $connection1 + ->expects($this->exactly(2)) + ->method('executeCommand') + ->with($command) + ->will($this->onConsecutiveCalls($askResponse, 'foobar')); $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380'); - $connection2->expects($this->at(2)) - ->method('executeCommand') - ->with($this->isRedisCommand('ASKING')); - $connection2->expects($this->at(3)) - ->method('executeCommand') - ->with($command) - ->will($this->returnValue('foobar')); + $connection2 + ->expects($this->at(2)) + ->method('executeCommand') + ->with($this->isRedisCommand('ASKING')); + $connection2 + ->expects($this->at(3)) + ->method('executeCommand') + ->with($command) + ->will($this->returnValue('foobar')); $factory = $this->getMock('Predis\Connection\Factory'); - $factory->expects($this->never())->method('create'); + $factory + ->expects($this->never()) + ->method('create'); $cluster = new RedisCluster($factory); $cluster->useClusterSlots(false); + $cluster->add($connection1); $cluster->add($connection2); @@ -894,32 +979,43 @@ class RedisClusterTest extends PredisTestCase $command = $this->getCommandFactory()->createCommand('get', array('node:1001')); $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379'); - $connection1->expects($this->exactly(2)) - ->method('executeCommand') - ->with($command) - ->will($this->onConsecutiveCalls($askResponse, 'foobar')); + $connection1 + ->expects($this->exactly(2)) + ->method('executeCommand') + ->with($command) + ->will($this->onConsecutiveCalls($askResponse, 'foobar')); $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380'); - $connection2->expects($this->never()) - ->method('executeCommand'); + $connection2 + ->expects($this->never()) + ->method('executeCommand'); $connection3 = $this->getMockConnection('tcp://127.0.0.1:6381'); - $connection3->expects($this->at(0)) - ->method('executeCommand') - ->with($this->isRedisCommand('ASKING')); - $connection3->expects($this->at(1)) - ->method('executeCommand') - ->with($command) - ->will($this->returnValue('foobar')); + $connection3 + ->expects($this->at(0)) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'ASKING' + )); + $connection3 + ->expects($this->at(1)) + ->method('executeCommand') + ->with($command) + ->will($this->returnValue('foobar')); $factory = $this->getMock('Predis\Connection\Factory'); - $factory->expects($this->once()) - ->method('create') - ->with(array('host' => '127.0.0.1', 'port' => '6381')) - ->will($this->returnValue($connection3)); + $factory + ->expects($this->once()) + ->method('create') + ->with(array( + 'host' => '127.0.0.1', + 'port' => '6381', + )) + ->will($this->returnValue($connection3)); $cluster = new RedisCluster($factory); $cluster->useClusterSlots(false); + $cluster->add($connection1); $cluster->add($connection2); @@ -938,22 +1034,25 @@ class RedisClusterTest extends PredisTestCase $command = $this->getCommandFactory()->createCommand('get', array('node:1001')); $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379'); - $connection1->expects($this->exactly(1)) - ->method('executeCommand') - ->with($command) - ->will($this->returnValue($movedResponse)); + $connection1 + ->expects($this->exactly(1)) + ->method('executeCommand') + ->with($command) + ->will($this->returnValue($movedResponse)); $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380'); - $connection2->expects($this->exactly(2)) - ->method('executeCommand') - ->with($command) - ->will($this->onConsecutiveCalls('foobar', 'foobar')); + $connection2 + ->expects($this->exactly(2)) + ->method('executeCommand') + ->with($command) + ->will($this->onConsecutiveCalls('foobar', 'foobar')); $factory = $this->getMock('Predis\Connection\Factory'); $factory->expects($this->never())->method('create'); $cluster = new RedisCluster($factory); $cluster->useClusterSlots(false); + $cluster->add($connection1); $cluster->add($connection2); @@ -972,29 +1071,37 @@ class RedisClusterTest extends PredisTestCase $command = $this->getCommandFactory()->createCommand('get', array('node:1001')); $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379'); - $connection1->expects($this->once()) - ->method('executeCommand') - ->with($command) - ->will($this->returnValue($movedResponse)); + $connection1 + ->expects($this->once()) + ->method('executeCommand') + ->with($command) + ->will($this->returnValue($movedResponse)); $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380'); - $connection2->expects($this->never()) - ->method('executeCommand'); + $connection2 + ->expects($this->never()) + ->method('executeCommand'); $connection3 = $this->getMockConnection('tcp://127.0.0.1:6381'); - $connection3->expects($this->exactly(2)) - ->method('executeCommand') - ->with($command) - ->will($this->onConsecutiveCalls('foobar', 'foobar')); + $connection3 + ->expects($this->exactly(2)) + ->method('executeCommand') + ->with($command) + ->will($this->onConsecutiveCalls('foobar', 'foobar')); $factory = $this->getMock('Predis\Connection\Factory'); - $factory->expects($this->once()) - ->method('create') - ->with(array('host' => '127.0.0.1', 'port' => '6381')) - ->will($this->returnValue($connection3)); + $factory + ->expects($this->once()) + ->method('create') + ->with(array( + 'host' => '127.0.0.1', + 'port' => '6381', + )) + ->will($this->returnValue($connection3)); $cluster = new RedisCluster($factory); $cluster->useClusterSlots(false); + $cluster->add($connection1); $cluster->add($connection2); @@ -1013,25 +1120,32 @@ class RedisClusterTest extends PredisTestCase $command = $this->getCommandFactory()->createCommand('get', array('node:1001')); $connection1 = $this->getMockConnection('tcp://[2001:db8:0:f101::1]:6379'); - $connection1->expects($this->once()) - ->method('executeCommand') - ->with($command) - ->will($this->returnValue($movedResponse)); + $connection1 + ->expects($this->once()) + ->method('executeCommand') + ->with($command) + ->will($this->returnValue($movedResponse)); $connection2 = $this->getMockConnection('tcp://[2001:db8:0:f101::2]:6379'); - $connection2->expects($this->once()) - ->method('executeCommand') - ->with($command) - ->will($this->returnValue('foobar')); + $connection2 + ->expects($this->once()) + ->method('executeCommand') + ->with($command) + ->will($this->returnValue('foobar')); $factory = $this->getMock('Predis\Connection\Factory'); - $factory->expects($this->once()) - ->method('create') - ->with(array('host' => '2001:db8:0:f101::2', 'port' => '6379')) - ->will($this->returnValue($connection2)); + $factory + ->expects($this->once()) + ->method('create') + ->with(array( + 'host' => '2001:db8:0:f101::2', + 'port' => '6379', + )) + ->will($this->returnValue($connection2)); $cluster = new RedisCluster($factory); $cluster->useClusterSlots(false); + $cluster->add($connection1); $cluster->executeCommand($command); @@ -1061,17 +1175,19 @@ class RedisClusterTest extends PredisTestCase array(7168, 8191, array('10.1.0.52', 6394), array('10.1.0.51', 6394)), ); - $command = Command\RawCommand::create('CLUSTER', 'SLOTS'); - $connection1 = $this->getMockConnection('tcp://10.1.0.51:6384'); - $connection1->expects($this->once()) - ->method('executeCommand') - ->with($command) - ->will($this->returnValue($response)); + $connection1 + ->expects($this->once()) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'CLUSTER', array('SLOTS') + )) + ->will($this->returnValue($response)); $factory = $this->getMock('Predis\Connection\Factory'); $cluster = new RedisCluster($factory); + $cluster->add($connection1); $cluster->askSlotsMap(); @@ -1092,28 +1208,38 @@ class RedisClusterTest extends PredisTestCase ); $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379'); - $connection1->expects($this->once()) - ->method('executeCommand') - ->with($cmdGET) - ->will($this->returnValue($rspMOVED)); + $connection1 + ->expects($this->once()) + ->method('executeCommand') + ->with($cmdGET) + ->will($this->returnValue($rspMOVED)); $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380'); - $connection2->expects($this->at(0)) - ->method('executeCommand') - ->with($this->isRedisCommand('CLUSTER', array('SLOTS'))) - ->will($this->returnValue($rspSlotsArray)); - $connection2->expects($this->at(2)) - ->method('executeCommand') - ->with($cmdGET) - ->will($this->returnValue('foobar')); + $connection2 + ->expects($this->at(0)) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'CLUSTER', array('SLOTS') + )) + ->will($this->returnValue($rspSlotsArray)); + $connection2 + ->expects($this->at(2)) + ->method('executeCommand') + ->with($cmdGET) + ->will($this->returnValue('foobar')); $factory = $this->getMock('Predis\Connection\Factory'); - $factory->expects($this->once()) - ->method('create') - ->with(array('host' => '127.0.0.1', 'port' => '6380')) - ->will($this->returnValue($connection2)); + $factory + ->expects($this->once()) + ->method('create') + ->with(array( + 'host' => '127.0.0.1', + 'port' => '6380', + )) + ->will($this->returnValue($connection2)); $cluster = new RedisCluster($factory); + $cluster->add($connection1); $this->assertSame('foobar', $cluster->executeCommand($cmdGET)); @@ -1130,6 +1256,7 @@ class RedisClusterTest extends PredisTestCase $ping = $this->getCommandFactory()->createCommand('ping'); $cluster = new RedisCluster(new Connection\Factory()); + $cluster->add($this->getMockConnection('tcp://127.0.0.1:6379')); $cluster->getConnection($ping); @@ -1146,6 +1273,7 @@ class RedisClusterTest extends PredisTestCase $connection3 = $this->getMockConnection('tcp://127.0.0.1:6381?slots=2730-4095'); $cluster = new RedisCluster(new Connection\Factory()); + $cluster->add($connection1); $cluster->add($connection2); $cluster->add($connection3); diff --git a/tests/Predis/Connection/CompositeStreamConnectionTest.php b/tests/Predis/Connection/CompositeStreamConnectionTest.php index 8f347272..0225e39f 100644 --- a/tests/Predis/Connection/CompositeStreamConnectionTest.php +++ b/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'); diff --git a/tests/Predis/Connection/FactoryTest.php b/tests/Predis/Connection/FactoryTest.php index efa34d3f..8d35ed46 100644 --- a/tests/Predis/Connection/FactoryTest.php +++ b/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()); } diff --git a/tests/Predis/Connection/PhpiredisSocketConnectionTest.php b/tests/Predis/Connection/PhpiredisSocketConnectionTest.php index 4ab1e3f5..0cdbb528 100644 --- a/tests/Predis/Connection/PhpiredisSocketConnectionTest.php +++ b/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'); diff --git a/tests/Predis/Connection/PhpiredisStreamConnectionTest.php b/tests/Predis/Connection/PhpiredisStreamConnectionTest.php index 67a696cf..b94f4ef8 100644 --- a/tests/Predis/Connection/PhpiredisStreamConnectionTest.php +++ b/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'); diff --git a/tests/Predis/Connection/Replication/MasterSlaveReplicationTest.php b/tests/Predis/Connection/Replication/MasterSlaveReplicationTest.php index 8bb5224d..b22eec9b 100644 --- a/tests/Predis/Connection/Replication/MasterSlaveReplicationTest.php +++ b/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)); + $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(' + $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)); + $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))); + $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(' + $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)); + $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))); + $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)); + $slave1 + ->expects($this->once()) + ->method('executeCommand') + ->with($cmdExists) + ->will($this->returnValue(1)); - $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 @@ -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); diff --git a/tests/Predis/Connection/Replication/SentinelReplicationTest.php b/tests/Predis/Connection/Replication/SentinelReplicationTest.php index e178098e..2669e421 100644 --- a/tests/Predis/Connection/Replication/SentinelReplicationTest.php +++ b/tests/Predis/Connection/Replication/SentinelReplicationTest.php @@ -72,7 +72,10 @@ class SentinelReplicationTest extends PredisTestCase 'tcp://127.0.0.1:5381?alias=sentinel&timeout=1', )); - $parameters = $replication->getSentinelConnection()->getParameters()->toArray(); + $parameters = $replication + ->getSentinelConnection() + ->getParameters() + ->toArray(); $this->assertArrayHasKey('timeout', $parameters); $this->assertSame('1', $parameters['timeout']); @@ -89,7 +92,9 @@ class SentinelReplicationTest extends PredisTestCase $replication = $this->getReplicationConnection('svc', array($originalParameters)); - $parameters = $replication->getSentinelConnection()->getParameters(); + $parameters = $replication + ->getSentinelConnection() + ->getParameters(); $this->assertSame($originalParameters, $parameters); $this->assertNotNull($parameters->password); @@ -166,32 +171,32 @@ class SentinelReplicationTest extends PredisTestCase public function testMethodUpdateSentinelsFetchesSentinelNodes() { $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); - $sentinel1->expects($this->once()) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'SENTINEL', array('sentinels', 'svc') - )) - ->will($this->returnValue( - array( - array( - 'name', '127.0.0.1:5382', - 'ip', '127.0.0.1', - 'port', '5382', - 'runid', 'a113aa7a0d4870a85bb22b4b605fd26eb93ed40e', - 'flags', 'sentinel', - ), - array( - 'name', '127.0.0.1:5383', - 'ip', '127.0.0.1', - 'port', '5383', - 'runid', 'f53b52d281be5cdd4873700c94846af8dbe47209', - 'flags', 'sentinel', - ), - ) - )); + $sentinel1 + ->expects($this->once()) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'SENTINEL', array('sentinels', 'svc') + )) + ->will($this->returnValue( + array( + array( + 'name', '127.0.0.1:5382', + 'ip', '127.0.0.1', + 'port', '5382', + 'runid', 'a113aa7a0d4870a85bb22b4b605fd26eb93ed40e', + 'flags', 'sentinel', + ), + array( + 'name', '127.0.0.1:5383', + 'ip', '127.0.0.1', + 'port', '5383', + 'runid', 'f53b52d281be5cdd4873700c94846af8dbe47209', + 'flags', 'sentinel', + ), + ) + )); $replication = $this->getReplicationConnection('svc', array($sentinel1)); - $replication->updateSentinels(); // TODO: sorry for the smell... @@ -214,35 +219,36 @@ class SentinelReplicationTest extends PredisTestCase public function testMethodUpdateSentinelsRemovesCurrentSentinelAndRetriesNextOneOnFailure() { $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); - $sentinel1->expects($this->once()) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'SENTINEL', array('sentinels', 'svc') - )) - ->will($this->throwException( - new Connection\ConnectionException($sentinel1, 'Unknown connection error [127.0.0.1:5381]') - )); + $sentinel1 + ->expects($this->once()) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'SENTINEL', array('sentinels', 'svc') + )) + ->will($this->throwException( + new Connection\ConnectionException($sentinel1, 'Unknown connection error [127.0.0.1:5381]') + )); $sentinel2 = $this->getMockSentinelConnection('tcp://127.0.0.1:5382?alias=sentinel2'); - $sentinel2->expects($this->once()) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'SENTINEL', array('sentinels', 'svc') - )) - ->will($this->returnValue( - array( - array( - 'name', '127.0.0.1:5383', - 'ip', '127.0.0.1', - 'port', '5383', - 'runid', 'f53b52d281be5cdd4873700c94846af8dbe47209', - 'flags', 'sentinel', - ), - ) - )); + $sentinel2 + ->expects($this->once()) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'SENTINEL', array('sentinels', 'svc') + )) + ->will($this->returnValue( + array( + array( + 'name', '127.0.0.1:5383', + 'ip', '127.0.0.1', + 'port', '5383', + 'runid', 'f53b52d281be5cdd4873700c94846af8dbe47209', + 'flags', 'sentinel', + ), + ) + )); $replication = $this->getReplicationConnection('svc', array($sentinel1, $sentinel2)); - $replication->updateSentinels(); // TODO: sorry for the smell... @@ -266,17 +272,17 @@ class SentinelReplicationTest extends PredisTestCase public function testMethodUpdateSentinelsThrowsExceptionOnNoAvailableSentinel() { $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); - $sentinel1->expects($this->once()) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'SENTINEL', array('sentinels', 'svc') - )) - ->will($this->throwException( - new Connection\ConnectionException($sentinel1, 'Unknown connection error [127.0.0.1:5381]') - )); + $sentinel1 + ->expects($this->once()) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'SENTINEL', array('sentinels', 'svc') + )) + ->will($this->throwException( + new Connection\ConnectionException($sentinel1, 'Unknown connection error [127.0.0.1:5381]') + )); $replication = $this->getReplicationConnection('svc', array($sentinel1)); - $replication->updateSentinels(); } @@ -286,50 +292,51 @@ class SentinelReplicationTest extends PredisTestCase public function testMethodQuerySentinelFetchesMasterNodeSlaveNodesAndSentinelNodes() { $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); - $sentinel1->expects($this->exactly(3)) - ->method('executeCommand') - ->withConsecutive( - $this->isRedisCommand('SENTINEL', array('sentinels', 'svc')), - $this->isRedisCommand('SENTINEL', array('get-master-addr-by-name', 'svc')), - $this->isRedisCommand('SENTINEL', array('slaves', 'svc')) - ) - ->will($this->onConsecutiveCalls( - // SENTINEL sentinels svc - array( - array( - 'name', '127.0.0.1:5382', - 'ip', '127.0.0.1', - 'port', '5382', - 'runid', 'a113aa7a0d4870a85bb22b4b605fd26eb93ed40e', - 'flags', 'sentinel', - ), - ), + $sentinel1 + ->expects($this->exactly(3)) + ->method('executeCommand') + ->withConsecutive( + $this->isRedisCommand('SENTINEL', array('sentinels', 'svc')), + $this->isRedisCommand('SENTINEL', array('get-master-addr-by-name', 'svc')), + $this->isRedisCommand('SENTINEL', array('slaves', 'svc')) + ) + ->will($this->onConsecutiveCalls( + // SENTINEL sentinels svc + array( + array( + 'name', '127.0.0.1:5382', + 'ip', '127.0.0.1', + 'port', '5382', + 'runid', 'a113aa7a0d4870a85bb22b4b605fd26eb93ed40e', + 'flags', 'sentinel', + ), + ), - // SENTINEL get-master-addr-by-name svc - array('127.0.0.1', '6381'), + // SENTINEL get-master-addr-by-name svc + array('127.0.0.1', '6381'), - // SENTINEL slaves svc - array( - array( - 'name', '127.0.0.1:6382', - 'ip', '127.0.0.1', - 'port', '6382', - 'runid', '112cdebd22924a7d962be496f3a1c4c7c9bad93f', - 'flags', 'slave', - 'master-host', '127.0.0.1', - 'master-port', '6381', - ), - array( - 'name', '127.0.0.1:6383', - 'ip', '127.0.0.1', - 'port', '6383', - 'runid', '1c0bf1291797fbc5608c07a17da394147dc62817', - 'flags', 'slave', - 'master-host', '127.0.0.1', - 'master-port', '6381', - ), - ) - )); + // SENTINEL slaves svc + array( + array( + 'name', '127.0.0.1:6382', + 'ip', '127.0.0.1', + 'port', '6382', + 'runid', '112cdebd22924a7d962be496f3a1c4c7c9bad93f', + 'flags', 'slave', + 'master-host', '127.0.0.1', + 'master-port', '6381', + ), + array( + 'name', '127.0.0.1:6383', + 'ip', '127.0.0.1', + 'port', '6383', + 'runid', '1c0bf1291797fbc5608c07a17da394147dc62817', + 'flags', 'slave', + 'master-host', '127.0.0.1', + 'master-port', '6381', + ), + ) + )); $sentinel2 = $this->getMockSentinelConnection('tcp://127.0.0.1:5382?alias=sentinel2'); @@ -368,14 +375,15 @@ class SentinelReplicationTest extends PredisTestCase public function testMethodGetMasterAsksSentinelForMasterOnMasterNotSet() { $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); - $sentinel1->expects($this->at(0)) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'SENTINEL', array('get-master-addr-by-name', 'svc') - )) - ->will($this->returnValue( - array('127.0.0.1', '6381') - )); + $sentinel1 + ->expects($this->at(0)) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'SENTINEL', array('get-master-addr-by-name', 'svc') + )) + ->will($this->returnValue( + array('127.0.0.1', '6381') + )); $replication = $this->getReplicationConnection('svc', array($sentinel1)); @@ -390,14 +398,15 @@ class SentinelReplicationTest extends PredisTestCase public function testMethodGetMasterThrowsExceptionOnNoAvailableSentinels() { $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); - $sentinel1->expects($this->any()) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'SENTINEL', array('get-master-addr-by-name', 'svc') - )) - ->will($this->throwException( - new Connection\ConnectionException($sentinel1, 'Unknown connection error [127.0.0.1:5381]') - )); + $sentinel1 + ->expects($this->any()) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'SENTINEL', array('get-master-addr-by-name', 'svc') + )) + ->will($this->throwException( + new Connection\ConnectionException($sentinel1, 'Unknown connection error [127.0.0.1:5381]') + )); $replication = $this->getReplicationConnection('svc', array($sentinel1)); @@ -410,33 +419,34 @@ class SentinelReplicationTest extends PredisTestCase public function testMethodGetSlavesOnEmptySlavePoolAsksSentinelForSlaves() { $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); - $sentinel1->expects($this->at(0)) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'SENTINEL', array('slaves', 'svc') - )) - ->will($this->returnValue( - array( - array( - 'name', '127.0.0.1:6382', - 'ip', '127.0.0.1', - 'port', '6382', - 'runid', '112cdebd22924a7d962be496f3a1c4c7c9bad93f', - 'flags', 'slave', - 'master-host', '127.0.0.1', - 'master-port', '6381', - ), - array( - 'name', '127.0.0.1:6383', - 'ip', '127.0.0.1', - 'port', '6383', - 'runid', '1c0bf1291797fbc5608c07a17da394147dc62817', - 'flags', 'slave', - 'master-host', '127.0.0.1', - 'master-port', '6381', - ), - ) - )); + $sentinel1 + ->expects($this->at(0)) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'SENTINEL', array('slaves', 'svc') + )) + ->will($this->returnValue( + array( + array( + 'name', '127.0.0.1:6382', + 'ip', '127.0.0.1', + 'port', '6382', + 'runid', '112cdebd22924a7d962be496f3a1c4c7c9bad93f', + 'flags', 'slave', + 'master-host', '127.0.0.1', + 'master-port', '6381', + ), + array( + 'name', '127.0.0.1:6383', + 'ip', '127.0.0.1', + 'port', '6383', + 'runid', '1c0bf1291797fbc5608c07a17da394147dc62817', + 'flags', 'slave', + 'master-host', '127.0.0.1', + 'master-port', '6381', + ), + ) + )); $replication = $this->getReplicationConnection('svc', array($sentinel1)); @@ -454,14 +464,15 @@ class SentinelReplicationTest extends PredisTestCase public function testMethodGetSlavesThrowsExceptionOnNoAvailableSentinels() { $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); - $sentinel1->expects($this->any()) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'SENTINEL', array('slaves', 'svc') - )) - ->will($this->throwException( - new Connection\ConnectionException($sentinel1, 'Unknown connection error [127.0.0.1:5381]') - )); + $sentinel1 + ->expects($this->any()) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'SENTINEL', array('slaves', 'svc') + )) + ->will($this->throwException( + new Connection\ConnectionException($sentinel1, 'Unknown connection error [127.0.0.1:5381]') + )); $replication = $this->getReplicationConnection('svc', array($sentinel1)); @@ -487,12 +498,14 @@ class SentinelReplicationTest extends PredisTestCase $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master'); - $master->expects($this->never()) - ->method('connect'); + $master + ->expects($this->never()) + ->method('connect'); $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1'); - $slave1->expects($this->once()) - ->method('connect'); + $slave1 + ->expects($this->once()) + ->method('connect'); $replication = $this->getReplicationConnection('svc', array($sentinel1)); @@ -508,42 +521,46 @@ class SentinelReplicationTest extends PredisTestCase public function testMethodConnectOnEmptySlavePoolAsksSentinelForSlavesAndForcesConnectionToSlave() { $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); - $sentinel1->expects($this->any()) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'SENTINEL', array('slaves', 'svc') - )) - ->will($this->returnValue( - array( - array( - 'name', '127.0.0.1:6382', - 'ip', '127.0.0.1', - 'port', '6382', - 'runid', '112cdebd22924a7d962be496f3a1c4c7c9bad93f', - 'flags', 'slave', - 'master-host', '127.0.0.1', - 'master-port', '6381', - ), - ) - )); + $sentinel1 + ->expects($this->any()) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'SENTINEL', array('slaves', 'svc') + )) + ->will($this->returnValue( + array( + array( + 'name', '127.0.0.1:6382', + 'ip', '127.0.0.1', + 'port', '6382', + 'runid', '112cdebd22924a7d962be496f3a1c4c7c9bad93f', + 'flags', 'slave', + 'master-host', '127.0.0.1', + 'master-port', '6381', + ), + ) + )); $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master'); - $master->expects($this->never()) - ->method('connect'); + $master + ->expects($this->never()) + ->method('connect'); $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1'); - $slave1->expects($this->once()) - ->method('connect'); + $slave1 + ->expects($this->once()) + ->method('connect'); $factory = $this->getMock('Predis\Connection\FactoryInterface'); - $factory->expects($this->once()) - ->method('create') - ->with(array( - 'host' => '127.0.0.1', - 'port' => '6382', - 'alias' => 'slave-127.0.0.1:6382', - )) - ->will($this->returnValue($slave1)); + $factory + ->expects($this->once()) + ->method('create') + ->with(array( + 'host' => '127.0.0.1', + 'port' => '6382', + 'alias' => 'slave-127.0.0.1:6382', + )) + ->will($this->returnValue($slave1)); $replication = $this->getReplicationConnection('svc', array($sentinel1), $factory); @@ -558,16 +575,24 @@ class SentinelReplicationTest extends PredisTestCase public function testMethodDisconnectForcesDisconnectionOnAllConnectionsInPool() { $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); - $sentinel1->expects($this->never())->method('disconnect'); + $sentinel1 + ->expects($this->never()) + ->method('disconnect'); $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master'); - $master->expects($this->once())->method('disconnect'); + $master + ->expects($this->once()) + ->method('disconnect'); $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1'); - $slave1->expects($this->once())->method('disconnect'); + $slave1 + ->expects($this->once()) + ->method('disconnect'); $slave2 = $this->getMockConnection('tcp://127.0.0.1:6383?alias=slave2'); - $slave2->expects($this->once())->method('disconnect'); + $slave2 + ->expects($this->once()) + ->method('disconnect'); $replication = $this->getReplicationConnection('svc', array($sentinel1)); @@ -586,9 +611,10 @@ class SentinelReplicationTest extends PredisTestCase $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1'); - $slave1->expects($this->exactly(2)) - ->method('isConnected') - ->will($this->onConsecutiveCalls(true, false)); + $slave1 + ->expects($this->exactly(2)) + ->method('isConnected') + ->will($this->onConsecutiveCalls(true, false)); $replication = $this->getReplicationConnection('svc', array($sentinel1)); @@ -612,6 +638,7 @@ class SentinelReplicationTest extends PredisTestCase $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1'); $replication = $this->getReplicationConnection('svc', array($sentinel1)); + $replication->add($master); $replication->add($slave1); @@ -628,13 +655,19 @@ class SentinelReplicationTest extends PredisTestCase $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master'); - $master->expects($this->once())->method('connect'); + $master + ->expects($this->once()) + ->method('connect'); $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1'); - $slave1->expects($this->never())->method('connect'); + $slave1 + ->expects($this->never()) + ->method('connect'); $slave2 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave2'); - $slave2->expects($this->once())->method('connect'); + $slave2 + ->expects($this->once()) + ->method('connect'); $replication = $this->getReplicationConnection('svc', array($sentinel1)); @@ -677,10 +710,14 @@ class SentinelReplicationTest extends PredisTestCase $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master'); - $master->expects($this->once())->method('connect'); + $master + ->expects($this->once()) + ->method('connect'); $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1'); - $slave1->expects($this->never())->method('connect'); + $slave1 + ->expects($this->never()) + ->method('connect'); $replication = $this->getReplicationConnection('svc', array($sentinel1)); @@ -700,10 +737,14 @@ class SentinelReplicationTest extends PredisTestCase $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master'); - $master->expects($this->never())->method('connect'); + $master + ->expects($this->never()) + ->method('connect'); $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1'); - $slave1->expects($this->once())->method('connect'); + $slave1 + ->expects($this->once()) + ->method('connect'); $replication = $this->getReplicationConnection('svc', array($sentinel1)); @@ -723,15 +764,17 @@ class SentinelReplicationTest extends PredisTestCase $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master'); - $master->expects($this->exactly(2)) - ->method('isConnected') - ->will($this->onConsecutiveCalls(false, true)); - $master->expects($this->at(2)) - ->method('executeCommand') - ->with($this->isRedisCommand('ROLE')) - ->will($this->returnValue(array( - 'master', 3129659, array(array('127.0.0.1', 6382, 3129242)), - ))); + $master + ->expects($this->exactly(2)) + ->method('isConnected') + ->will($this->onConsecutiveCalls(false, true)); + $master + ->expects($this->at(2)) + ->method('executeCommand') + ->with($this->isRedisCommand('ROLE')) + ->will($this->returnValue(array( + 'master', 3129659, array(array('127.0.0.1', 6382, 3129242)), + ))); $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1'); @@ -759,16 +802,17 @@ class SentinelReplicationTest extends PredisTestCase $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master'); $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1'); - $slave1->expects($this->exactly(2)) - ->method('isConnected') - ->will($this->onConsecutiveCalls(false, true)); - - $slave1->expects($this->at(2)) - ->method('executeCommand') - ->with($this->isRedisCommand('ROLE')) - ->will($this->returnValue(array( - 'slave', '127.0.0.1', 9000, 'connected', 3167038, - ))); + $slave1 + ->expects($this->exactly(2)) + ->method('isConnected') + ->will($this->onConsecutiveCalls(false, true)); + $slave1 + ->expects($this->at(2)) + ->method('executeCommand') + ->with($this->isRedisCommand('ROLE')) + ->will($this->returnValue(array( + 'slave', '127.0.0.1', 9000, 'connected', 3167038, + ))); $replication = $this->getReplicationConnection('svc', array($sentinel1)); @@ -792,26 +836,30 @@ class SentinelReplicationTest extends PredisTestCase $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master'); - $master->expects($this->exactly(2)) - ->method('isConnected') - ->will($this->onConsecutiveCalls(false, true)); - $master->expects($this->at(2)) - ->method('executeCommand') - ->with($this->isRedisCommand('ROLE')) - ->will($this->returnValue(array( - 'master', 3129659, array(array('127.0.0.1', 6382, 3129242)), - ))); + $master + ->expects($this->exactly(2)) + ->method('isConnected') + ->will($this->onConsecutiveCalls(false, true)); + $master + ->expects($this->at(2)) + ->method('executeCommand') + ->with($this->isRedisCommand('ROLE')) + ->will($this->returnValue(array( + 'master', 3129659, array(array('127.0.0.1', 6382, 3129242)), + ))); $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1'); - $slave1->expects($this->exactly(1)) - ->method('isConnected') - ->will($this->onConsecutiveCalls(false)); - $slave1->expects($this->at(2)) - ->method('executeCommand') - ->with($this->isRedisCommand('ROLE')) - ->will($this->returnValue(array( - 'slave', '127.0.0.1', 9000, 'connected', 3167038, - ))); + $slave1 + ->expects($this->exactly(1)) + ->method('isConnected') + ->will($this->onConsecutiveCalls(false)); + $slave1 + ->expects($this->at(2)) + ->method('executeCommand') + ->with($this->isRedisCommand('ROLE')) + ->will($this->returnValue(array( + 'slave', '127.0.0.1', 9000, 'connected', 3167038, + ))); $replication = $this->getReplicationConnection('svc', array($sentinel1)); @@ -841,15 +889,17 @@ class SentinelReplicationTest extends PredisTestCase $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master'); - $master->expects($this->once()) - ->method('isConnected') - ->will($this->returnValue(false)); - $master->expects($this->at(2)) - ->method('executeCommand') - ->with($this->isRedisCommand('ROLE')) - ->will($this->returnValue(array( - 'slave', '127.0.0.1', 9000, 'connected', 3167038, - ))); + $master + ->expects($this->once()) + ->method('isConnected') + ->will($this->returnValue(false)); + $master + ->expects($this->at(2)) + ->method('executeCommand') + ->with($this->isRedisCommand('ROLE')) + ->will($this->returnValue(array( + 'slave', '127.0.0.1', 9000, 'connected', 3167038, + ))); $replication = $this->getReplicationConnection('svc', array($sentinel1)); @@ -864,35 +914,38 @@ class SentinelReplicationTest extends PredisTestCase public function testGetConnectionReturnsMasterForReadOnlyOperationsOnUnavailableSlaves() { $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); - $sentinel1->expects($this->once()) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'SENTINEL', array('slaves', 'svc') - )) - ->will($this->returnValue( - array( - array( - 'name', '127.0.0.1:6382', - 'ip', '127.0.0.1', - 'port', '6382', - 'runid', '1c0bf1291797fbc5608c07a17da394147dc62817', - 'flags', 'slave,s_down,disconnected', - 'master-host', '127.0.0.1', - 'master-port', '6381', - ), - ) - )); + $sentinel1 + ->expects($this->once()) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'SENTINEL', array('slaves', 'svc') + )) + ->will($this->returnValue( + array( + array( + 'name', '127.0.0.1:6382', + 'ip', '127.0.0.1', + 'port', '6382', + 'runid', '1c0bf1291797fbc5608c07a17da394147dc62817', + 'flags', 'slave,s_down,disconnected', + 'master-host', '127.0.0.1', + 'master-port', '6381', + ), + ) + )); $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master'); - $master->expects($this->once()) - ->method('isConnected') - ->will($this->returnValue(false)); - $master->expects($this->at(2)) - ->method('executeCommand') - ->with($this->isRedisCommand('ROLE')) - ->will($this->returnValue(array( - 'master', '0', array(), - ))); + $master + ->expects($this->once()) + ->method('isConnected') + ->will($this->returnValue(false)); + $master + ->expects($this->at(2)) + ->method('executeCommand') + ->with($this->isRedisCommand('ROLE')) + ->will($this->returnValue(array( + 'master', '0', array(), + ))); $replication = $this->getReplicationConnection('svc', array($sentinel1)); @@ -915,22 +968,30 @@ class SentinelReplicationTest extends PredisTestCase $cmdSetResponse = Response\Status::get('OK'); $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master'); - $master->expects($this->any()) - ->method('isConnected') - ->will($this->returnValue(true)); - $master->expects($this->at(2)) - ->method('executeCommand') - ->with($this->isRedisCommand('SET', array('key', $cmdGetResponse))) - ->will($this->returnValue($cmdSetResponse)); + $master + ->expects($this->any()) + ->method('isConnected') + ->will($this->returnValue(true)); + $master + ->expects($this->at(2)) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'SET', array('key', $cmdGetResponse) + )) + ->will($this->returnValue($cmdSetResponse)); $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1'); - $slave1->expects($this->any()) - ->method('isConnected') - ->will($this->returnValue(true)); - $slave1->expects($this->at(2)) - ->method('executeCommand') - ->with($this->isRedisCommand('GET', array('key'))) - ->will($this->returnValue($cmdGetResponse)); + $slave1 + ->expects($this->any()) + ->method('isConnected') + ->will($this->returnValue(true)); + $slave1 + ->expects($this->at(2)) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'GET', array('key') + )) + ->will($this->returnValue($cmdGetResponse)); $replication = $this->getReplicationConnection('svc', array($sentinel1)); @@ -947,59 +1008,70 @@ class SentinelReplicationTest extends PredisTestCase public function testMethodExecuteCommandRetriesReadOnlyCommandOnNextSlaveOnFailure() { $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); - $sentinel1->expects($this->any()) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'SENTINEL', array('slaves', 'svc') - )) - ->will($this->returnValue( - array( - array( - 'name', '127.0.0.1:6383', - 'ip', '127.0.0.1', - 'port', '6383', - 'runid', '1c0bf1291797fbc5608c07a17da394147dc62817', - 'flags', 'slave', - 'master-host', '127.0.0.1', - 'master-port', '6381', - ), - ) - )); + $sentinel1 + ->expects($this->any()) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'SENTINEL', array('slaves', 'svc') + )) + ->will($this->returnValue( + array( + array( + 'name', '127.0.0.1:6383', + 'ip', '127.0.0.1', + 'port', '6383', + 'runid', '1c0bf1291797fbc5608c07a17da394147dc62817', + 'flags', 'slave', + 'master-host', '127.0.0.1', + 'master-port', '6381', + ), + ) + )); $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master'); - $master->expects($this->any()) - ->method('isConnected') - ->will($this->returnValue(true)); + $master + ->expects($this->any()) + ->method('isConnected') + ->will($this->returnValue(true)); $slave1 = $this->getMockConnection('tcp://127.0.0.1:6382?alias=slave1'); - $slave1->expects($this->any()) - ->method('isConnected') - ->will($this->returnValue(true)); - $slave1->expects($this->at(2)) - ->method('executeCommand') - ->with($this->isRedisCommand('GET', array('key'))) - ->will($this->throwException( - new Connection\ConnectionException($slave1, 'Unknown connection error [127.0.0.1:6382]') - )); + $slave1 + ->expects($this->any()) + ->method('isConnected') + ->will($this->returnValue(true)); + $slave1 + ->expects($this->at(2)) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'GET', array('key') + )) + ->will($this->throwException( + new Connection\ConnectionException($slave1, 'Unknown connection error [127.0.0.1:6382]') + )); $slave2 = $this->getMockConnection('tcp://127.0.0.1:6383?alias=slave2'); - $slave2->expects($this->any()) - ->method('isConnected') - ->will($this->returnValue(true)); - $slave2->expects($this->at(2)) - ->method('executeCommand') - ->with($this->isRedisCommand('GET', array('key'))) - ->will($this->returnValue('value')); + $slave2 + ->expects($this->any()) + ->method('isConnected') + ->will($this->returnValue(true)); + $slave2 + ->expects($this->at(2)) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'GET', array('key') + )) + ->will($this->returnValue('value')); $factory = $this->getMock('Predis\Connection\FactoryInterface'); - $factory->expects($this->once()) - ->method('create') - ->with(array( - 'host' => '127.0.0.1', - 'port' => '6383', - 'alias' => 'slave-127.0.0.1:6383', - )) - ->will($this->returnValue($slave2)); + $factory + ->expects($this->once()) + ->method('create') + ->with(array( + 'host' => '127.0.0.1', + 'port' => '6383', + 'alias' => 'slave-127.0.0.1:6383', + )) + ->will($this->returnValue($slave2)); $replication = $this->getReplicationConnection('svc', array($sentinel1), $factory); @@ -1017,44 +1089,54 @@ class SentinelReplicationTest extends PredisTestCase public function testMethodExecuteCommandRetriesWriteCommandOnNewMasterOnFailure() { $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); - $sentinel1->expects($this->any()) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'SENTINEL', array('get-master-addr-by-name', 'svc') - )) - ->will($this->returnValue( - array('127.0.0.1', '6391') - )); + $sentinel1 + ->expects($this->any()) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'SENTINEL', array('get-master-addr-by-name', 'svc') + )) + ->will($this->returnValue( + array('127.0.0.1', '6391') + )); $masterOld = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master'); - $masterOld->expects($this->any()) - ->method('isConnected') - ->will($this->returnValue(true)); - $masterOld->expects($this->at(2)) - ->method('executeCommand') - ->with($this->isRedisCommand('DEL', array('key'))) - ->will($this->throwException( - new Connection\ConnectionException($masterOld, 'Unknown connection error [127.0.0.1:6381]') - )); + $masterOld + ->expects($this->any()) + ->method('isConnected') + ->will($this->returnValue(true)); + $masterOld + ->expects($this->at(2)) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'DEL', array('key') + )) + ->will($this->throwException( + new Connection\ConnectionException($masterOld, 'Unknown connection error [127.0.0.1:6381]') + )); $masterNew = $this->getMockConnection('tcp://127.0.0.1:6391?alias=master'); - $masterNew->expects($this->any()) - ->method('isConnected') - ->will($this->returnValue(true)); - $masterNew->expects($this->at(2)) - ->method('executeCommand') - ->with($this->isRedisCommand('DEL', array('key'))) - ->will($this->returnValue(1)); + $masterNew + ->expects($this->any()) + ->method('isConnected') + ->will($this->returnValue(true)); + $masterNew + ->expects($this->at(2)) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'DEL', array('key') + )) + ->will($this->returnValue(1)); $factory = $this->getMock('Predis\Connection\FactoryInterface'); - $factory->expects($this->once()) - ->method('create') - ->with(array( - 'host' => '127.0.0.1', - 'port' => '6391', - 'alias' => 'master', - )) - ->will($this->returnValue($masterNew)); + $factory + ->expects($this->once()) + ->method('create') + ->with(array( + 'host' => '127.0.0.1', + 'port' => '6391', + 'alias' => 'master', + )) + ->will($this->returnValue($masterNew)); $replication = $this->getReplicationConnection('svc', array($sentinel1), $factory); @@ -1073,23 +1155,28 @@ class SentinelReplicationTest extends PredisTestCase public function testMethodExecuteCommandThrowsExceptionOnUnknownServiceName() { $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); - $sentinel1->expects($this->any()) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'SENTINEL', array('get-master-addr-by-name', 'svc') - )) - ->will($this->returnValue(null)); + $sentinel1 + ->expects($this->any()) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'SENTINEL', array('get-master-addr-by-name', 'svc') + )) + ->will($this->returnValue(null)); $masterOld = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master'); - $masterOld->expects($this->any()) - ->method('isConnected') - ->will($this->returnValue(true)); - $masterOld->expects($this->at(2)) - ->method('executeCommand') - ->with($this->isRedisCommand('DEL', array('key'))) - ->will($this->throwException( - new Connection\ConnectionException($masterOld, 'Unknown connection error [127.0.0.1:6381]') - )); + $masterOld + ->expects($this->any()) + ->method('isConnected') + ->will($this->returnValue(true)); + $masterOld + ->expects($this->at(2)) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'DEL', array('key') + )) + ->will($this->throwException( + new Connection\ConnectionException($masterOld, 'Unknown connection error [127.0.0.1:6381]') + )); $replication = $this->getReplicationConnection('svc', array($sentinel1)); @@ -1108,25 +1195,30 @@ class SentinelReplicationTest extends PredisTestCase public function testMethodExecuteCommandThrowsExceptionOnConnectionFailureAndNoAvailableSentinels() { $sentinel1 = $this->getMockSentinelConnection('tcp://127.0.0.1:5381?alias=sentinel1'); - $sentinel1->expects($this->any()) - ->method('executeCommand') - ->with($this->isRedisCommand( - 'SENTINEL', array('get-master-addr-by-name', 'svc') - )) - ->will($this->throwException( - new Connection\ConnectionException($sentinel1, 'Unknown connection error [127.0.0.1:5381]') - )); + $sentinel1 + ->expects($this->any()) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'SENTINEL', array('get-master-addr-by-name', 'svc') + )) + ->will($this->throwException( + new Connection\ConnectionException($sentinel1, 'Unknown connection error [127.0.0.1:5381]') + )); $master = $this->getMockConnection('tcp://127.0.0.1:6381?alias=master'); - $master->expects($this->any()) - ->method('isConnected') - ->will($this->returnValue(true)); - $master->expects($this->at(2)) - ->method('executeCommand') - ->with($this->isRedisCommand('DEL', array('key'))) - ->will($this->throwException( - new Connection\ConnectionException($master, 'Unknown connection error [127.0.0.1:6381]') - )); + $master + ->expects($this->any()) + ->method('isConnected') + ->will($this->returnValue(true)); + $master + ->expects($this->at(2)) + ->method('executeCommand') + ->with($this->isRedisCommand( + 'DEL', array('key') + )) + ->will($this->throwException( + new Connection\ConnectionException($master, 'Unknown connection error [127.0.0.1:6381]') + )); $replication = $this->getReplicationConnection('svc', array($sentinel1)); diff --git a/tests/Predis/Connection/StreamConnectionTest.php b/tests/Predis/Connection/StreamConnectionTest.php index 6b31b65b..7690be19 100644 --- a/tests/Predis/Connection/StreamConnectionTest.php +++ b/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'); diff --git a/tests/Predis/Monitor/ConsumerTest.php b/tests/Predis/Monitor/ConsumerTest.php index 1fd9ccad..966c8f11 100644 --- a/tests/Predis/Monitor/ConsumerTest.php +++ b/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); diff --git a/tests/Predis/Pipeline/AtomicTest.php b/tests/Predis/Pipeline/AtomicTest.php index 369aa2d1..7de5fff6 100644 --- a/tests/Predis/Pipeline/AtomicTest.php +++ b/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(); diff --git a/tests/Predis/Pipeline/FireAndForgetTest.php b/tests/Predis/Pipeline/FireAndForgetTest.php index a1ce967f..44b68536 100644 --- a/tests/Predis/Pipeline/FireAndForgetTest.php +++ b/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)); diff --git a/tests/Predis/Pipeline/PipelineTest.php b/tests/Predis/Pipeline/PipelineTest.php index eb8e47ab..7d867ef1 100644 --- a/tests/Predis/Pipeline/PipelineTest.php +++ b/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); } diff --git a/tests/Predis/Protocol/Text/CompositeProtocolProcessorTest.php b/tests/Predis/Protocol/Text/CompositeProtocolProcessorTest.php index 21552c1f..c7e692e6 100644 --- a/tests/Predis/Protocol/Text/CompositeProtocolProcessorTest.php +++ b/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)); } diff --git a/tests/Predis/Protocol/Text/Handler/BulkResponseTest.php b/tests/Predis/Protocol/Text/Handler/BulkResponseTest.php index 1eb80d54..b388bd0e 100644 --- a/tests/Predis/Protocol/Text/Handler/BulkResponseTest.php +++ b/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'); } diff --git a/tests/Predis/Protocol/Text/Handler/ErrorResponseTest.php b/tests/Predis/Protocol/Text/Handler/ErrorResponseTest.php index 00b3dc7c..4e990a82 100644 --- a/tests/Predis/Protocol/Text/Handler/ErrorResponseTest.php +++ b/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); diff --git a/tests/Predis/Protocol/Text/Handler/IntegerResponseTest.php b/tests/Predis/Protocol/Text/Handler/IntegerResponseTest.php index a2d36d7a..7551dfd3 100644 --- a/tests/Predis/Protocol/Text/Handler/IntegerResponseTest.php +++ b/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'); } diff --git a/tests/Predis/Protocol/Text/Handler/MultiBulkResponseTest.php b/tests/Predis/Protocol/Text/Handler/MultiBulkResponseTest.php index 95ce4a93..2d2e3126 100644 --- a/tests/Predis/Protocol/Text/Handler/MultiBulkResponseTest.php +++ b/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'); } diff --git a/tests/Predis/Protocol/Text/Handler/StatusResponseTest.php b/tests/Predis/Protocol/Text/Handler/StatusResponseTest.php index 185c393a..45583970 100644 --- a/tests/Predis/Protocol/Text/Handler/StatusResponseTest.php +++ b/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); diff --git a/tests/Predis/Protocol/Text/Handler/StreamableMultiBulkResponseTest.php b/tests/Predis/Protocol/Text/Handler/StreamableMultiBulkResponseTest.php index b6e62118..184f5270 100644 --- a/tests/Predis/Protocol/Text/Handler/StreamableMultiBulkResponseTest.php +++ b/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'); } diff --git a/tests/Predis/Protocol/Text/ProtocolProcessorTest.php b/tests/Predis/Protocol/Text/ProtocolProcessorTest.php index 82d8e553..2e03a231 100644 --- a/tests/Predis/Protocol/Text/ProtocolProcessorTest.php +++ b/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); } diff --git a/tests/Predis/Protocol/Text/RequestSerializerTest.php b/tests/Predis/Protocol/Text/RequestSerializerTest.php index a9e91b61..fe945674 100644 --- a/tests/Predis/Protocol/Text/RequestSerializerTest.php +++ b/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); diff --git a/tests/Predis/Protocol/Text/ResponseReaderTest.php b/tests/Predis/Protocol/Text/ResponseReaderTest.php index d469130a..83e362d7 100644 --- a/tests/Predis/Protocol/Text/ResponseReaderTest.php +++ b/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); } } diff --git a/tests/Predis/PubSub/ConsumerTest.php b/tests/Predis/PubSub/ConsumerTest.php index 1bf24a4b..44447271 100644 --- a/tests/Predis/PubSub/ConsumerTest.php +++ b/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')); diff --git a/tests/Predis/PubSub/DispatcherLoopTest.php b/tests/Predis/PubSub/DispatcherLoopTest.php index dff9368b..c4db7212 100644 --- a/tests/Predis/PubSub/DispatcherLoopTest.php +++ b/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); diff --git a/tests/Predis/Replication/ReplicationStrategyTest.php b/tests/Predis/Replication/ReplicationStrategyTest.php index be05feb1..bde9f17b 100644 --- a/tests/Predis/Replication/ReplicationStrategyTest.php +++ b/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)); diff --git a/tests/Predis/Response/Iterator/MultiBulkTupleTest.php b/tests/Predis/Response/Iterator/MultiBulkTupleTest.php index b7a99226..2e5b6670 100644 --- a/tests/Predis/Response/Iterator/MultiBulkTupleTest.php +++ b/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); diff --git a/tests/Predis/Transaction/MultiExecTest.php b/tests/Predis/Transaction/MultiExecTest.php index 55c9483e..b08a5e39 100644 --- a/tests/Predis/Transaction/MultiExecTest.php +++ b/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; }