From 2a7607f128bf2ad98e58db35d67bab22f40329fe Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Sun, 15 Dec 2013 10:09:08 +0100 Subject: [PATCH] Rename Predis\Connection\ConnectionFactory. --- .../Configuration/ConnectionFactoryOption.php | 7 ++-- .../{ConnectionFactory.php => Factory.php} | 2 +- ...toryInterface.php => FactoryInterface.php} | 2 +- lib/Predis/Connection/RedisCluster.php | 6 +-- tests/Predis/ClientTest.php | 16 ++++---- .../ConnectionFactoryOptionTest.php | 9 ++--- tests/Predis/Configuration/OptionsTest.php | 6 +-- ...nectionFactoryTest.php => FactoryTest.php} | 38 +++++++++---------- tests/Predis/Connection/RedisClusterTest.php | 8 ++-- 9 files changed, 45 insertions(+), 49 deletions(-) rename lib/Predis/Connection/{ConnectionFactory.php => Factory.php} (98%) rename lib/Predis/Connection/{ConnectionFactoryInterface.php => FactoryInterface.php} (97%) rename tests/Predis/Connection/{ConnectionFactoryTest.php => FactoryTest.php} (90%) diff --git a/lib/Predis/Configuration/ConnectionFactoryOption.php b/lib/Predis/Configuration/ConnectionFactoryOption.php index 2b99a6b7..c8c30758 100644 --- a/lib/Predis/Configuration/ConnectionFactoryOption.php +++ b/lib/Predis/Configuration/ConnectionFactoryOption.php @@ -12,8 +12,7 @@ namespace Predis\Configuration; use InvalidArgumentException; -use Predis\Connection\ConnectionFactory; -use Predis\Connection\ConnectionFactoryInterface; +use Predis\Connection; /** * Configures a connection factory used by the client to create new connection @@ -28,7 +27,7 @@ class ConnectionFactoryOption implements OptionInterface */ public function filter(OptionsInterface $options, $value) { - if ($value instanceof ConnectionFactoryInterface) { + if ($value instanceof Connection\FactoryInterface) { return $value; } else if (is_array($value)) { $factory = $this->getDefault($options); @@ -48,6 +47,6 @@ class ConnectionFactoryOption implements OptionInterface */ public function getDefault(OptionsInterface $options) { - return new ConnectionFactory(); + return new Connection\Factory(); } } diff --git a/lib/Predis/Connection/ConnectionFactory.php b/lib/Predis/Connection/Factory.php similarity index 98% rename from lib/Predis/Connection/ConnectionFactory.php rename to lib/Predis/Connection/Factory.php index e97282d1..92309369 100644 --- a/lib/Predis/Connection/ConnectionFactory.php +++ b/lib/Predis/Connection/Factory.php @@ -20,7 +20,7 @@ use Predis\Command; * * @author Daniele Alessandri */ -class ConnectionFactory implements ConnectionFactoryInterface +class Factory implements FactoryInterface { protected $schemes = array( 'tcp' => 'Predis\Connection\StreamConnection', diff --git a/lib/Predis/Connection/ConnectionFactoryInterface.php b/lib/Predis/Connection/FactoryInterface.php similarity index 97% rename from lib/Predis/Connection/ConnectionFactoryInterface.php rename to lib/Predis/Connection/FactoryInterface.php index 30211c24..06f6de82 100644 --- a/lib/Predis/Connection/ConnectionFactoryInterface.php +++ b/lib/Predis/Connection/FactoryInterface.php @@ -16,7 +16,7 @@ namespace Predis\Connection; * * @author Daniele Alessandri */ -interface ConnectionFactoryInterface +interface FactoryInterface { /** * Defines or overrides the connection class identified by a scheme prefix. diff --git a/lib/Predis/Connection/RedisCluster.php b/lib/Predis/Connection/RedisCluster.php index bf8582d4..82481f3a 100644 --- a/lib/Predis/Connection/RedisCluster.php +++ b/lib/Predis/Connection/RedisCluster.php @@ -55,12 +55,12 @@ class RedisCluster implements ClusterConnectionInterface, IteratorAggregate, Cou private $connections; /** - * @param ConnectionFactoryInterface $connections Connection factory object. + * @param FactoryInterface $connections Connection factory object. */ - public function __construct(ConnectionFactoryInterface $connections = null) + public function __construct(FactoryInterface $connections = null) { $this->strategy = new Cluster\RedisStrategy(); - $this->connections = $connections ?: new ConnectionFactory(); + $this->connections = $connections ?: new Factory(); } /** diff --git a/tests/Predis/ClientTest.php b/tests/Predis/ClientTest.php index 88e2a4fa..9eb070e5 100644 --- a/tests/Predis/ClientTest.php +++ b/tests/Predis/ClientTest.php @@ -12,9 +12,7 @@ namespace Predis; use PredisTestCase; -use Predis\Connection\ConnectionFactory; -use Predis\Connection\MasterSlaveReplication; -use Predis\Connection\PredisCluster; +use Predis\Connection; use Predis\Profile; use Predis\Response; @@ -152,7 +150,7 @@ class ClientTest extends PredisTestCase */ public function testConstructorWithConnectionArgument() { - $factory = new ConnectionFactory(); + $factory = new Connection\Factory(); $connection = $factory->create('tcp://localhost:7000'); $client = new Client($connection); @@ -170,9 +168,9 @@ class ClientTest extends PredisTestCase */ public function testConstructorWithClusterArgument() { - $cluster = new PredisCluster(); + $cluster = new Connection\PredisCluster(); - $factory = new ConnectionFactory(); + $factory = new Connection\Factory(); $factory->aggregate($cluster, array('tcp://localhost:7000', 'tcp://localhost:7001')); $client = new Client($cluster); @@ -186,9 +184,9 @@ class ClientTest extends PredisTestCase */ public function testConstructorWithReplicationArgument() { - $replication = new MasterSlaveReplication(); + $replication = new Connection\MasterSlaveReplication(); - $factory = new ConnectionFactory(); + $factory = new Connection\Factory(); $factory->aggregate($replication, array('tcp://host1?alias=master', 'tcp://host2?alias=slave')); $client = new Client($replication); @@ -238,7 +236,7 @@ class ClientTest extends PredisTestCase */ public function testConstructorWithNullAndArrayArgument() { - $factory = $this->getMock('Predis\Connection\ConnectionFactoryInterface'); + $factory = $this->getMock('Predis\Connection\FactoryInterface'); $arg2 = array('profile' => '2.0', 'prefix' => 'prefix:', 'connections' => $factory); $client = new Client(null, $arg2); diff --git a/tests/Predis/Configuration/ConnectionFactoryOptionTest.php b/tests/Predis/Configuration/ConnectionFactoryOptionTest.php index e4b2200e..92e73c61 100644 --- a/tests/Predis/Configuration/ConnectionFactoryOptionTest.php +++ b/tests/Predis/Configuration/ConnectionFactoryOptionTest.php @@ -14,7 +14,6 @@ namespace Predis\Configuration; use InvalidArgumentException; use stdClass; use PredisTestCase; -use Predis\Connection\ConnectionFactory; /** * @@ -29,7 +28,7 @@ class ConnectionFactoryOptionTest extends PredisTestCase $option = new ConnectionFactoryOption(); $options = $this->getMock('Predis\Configuration\OptionsInterface'); - $this->assertInstanceOf('Predis\Connection\ConnectionFactory', $option->getDefault($options)); + $this->assertInstanceOf('Predis\Connection\Factory', $option->getDefault($options)); } /** @@ -43,7 +42,7 @@ class ConnectionFactoryOptionTest extends PredisTestCase $class = get_class($this->getMock('Predis\Connection\SingleConnectionInterface')); $value = array('tcp' => $class, 'redis' => $class); - $default = $this->getMock('Predis\Connection\ConnectionFactoryInterface'); + $default = $this->getMock('Predis\Connection\FactoryInterface'); $default->expects($this->exactly(2)) ->method('define') ->with($this->matchesRegularExpression('/^tcp|redis$/'), $class); @@ -54,7 +53,7 @@ class ConnectionFactoryOptionTest extends PredisTestCase ->with($options) ->will($this->returnValue($default)); - $this->assertInstanceOf('Predis\Connection\ConnectionFactoryInterface', $factory = $option->filter($options, $value)); + $this->assertInstanceOf('Predis\Connection\FactoryInterface', $factory = $option->filter($options, $value)); $this->assertSame($default, $factory); } @@ -65,7 +64,7 @@ class ConnectionFactoryOptionTest extends PredisTestCase { $option = new ConnectionFactoryOption(); $options = $this->getMock('Predis\Configuration\OptionsInterface'); - $value = $this->getMock('Predis\Connection\ConnectionFactoryInterface'); + $value = $this->getMock('Predis\Connection\FactoryInterface'); $option = $this->getMock('Predis\Configuration\ConnectionFactoryOption', array('getDefault')); $option->expects($this->never())->method('getDefault'); diff --git a/tests/Predis/Configuration/OptionsTest.php b/tests/Predis/Configuration/OptionsTest.php index 34751c35..4e12d93c 100644 --- a/tests/Predis/Configuration/OptionsTest.php +++ b/tests/Predis/Configuration/OptionsTest.php @@ -27,7 +27,7 @@ class OptionsTest extends PredisTestCase { $options = new Options(); - $this->assertInstanceOf('Predis\Connection\ConnectionFactoryInterface', $options->connections); + $this->assertInstanceOf('Predis\Connection\FactoryInterface', $options->connections); $this->assertInstanceOf('Predis\Profile\ProfileInterface', $options->profile); $this->assertInstanceOf('Predis\Connection\ClusterConnectionInterface', $options->cluster); $this->assertInstanceOf('Predis\Connection\ReplicationConnectionInterface', $options->replication); @@ -44,7 +44,7 @@ class OptionsTest extends PredisTestCase 'exceptions' => false, 'profile' => '2.0', 'prefix' => 'prefix:', - 'connections' => $this->getMock('Predis\Connection\ConnectionFactoryInterface'), + 'connections' => $this->getMock('Predis\Connection\FactoryInterface'), 'cluster' => $this->getMock('Predis\Connection\ClusterConnectionInterface'), 'replication' => $this->getMock('Predis\Connection\ReplicationConnectionInterface'), )); @@ -52,7 +52,7 @@ class OptionsTest extends PredisTestCase $this->assertInternalType('bool', $options->exceptions); $this->assertInstanceOf('Predis\Profile\ProfileInterface', $options->profile); $this->assertInstanceOf('Predis\Command\Processor\CommandProcessorInterface', $options->prefix); - $this->assertInstanceOf('Predis\Connection\ConnectionFactoryInterface', $options->connections); + $this->assertInstanceOf('Predis\Connection\FactoryInterface', $options->connections); $this->assertInstanceOf('Predis\Connection\ClusterConnectionInterface', $options->cluster); $this->assertInstanceOf('Predis\Connection\ReplicationConnectionInterface', $options->replication); } diff --git a/tests/Predis/Connection/ConnectionFactoryTest.php b/tests/Predis/Connection/FactoryTest.php similarity index 90% rename from tests/Predis/Connection/ConnectionFactoryTest.php rename to tests/Predis/Connection/FactoryTest.php index fa748abb..957afdcf 100644 --- a/tests/Predis/Connection/ConnectionFactoryTest.php +++ b/tests/Predis/Connection/FactoryTest.php @@ -16,16 +16,16 @@ use PredisTestCase; /** * */ -class ConnectionFactoryTest extends PredisTestCase +class FactoryTest extends PredisTestCase { /** * @group disconnected */ public function testImplementsCorrectInterface() { - $factory = new ConnectionFactory(); + $factory = new Factory(); - $this->assertInstanceOf('Predis\Connection\ConnectionFactoryInterface', $factory); + $this->assertInstanceOf('Predis\Connection\FactoryInterface', $factory); } /** @@ -33,7 +33,7 @@ class ConnectionFactoryTest extends PredisTestCase */ public function testCreateConnection() { - $factory = new ConnectionFactory(); + $factory = new Factory(); $tcp = new ConnectionParameters(array( 'scheme' => 'tcp', @@ -65,7 +65,7 @@ class ConnectionFactoryTest extends PredisTestCase */ public function testCreateConnectionWithNullParameters() { - $factory = new ConnectionFactory(); + $factory = new Factory(); $connection = $factory->create(null); $parameters = $connection->getParameters(); @@ -81,7 +81,7 @@ class ConnectionFactoryTest extends PredisTestCase */ public function testCreateConnectionWithArrayParameters() { - $factory = new ConnectionFactory(); + $factory = new Factory(); $connection = $factory->create(array('scheme' => 'tcp', 'custom' => 'foobar')); $parameters = $connection->getParameters(); @@ -97,7 +97,7 @@ class ConnectionFactoryTest extends PredisTestCase */ public function testCreateConnectionWithStringURI() { - $factory = new ConnectionFactory(); + $factory = new Factory(); $connection = $factory->create('tcp://127.0.0.1?custom=foobar'); $parameters = $connection->getParameters(); @@ -116,7 +116,7 @@ class ConnectionFactoryTest extends PredisTestCase $profile = $this->getMock('Predis\Profile\ProfileInterface'); $profile->expects($this->never())->method('create'); - $factory = new ConnectionFactory($profile); + $factory = new Factory($profile); $parameters = new ConnectionParameters(); $connection = $factory->create($parameters); @@ -145,7 +145,7 @@ class ConnectionFactoryTest extends PredisTestCase ->method('pushInitCommand') ->with($this->isRedisCommand('SELECT', array(0))); - $factory = new ConnectionFactory(); + $factory = new Factory(); $reflection = new \ReflectionObject($factory); $prepareConnection = $reflection->getMethod('prepareConnection'); @@ -161,7 +161,7 @@ class ConnectionFactoryTest extends PredisTestCase $scheme = 'unknown'; $this->setExpectedException('InvalidArgumentException', "Unknown connection scheme: $scheme"); - $factory = new ConnectionFactory(); + $factory = new Factory(); $factory->create(new ConnectionParameters(array('scheme' => $scheme))); } @@ -173,7 +173,7 @@ class ConnectionFactoryTest extends PredisTestCase list(, $connectionClass) = $this->getMockConnectionClass(); $parameters = new ConnectionParameters(array('scheme' => 'foobar')); - $factory = new ConnectionFactory(); + $factory = new Factory(); $factory->define($parameters->scheme, $connectionClass); $connection = $factory->create($parameters); @@ -200,7 +200,7 @@ class ConnectionFactoryTest extends PredisTestCase ->with($parameters) ->will($this->returnCallback($initializer)); - $factory = new ConnectionFactory(); + $factory = new Factory(); $factory->define($parameters->scheme, $initializerMock); $connection1 = $factory->create($parameters); $connection2 = $factory->create($parameters); @@ -217,7 +217,7 @@ class ConnectionFactoryTest extends PredisTestCase { $this->setExpectedException('InvalidArgumentException'); - $factory = new ConnectionFactory(); + $factory = new Factory(); $factory->define('foobar', new \stdClass()); } @@ -228,7 +228,7 @@ class ConnectionFactoryTest extends PredisTestCase { $this->setExpectedException('InvalidArgumentException', 'Unknown connection scheme: tcp'); - $factory = new ConnectionFactory(); + $factory = new Factory(); $factory->undefine('tcp'); $factory->create('tcp://127.0.0.1'); } @@ -238,7 +238,7 @@ class ConnectionFactoryTest extends PredisTestCase */ public function testUndefineUndefinedConnection() { - $factory = new ConnectionFactory(); + $factory = new Factory(); $factory->undefine('unknown'); $connection = $factory->create('tcp://127.0.0.1'); @@ -252,7 +252,7 @@ class ConnectionFactoryTest extends PredisTestCase { list(, $connectionClass) = $this->getMockConnectionClass(); - $factory = new ConnectionFactory(); + $factory = new Factory(); $factory->define('redis', $connectionClass); $this->assertInstanceOf($connectionClass, $factory->create('redis://127.0.0.1')); @@ -274,7 +274,7 @@ class ConnectionFactoryTest extends PredisTestCase ->method('add') ->with($this->isInstanceOf('Predis\Connection\SingleConnectionInterface')); - $factory = $this->getMock('Predis\Connection\ConnectionFactory', array('create')); + $factory = $this->getMock('Predis\Connection\Factory', array('create')); $factory->expects($this->never()) ->method('create'); @@ -293,7 +293,7 @@ class ConnectionFactoryTest extends PredisTestCase ->method('add') ->with($this->isInstanceOf('Predis\Connection\SingleConnectionInterface')); - $factory = $this->getMock('Predis\Connection\ConnectionFactory', array('create')); + $factory = $this->getMock('Predis\Connection\Factory', array('create')); $factory->expects($this->exactly(3)) ->method('create') ->will($this->returnCallback(function ($_) use ($connectionClass) { @@ -311,7 +311,7 @@ class ConnectionFactoryTest extends PredisTestCase $cluster = $this->getMock('Predis\Connection\ClusterConnectionInterface'); $cluster->expects($this->never())->method('add'); - $factory = $this->getMock('Predis\Connection\ConnectionFactory', array('create')); + $factory = $this->getMock('Predis\Connection\Factory', array('create')); $factory->expects($this->never())->method('create'); $factory->aggregate($cluster, array()); diff --git a/tests/Predis/Connection/RedisClusterTest.php b/tests/Predis/Connection/RedisClusterTest.php index 3d2115de..c6892e72 100644 --- a/tests/Predis/Connection/RedisClusterTest.php +++ b/tests/Predis/Connection/RedisClusterTest.php @@ -472,7 +472,7 @@ class RedisClusterTest extends PredisTestCase ->with($command) ->will($this->returnValue('foobar')); - $factory = $this->getMock('Predis\Connection\ConnectionFactory'); + $factory = $this->getMock('Predis\Connection\Factory'); $factory->expects($this->never())->method('create'); $cluster = new RedisCluster($factory); @@ -512,7 +512,7 @@ class RedisClusterTest extends PredisTestCase ->with($command) ->will($this->returnValue('foobar')); - $factory = $this->getMock('Predis\Connection\ConnectionFactory'); + $factory = $this->getMock('Predis\Connection\Factory'); $factory->expects($this->once()) ->method('create') ->with(array('host' => '127.0.0.1', 'port' => '6381')) @@ -549,7 +549,7 @@ class RedisClusterTest extends PredisTestCase ->will($this->onConsecutiveCalls('foobar', 'foobar')); - $factory = $this->getMock('Predis\Connection\ConnectionFactory'); + $factory = $this->getMock('Predis\Connection\Factory'); $factory->expects($this->never())->method('create'); $cluster = new RedisCluster($factory); @@ -586,7 +586,7 @@ class RedisClusterTest extends PredisTestCase ->with($command) ->will($this->onConsecutiveCalls('foobar', 'foobar')); - $factory = $this->getMock('Predis\Connection\ConnectionFactory'); + $factory = $this->getMock('Predis\Connection\Factory'); $factory->expects($this->once()) ->method('create') ->with(array('host' => '127.0.0.1', 'port' => '6381'))