mirror of
https://github.com/predis/predis.git
synced 2026-09-12 03:17:22 +00:00
Add "default" as accepted string for "connections".
Using "default" returns a connection factory instance with the default
configuration. Basically it is no different than omitting "connections"
in the client options array but it can be useful when applications want
to automatically configure Predis to use phpiredis when it is loaded:
$client = new Predis\Client('tcp://127.0.0.1', [
'connections' =>
extension_loaded('phpiredis')
? 'phpiredis'
: 'default'
]);
This is in response to ISSUE #397.
This commit is contained in:
@@ -112,6 +112,9 @@ class Connections implements OptionInterface
|
||||
$factory->define('unix', 'Predis\Connection\PhpiredisSocketConnection');
|
||||
break;
|
||||
|
||||
case 'default':
|
||||
return $factory;
|
||||
|
||||
default:
|
||||
throw new \InvalidArgumentException(sprintf(
|
||||
'%s does not recognize `%s` as a supported configuration string', static::class, $value
|
||||
|
||||
@@ -88,6 +88,33 @@ class ConnectionsTest extends PredisTestCase
|
||||
$this->assertSame($default, $factory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testAcceptsStringDefaultToReturnConnectionFactoryWithDefaultConfiguration()
|
||||
{
|
||||
$options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock();
|
||||
|
||||
$default = $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock();
|
||||
$default
|
||||
->expects($this->never())
|
||||
->method('define');
|
||||
|
||||
$option = $this->getMockBuilder('Predis\Configuration\Option\Connections')
|
||||
->setMethods(array('getDefault'))
|
||||
->getMock();
|
||||
$option
|
||||
->expects($this->once())
|
||||
->method('getDefault')
|
||||
->with($options)
|
||||
->will($this->returnValue($default));
|
||||
|
||||
$factory = $option->filter($options, 'default');
|
||||
|
||||
$this->assertInstanceOf('Predis\Connection\FactoryInterface', $factory);
|
||||
$this->assertSame($default, $factory);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user