mirror of
https://github.com/predis/predis.git
synced 2026-11-29 07:32:05 +00:00
Rename Predis\Connection\ConnectionFactory.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ use Predis\Command;
|
||||
*
|
||||
* @author Daniele Alessandri <suppakilla@gmail.com>
|
||||
*/
|
||||
class ConnectionFactory implements ConnectionFactoryInterface
|
||||
class Factory implements FactoryInterface
|
||||
{
|
||||
protected $schemes = array(
|
||||
'tcp' => 'Predis\Connection\StreamConnection',
|
||||
+1
-1
@@ -16,7 +16,7 @@ namespace Predis\Connection;
|
||||
*
|
||||
* @author Daniele Alessandri <suppakilla@gmail.com>
|
||||
*/
|
||||
interface ConnectionFactoryInterface
|
||||
interface FactoryInterface
|
||||
{
|
||||
/**
|
||||
* Defines or overrides the connection class identified by a scheme prefix.
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
+19
-19
@@ -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());
|
||||
@@ -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'))
|
||||
|
||||
Reference in New Issue
Block a user