From 843ad23ea7318b2d91b0e2d6ee2c06215e860b88 Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Wed, 1 Jun 2016 22:27:36 +0200 Subject: [PATCH] [tests] Move utility method into base test class. --- tests/PHPUnit/PredisTestCase.php | 26 ++++++++++++++++ tests/Predis/ClientTest.php | 26 ---------------- .../Aggregate/MasterSlaveReplicationTest.php | 30 ------------------- .../Aggregate/PredisClusterTest.php | 30 ------------------- .../Connection/Aggregate/RedisClusterTest.php | 30 ------------------- .../Aggregate/SentinelReplicationTest.php | 26 ---------------- 6 files changed, 26 insertions(+), 142 deletions(-) diff --git a/tests/PHPUnit/PredisTestCase.php b/tests/PHPUnit/PredisTestCase.php index a12ce792..ed159785 100644 --- a/tests/PHPUnit/PredisTestCase.php +++ b/tests/PHPUnit/PredisTestCase.php @@ -203,6 +203,32 @@ abstract class PredisTestCase extends \PHPUnit_Framework_TestCase return $client; } + /** + * Returns a base mocked connection from Predis\Connection\NodeConnectionInterface. + * + * @param mixed $parameters Optional parameters. + * + * @return mixed + */ + protected function getMockConnection($parameters = null) + { + $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); + + if ($parameters) { + $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)); + } + + return $connection; + } + /** * Returns the server version of the Redis instance used by the test suite. * diff --git a/tests/Predis/ClientTest.php b/tests/Predis/ClientTest.php index c08d1cca..93ef909f 100644 --- a/tests/Predis/ClientTest.php +++ b/tests/Predis/ClientTest.php @@ -892,30 +892,4 @@ class ClientTest extends PredisTestCase return $uriString; } - - /** - * Returns a base mocked connection from Predis\Connection\NodeConnectionInterface. - * - * @param mixed $parameters Optional parameters. - * - * @return mixed - */ - protected function getMockConnection($parameters = null) - { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); - - if ($parameters) { - $parameters = \Predis\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)); - } - - return $connection; - } } diff --git a/tests/Predis/Connection/Aggregate/MasterSlaveReplicationTest.php b/tests/Predis/Connection/Aggregate/MasterSlaveReplicationTest.php index 18dda8a0..0f210b76 100644 --- a/tests/Predis/Connection/Aggregate/MasterSlaveReplicationTest.php +++ b/tests/Predis/Connection/Aggregate/MasterSlaveReplicationTest.php @@ -1170,34 +1170,4 @@ repl_backlog_histlen:12978 $this->assertEquals($master, $unserialized->getConnectionById('master')); $this->assertEquals($slave1, $unserialized->getConnectionById('slave1')); } - - // ******************************************************************** // - // ---- HELPER METHODS ------------------------------------------------ // - // ******************************************************************** // - - /** - * Returns a base mocked connection from Predis\Connection\NodeConnectionInterface. - * - * @param mixed $parameters Optional parameters. - * - * @return mixed - */ - protected function getMockConnection($parameters = null) - { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); - - if ($parameters) { - $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)); - } - - return $connection; - } } diff --git a/tests/Predis/Connection/Aggregate/PredisClusterTest.php b/tests/Predis/Connection/Aggregate/PredisClusterTest.php index ef826e10..9dd3d086 100644 --- a/tests/Predis/Connection/Aggregate/PredisClusterTest.php +++ b/tests/Predis/Connection/Aggregate/PredisClusterTest.php @@ -397,34 +397,4 @@ class PredisClusterTest extends PredisTestCase $this->assertEquals($cluster, $unserialized); } - - // ******************************************************************** // - // ---- HELPER METHODS ------------------------------------------------ // - // ******************************************************************** // - - /** - * Returns a base mocked connection from Predis\Connection\NodeConnectionInterface. - * - * @param mixed $parameters Optional parameters. - * - * @return mixed - */ - protected function getMockConnection($parameters = null) - { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); - - if ($parameters) { - $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)); - } - - return $connection; - } } diff --git a/tests/Predis/Connection/Aggregate/RedisClusterTest.php b/tests/Predis/Connection/Aggregate/RedisClusterTest.php index 038041c5..2dfb3e76 100644 --- a/tests/Predis/Connection/Aggregate/RedisClusterTest.php +++ b/tests/Predis/Connection/Aggregate/RedisClusterTest.php @@ -1157,34 +1157,4 @@ class RedisClusterTest extends PredisTestCase $this->assertEquals($cluster, $unserialized); } - - // ******************************************************************** // - // ---- HELPER METHODS ------------------------------------------------ // - // ******************************************************************** // - - /** - * Returns a base mocked connection from Predis\Connection\NodeConnectionInterface. - * - * @param mixed $parameters Optional parameters. - * - * @return mixed - */ - protected function getMockConnection($parameters = null) - { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); - - if ($parameters) { - $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)); - } - - return $connection; - } } diff --git a/tests/Predis/Connection/Aggregate/SentinelReplicationTest.php b/tests/Predis/Connection/Aggregate/SentinelReplicationTest.php index d4a5116c..5fcef836 100644 --- a/tests/Predis/Connection/Aggregate/SentinelReplicationTest.php +++ b/tests/Predis/Connection/Aggregate/SentinelReplicationTest.php @@ -1216,30 +1216,4 @@ class SentinelReplicationTest extends PredisTestCase return $connection; } - - /** - * Returns a base mocked connection from Predis\Connection\NodeConnectionInterface. - * - * @param mixed $parameters Optional parameters. - * - * @return mixed - */ - protected function getMockConnection($parameters = null) - { - $connection = $this->getMock('Predis\Connection\NodeConnectionInterface'); - - if ($parameters) { - $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)); - } - - return $connection; - } }