[tests] Start improving test suite.

- Make use of more typehints for function parameters
- Make use of typehints for function return values
- Use @var where needed to give proper hints to IDEs and avoid warnings
- Replace MockObject::setMethods() with addMethods() and onlyMethods()
- Rewording of some phpdocs
This commit is contained in:
Daniele Alessandri
2020-08-28 18:59:10 +02:00
parent c2ede30394
commit 36c9bb047e
236 changed files with 2887 additions and 2454 deletions
+122 -91
View File
@@ -12,6 +12,12 @@
namespace Predis;
use PredisTestCase;
use PHPUnit\Framework\MockObject\MockObject;
use Predis\Connection\ParametersInterface;
use Predis\Command\Factory as CommandFactory;
use Predis\Connection\NodeConnectionInterface;
use Predis\Command\Processor\KeyPrefixProcessor;
use Predis\Connection\Replication\MasterSlaveReplication;
/**
*
@@ -21,10 +27,11 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testConstructorWithoutArguments()
public function testConstructorWithoutArguments(): void
{
$client = new Client();
/** @var NodeConnectionInterface */
$connection = $client->getConnection();
$this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $connection);
@@ -41,10 +48,11 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testConstructorWithNullArgument()
public function testConstructorWithNullArgument(): void
{
$client = new Client(null);
/** @var NodeConnectionInterface */
$connection = $client->getConnection();
$this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $connection);
@@ -61,10 +69,11 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testConstructorWithNullAndNullArguments()
public function testConstructorWithNullAndNullArguments(): void
{
$client = new Client(null, null);
/** @var NodeConnectionInterface */
$connection = $client->getConnection();
$this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $connection);
@@ -81,11 +90,14 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testConstructorWithArrayArgument()
public function testConstructorWithArrayArgument(): void
{
$client = new Client($arg1 = array('host' => 'localhost', 'port' => 7000));
$parameters = $client->getConnection()->getParameters();
/** @var NodeConnectionInterface */
$connection = $client->getConnection();
$parameters = $connection->getParameters();
$this->assertSame($parameters->host, $arg1['host']);
$this->assertSame($parameters->port, $arg1['port']);
}
@@ -93,7 +105,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testConstructorThrowsExceptionWithArrayOfParametersArgumentAndMissingOption()
public function testConstructorThrowsExceptionWithArrayOfParametersArgumentAndMissingOption(): void
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Array of connection parameters requires `cluster`, `replication` or `aggregate` client option');
@@ -109,7 +121,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testConstructorWithArrayOfArrayArgumentAndClusterOption()
public function testConstructorWithArrayOfArrayArgumentAndClusterOption(): void
{
$arg1 = array(
array('host' => 'localhost', 'port' => 7000),
@@ -126,11 +138,14 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testConstructorWithStringArgument()
public function testConstructorWithStringArgument(): void
{
$client = new Client('tcp://localhost:7000');
$parameters = $client->getConnection()->getParameters();
/** @var NodeConnectionInterface */
$connection = $client->getConnection();
$parameters = $connection->getParameters();
$this->assertSame($parameters->host, 'localhost');
$this->assertSame($parameters->port, 7000);
}
@@ -138,7 +153,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testConstructorWithArrayOfStringArgument()
public function testConstructorWithArrayOfStringArgument(): void
{
$arg1 = array('tcp://localhost:7000', 'tcp://localhost:7001');
@@ -152,7 +167,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testConstructorWithArrayOfConnectionsArgument()
public function testConstructorWithArrayOfConnectionsArgument(): void
{
$arg1 = array(
$this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(),
@@ -169,7 +184,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testConstructorWithConnectionArgument()
public function testConstructorWithConnectionArgument(): void
{
$factory = new Connection\Factory();
$connection = $factory->create('tcp://localhost:7000');
@@ -179,7 +194,10 @@ class ClientTest extends PredisTestCase
$this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $client->getConnection());
$this->assertSame($connection, $client->getConnection());
$parameters = $client->getConnection()->getParameters();
/** @var NodeConnectionInterface */
$connection = $client->getConnection();
$parameters = $connection->getParameters();
$this->assertSame($parameters->host, 'localhost');
$this->assertSame($parameters->port, 7000);
}
@@ -187,7 +205,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testConstructorWithClusterArgument()
public function testConstructorWithClusterArgument(): void
{
$cluster = new Connection\Cluster\PredisCluster();
@@ -203,7 +221,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testConstructorWithReplicationArgument()
public function testConstructorWithReplicationArgument(): void
{
$replication = new Connection\Replication\MasterSlaveReplication();
@@ -219,12 +237,12 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testConstructorWithCallableArgument()
public function testConstructorWithCallableArgument(): void
{
$connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock();
$callable = $this->getMockBuilder('stdClass')
->setMethods(array('__invoke'))
->addMethods(array('__invoke'))
->getMock();
$callable
->expects($this->once())
@@ -240,7 +258,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testConstructorWithCallableConnectionInitializerThrowsExceptionOnInvalidReturnType()
public function testConstructorWithCallableConnectionInitializerThrowsExceptionOnInvalidReturnType(): void
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Callable parameters must return a valid connection');
@@ -248,7 +266,7 @@ class ClientTest extends PredisTestCase
$wrongType = $this->getMockBuilder('stdClass')->getMock();
$callable = $this->getMockBuilder('stdClass')
->setMethods(array('__invoke'))
->addMethods(array('__invoke'))
->getMock();
$callable
->expects($this->once())
@@ -262,28 +280,36 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testConstructorWithNullAndArrayArgument()
public function testConstructorWithNullAndArrayArgument(): void
{
$connections = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock();
$arg2 = array('prefix' => 'prefix:', 'connections' => $connections);
$client = new Client(null, $arg2);
$this->assertInstanceOf('Predis\Command\FactoryInterface', $commands = $client->getCommandFactory());
$this->assertInstanceOf('Predis\Command\Processor\KeyPrefixProcessor', $commands->getProcessor());
$this->assertSame('prefix:', $commands->getProcessor()->getPrefix());
/** @var CommandFactory */
$commands = $client->getCommandFactory();
$this->assertInstanceOf('Predis\Command\FactoryInterface', $commands);
/** @var KeyPrefixProcessor */
$processor = $commands->getProcessor();
$this->assertInstanceOf('Predis\Command\Processor\KeyPrefixProcessor', $processor);
$this->assertSame('prefix:', $processor->getPrefix());
}
/**
* @group disconnected
*/
public function testConstructorWithArrayAndOptionReplication()
public function testConstructorWithArrayAndOptionReplication(): void
{
$arg1 = array('tcp://127.0.0.1:6379?role=master', 'tcp://127.0.0.1:6380?role=slave');
$arg2 = array('replication' => 'predis');
$client = new Client($arg1, $arg2);
$this->assertInstanceOf('Predis\Connection\Replication\ReplicationInterface', $connection = $client->getConnection());
/** @var MasterSlaveReplication */
$connection = $client->getConnection();
$this->assertInstanceOf('Predis\Connection\Replication\ReplicationInterface', $connection);
$this->assertSame('127.0.0.1:6379', (string) $connection->getConnectionByRole('master'));
$this->assertSame('127.0.0.1:6380', (string) $connection->getConnectionByRole('slave'));
}
@@ -291,14 +317,14 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testClusterOptionHasPrecedenceOverReplicationOptionAndAggregateOption()
public function testClusterOptionHasPrecedenceOverReplicationOptionAndAggregateOption(): void
{
$arg1 = array('tcp://host1', 'tcp://host2');
$connection = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface')->getMock();
$fncluster = $this->getMockBuilder('stdClass')
->setMethods(array('__invoke'))
->addMethods(array('__invoke'))
->getMock();
$fncluster
->expects($this->once())
@@ -307,14 +333,14 @@ class ClientTest extends PredisTestCase
->will($this->returnValue($connection));
$fnreplication = $this->getMockBuilder('stdClass')
->setMethods(array('__invoke'))
->addMethods(array('__invoke'))
->getMock();
$fnreplication
->expects($this->never())
->method('__invoke');
$fnaggregate = $this->getMockBuilder('stdClass')
->setMethods(array('__invoke'))
->addMethods(array('__invoke'))
->getMock();
$fnaggregate
->expects($this->never())
@@ -334,14 +360,14 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testReplicationOptionHasPrecedenceOverAggregateOption()
public function testReplicationOptionHasPrecedenceOverAggregateOption(): void
{
$arg1 = array('tcp://host1', 'tcp://host2');
$connection = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface')->getMock();
$fnreplication = $this->getMockBuilder('stdClass')
->setMethods(array('__invoke'))
->addMethods(array('__invoke'))
->getMock();
$fnreplication
->expects($this->once())
@@ -350,7 +376,7 @@ class ClientTest extends PredisTestCase
->will($this->returnValue($connection));
$fnaggregate = $this->getMockBuilder('stdClass')
->setMethods(array('__invoke'))
->addMethods(array('__invoke'))
->getMock();
$fnaggregate
->expects($this->never())
@@ -367,14 +393,14 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testAggregateOptionDoesNotTriggerAggregationInClient()
public function testAggregateOptionDoesNotTriggerAggregationInClient(): void
{
$arg1 = array('tcp://host1', 'tcp://host2');
$connection = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface')->getMock();
$fnaggregate = $this->getMockBuilder('stdClass')
->setMethods(array('__invoke'))
->addMethods(array('__invoke'))
->getMock();
$fnaggregate
->expects($this->once())
@@ -397,7 +423,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testConstructorWithInvalidArgumentType()
public function testConstructorWithInvalidArgumentType(): void
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Invalid type for connection parameters');
@@ -408,7 +434,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testConstructorWithInvalidOptionType()
public function testConstructorWithInvalidOptionType(): void
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Invalid type for client options');
@@ -419,7 +445,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testConnectAndDisconnect()
public function testConnectAndDisconnect(): void
{
$connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock();
$connection
@@ -437,7 +463,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testIsConnectedChecksConnectionState()
public function testIsConnectedChecksConnectionState(): void
{
$connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock();
$connection
@@ -451,7 +477,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testQuitIsAliasForDisconnect()
public function testQuitIsAliasForDisconnect(): void
{
$connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock();
$connection
@@ -465,7 +491,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testCreatesNewCommandUsingSpecifiedCommandFactory()
public function testCreatesNewCommandUsingSpecifiedCommandFactory(): void
{
$ping = $this->getCommandFactory()->create('ping', array());
@@ -483,7 +509,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testExecuteCommandReturnsParsedResponses()
public function testExecuteCommandReturnsParsedResponses(): void
{
$commands = $this->getCommandFactory();
@@ -511,7 +537,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testExecuteCommandThrowsExceptionOnRedisError()
public function testExecuteCommandThrowsExceptionOnRedisError(): void
{
$this->expectException('Predis\Response\ServerException');
$this->expectExceptionMessage('Operation against a key holding the wrong kind of value');
@@ -532,7 +558,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testExecuteCommandReturnsErrorResponseOnRedisError()
public function testExecuteCommandReturnsErrorResponseOnRedisError(): void
{
$ping = $this->getCommandFactory()->create('ping', array());
$expectedResponse = new Response\Error('ERR Operation against a key holding the wrong kind of value');
@@ -552,7 +578,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testCallingRedisCommandExecutesInstanceOfCommand()
public function testCallingRedisCommandExecutesInstanceOfCommand(): void
{
$ping = $this->getCommandFactory()->create('ping', array());
@@ -571,8 +597,10 @@ class ClientTest extends PredisTestCase
->will($this->returnValue($ping));
$options = array('commands' => $commands);
/** @var ClientInterface */
$client = $this->getMockBuilder('Predis\Client')
->setMethods(null)
->onlyMethods(array())
->setConstructorArgs(array($connection, $options))
->getMock();
@@ -582,7 +610,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testCallingRedisCommandThrowsExceptionOnServerError()
public function testCallingRedisCommandThrowsExceptionOnServerError(): void
{
$this->expectException('Predis\Response\ServerException');
$this->expectExceptionMessage('Operation against a key holding the wrong kind of value');
@@ -603,7 +631,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testCallingRedisCommandReturnsErrorResponseOnRedisError()
public function testCallingRedisCommandReturnsErrorResponseOnRedisError(): void
{
$expectedResponse = new Response\Error('ERR Operation against a key holding the wrong kind of value');
@@ -623,7 +651,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testRawCommand()
public function testRawCommand(): void
{
$connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock();
$connection
@@ -655,7 +683,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testRawCommandNeverAppliesPrefix()
public function testRawCommandNeverAppliesPrefix(): void
{
$connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock();
$connection
@@ -678,7 +706,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testRawCommandNeverThrowsExceptions()
public function testRawCommandNeverThrowsExceptions(): void
{
$message = 'ERR Mock error response';
$response = new Response\Error($message);
@@ -699,7 +727,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testThrowsExceptionOnNonRegisteredRedisCommand()
public function testThrowsExceptionOnNonRegisteredRedisCommand(): void
{
$this->expectException('Predis\ClientException');
$this->expectExceptionMessage("Command `INVALIDCOMMAND` is not a registered Redis command");
@@ -711,10 +739,11 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testGetClientByMethodReturnsInstanceOfSubclass()
public function testGetClientByMethodReturnsInstanceOfSubclass(): void
{
/** @var Client */
$client = $this->getMockBuilder('Predis\Client')
->setMethods(null)
->onlyMethods(array())
->setConstructorArgs(array(
array('tcp://host1?alias=node01', 'tcp://host2?alias=node02'),
array('cluster' => 'predis'),
@@ -728,12 +757,12 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testGetClientByMethodSupportsSelectingConnectionById()
public function testGetClientByMethodSupportsSelectingConnectionById(): void
{
$connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock();
$aggregate = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface')
->setMethods(array('getConnectionById'))
->onlyMethods(array('getConnectionById'))
->getMockForAbstractClass();
$aggregate
->expects($this->once())
@@ -751,7 +780,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testGetClientByMethodThrowsExceptionSelectingConnectionByUnknownId()
public function testGetClientByMethodThrowsExceptionSelectingConnectionByUnknownId(): void
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Cannot find a connection by id matching `127.0.0.1:7000`');
@@ -770,12 +799,12 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testGetClientByMethodSupportsSelectingConnectionByAlias()
public function testGetClientByMethodSupportsSelectingConnectionByAlias(): void
{
$connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock();
$aggregate = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface')
->setMethods(array('getConnectionByAlias'))
->addMethods(array('getConnectionByAlias'))
->getMockForAbstractClass();
$aggregate
->expects($this->once())
@@ -793,12 +822,12 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testGetClientByMethodSupportsSelectingConnectionByKey()
public function testGetClientByMethodSupportsSelectingConnectionByKey(): void
{
$connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock();
$aggregate = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface')
->setMethods(array('getConnectionByKey'))
->addMethods(array('getConnectionByKey'))
->getMockForAbstractClass();
$aggregate
->expects($this->once())
@@ -816,12 +845,12 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testGetClientByMethodSupportsSelectingConnectionBySlot()
public function testGetClientByMethodSupportsSelectingConnectionBySlot(): void
{
$connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock();
$aggregate = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface')
->setMethods(array('getConnectionBySlot'))
->addMethods(array('getConnectionBySlot'))
->getMockForAbstractClass();
$aggregate
->expects($this->once())
@@ -839,12 +868,12 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testGetClientByMethodSupportsSelectingConnectionByRole()
public function testGetClientByMethodSupportsSelectingConnectionByRole(): void
{
$connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock();
$aggregate = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface')
->setMethods(array('getConnectionByRole'))
->addMethods(array('getConnectionByRole'))
->getMockForAbstractClass();
$aggregate
->expects($this->once())
@@ -862,13 +891,13 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testGetClientByMethodSupportsSelectingConnectionByCommand()
public function testGetClientByMethodSupportsSelectingConnectionByCommand(): void
{
$command = \Predis\Command\RawCommand::create('GET', 'key');
$connection = $this->getMockBuilder('Predis\Connection\ConnectionInterface')->getMock();
$aggregate = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface')
->setMethods(array('getConnectionByCommand'))
->onlyMethods(array('getConnectionByCommand'))
->getMockForAbstractClass();
$aggregate
->expects($this->once())
@@ -886,7 +915,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testGetClientByMethodThrowsExceptionWhenSelectingConnectionByUnknownType()
public function testGetClientByMethodThrowsExceptionWhenSelectingConnectionByUnknownType(): void
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Invalid selector type: `unknown`');
@@ -899,7 +928,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testGetClientByMethodThrowsExceptionWhenConnectionDoesNotSupportSelectorType()
public function testGetClientByMethodThrowsExceptionWhenConnectionDoesNotSupportSelectorType(): void
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Selecting connection by id is not supported by Predis\Connection\StreamConnection');
@@ -912,7 +941,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testPipelineWithoutArgumentsReturnsPipeline()
public function testPipelineWithoutArgumentsReturnsPipeline(): void
{
$client = new Client();
@@ -922,7 +951,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testPipelineWithArrayReturnsPipeline()
public function testPipelineWithArrayReturnsPipeline(): void
{
$client = new Client();
@@ -934,10 +963,10 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testPipelineWithCallableExecutesPipeline()
public function testPipelineWithCallableExecutesPipeline(): void
{
$callable = $this->getMockBuilder('stdClass')
->setMethods(array('__invoke'))
->addMethods(array('__invoke'))
->getMock();
$callable
->expects($this->once())
@@ -951,7 +980,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testPubSubLoopWithoutArgumentsReturnsPubSubConsumer()
public function testPubSubLoopWithoutArgumentsReturnsPubSubConsumer(): void
{
$client = new Client();
@@ -961,7 +990,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testPubSubLoopWithArrayReturnsPubSubConsumerWithOptions()
public function testPubSubLoopWithArrayReturnsPubSubConsumerWithOptions(): void
{
$connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock();
$options = array('subscribe' => 'channel');
@@ -979,7 +1008,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testPubSubLoopWithArrayAndCallableExecutesPubSub()
public function testPubSubLoopWithArrayAndCallableExecutesPubSub(): void
{
// NOTE: we use a subscribe count of 0 in the message payload to trick
// the context and forcing it to be closed since there are no more
@@ -991,7 +1020,7 @@ class ClientTest extends PredisTestCase
->will($this->returnValue(array('subscribe', 'channel', 0)));
$callable = $this->getMockBuilder('stdClass')
->setMethods(array('__invoke'))
->addMethods(array('__invoke'))
->getMock();
$callable
->expects($this->once())
@@ -1004,7 +1033,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testPubSubLoopWithCallableReturningFalseStopsPubSubConsumer()
public function testPubSubLoopWithCallableReturningFalseStopsPubSubConsumer(): void
{
$connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock();
$connection
@@ -1021,7 +1050,7 @@ class ClientTest extends PredisTestCase
->will($this->returnValue(array('unsubscribe', 'channel', 0)));
$callable = $this->getMockBuilder('stdClass')
->setMethods(array('__invoke'))
->addMethods(array('__invoke'))
->getMock();
$callable
->expects($this->at(0))
@@ -1036,7 +1065,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testTransactionWithoutArgumentsReturnsMultiExec()
public function testTransactionWithoutArgumentsReturnsMultiExec(): void
{
$client = new Client();
@@ -1046,7 +1075,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testTransactionWithArrayReturnsMultiExecTransactionWithOptions()
public function testTransactionWithArrayReturnsMultiExecTransactionWithOptions(): void
{
$options = array('cas' => true, 'retry' => 3);
@@ -1067,7 +1096,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testTransactionWithArrayAndCallableExecutesMultiExec()
public function testTransactionWithArrayAndCallableExecutesMultiExec(): void
{
// We use CAS here as we don't care about the actual MULTI/EXEC context.
$options = array('cas' => true, 'retry' => 3);
@@ -1079,7 +1108,7 @@ class ClientTest extends PredisTestCase
->will($this->returnValue(new Response\Status('QUEUED')));
$callable = $this->getMockBuilder('stdClass')
->setMethods(array('__invoke'))
->addMethods(array('__invoke'))
->getMock();
$callable
->expects($this->once())
@@ -1093,7 +1122,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testMonitorReturnsMonitorConsumer()
public function testMonitorReturnsMonitorConsumer(): void
{
$connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock();
$client = new Client($connection);
@@ -1104,7 +1133,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testClientResendScriptCommandUsingEvalOnNoScriptErrors()
public function testClientResendScriptCommandUsingEvalOnNoScriptErrors(): void
{
$command = $this->getMockForAbstractClass('Predis\Command\ScriptCommand', array(), '', true, true, true, array('parseResponse'));
$command
@@ -1137,7 +1166,7 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testGetIteratorWithTraversableConnections()
public function testGetIteratorWithTraversableConnections(): void
{
$connection1 = $this->getMockConnection('tcp://127.0.0.1:6381');
$connection2 = $this->getMockConnection('tcp://127.0.0.1:6382');
@@ -1151,6 +1180,7 @@ class ClientTest extends PredisTestCase
$client = new Client($aggregate);
/** @var \Iterator */
$iterator = $client->getIterator();
$this->assertInstanceOf('\Predis\Client', $nodeClient = $iterator->current());
@@ -1173,11 +1203,12 @@ class ClientTest extends PredisTestCase
/**
* @group disconnected
*/
public function testGetIteratorWithNonTraversableConnectionNoException()
public function testGetIteratorWithNonTraversableConnectionNoException(): void
{
$connection = $this->getMockConnection('tcp://127.0.0.1:6381');
$client = new Client($connection);
/** @var \Iterator */
$iterator = $client->getIterator();
$this->assertInstanceOf('\Predis\Client', $nodeClient = $iterator->current());
@@ -1196,7 +1227,7 @@ class ClientTest extends PredisTestCase
*
* @return string URI string.
*/
protected function getParametersString(array $parameters)
protected function getParametersString(array $parameters): string
{
$defaults = $this->getDefaultParametersArray();
@@ -1215,18 +1246,18 @@ class ClientTest extends PredisTestCase
}
/**
* Returns a mock callable simulating an aggregate connection initializer.
* Returns a mock object simulating an aggregate connection initializer.
*
* @param mixed $parameters Expected connection parameters
* @param ParametersInterface|array|string $parameters Expected connection parameters
*
* @return callable
* @return callable|MockObject
*/
protected function getAggregateInitializer($parameters)
{
$connection = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface')->getMock();
$callable = $this->getMockBuilder('stdClass')
->setMethods(array('__invoke'))
->addMethods(array('__invoke'))
->getMock();
$callable
->expects($this->once())