diff --git a/CHANGELOG.md b/CHANGELOG.md index f8c1961a..b9c9341b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,8 +19,10 @@ v1.1.0 (2015-xx-xx) considered obsolete and will not be supported from the next major release. - Added support for default connection parameters in `Predis\Connection\Factory` - augmenting the user-supplied parameters used to create new connections. - but they do not override specific parameters when already defined. + augmenting the user-supplied parameters used to create new connections. These + parameters do not override specific parameters when already defined. They can + also be passed via client options when configuring the client using the newly + added `parameters` option. - Removed the default value for `timeout` from `Predis\Connection\Parameters`. The fallback to a default value is a responsibility of connection classes, but diff --git a/src/Configuration/ConnectionFactoryOption.php b/src/Configuration/ConnectionFactoryOption.php index ba38df96..bf8479c9 100644 --- a/src/Configuration/ConnectionFactoryOption.php +++ b/src/Configuration/ConnectionFactoryOption.php @@ -49,6 +49,12 @@ class ConnectionFactoryOption implements OptionInterface */ public function getDefault(OptionsInterface $options) { - return new Factory(); + $factory = new Factory(); + + if ($options->defined('parameters')) { + $factory->setDefaultParameters($options->parameters); + } + + return $factory; } } diff --git a/tests/Predis/Configuration/ConnectionFactoryOptionTest.php b/tests/Predis/Configuration/ConnectionFactoryOptionTest.php index 437b279a..d4863a4b 100644 --- a/tests/Predis/Configuration/ConnectionFactoryOptionTest.php +++ b/tests/Predis/Configuration/ConnectionFactoryOptionTest.php @@ -54,6 +54,32 @@ class ConnectionFactoryOptionTest extends PredisTestCase $this->assertSame($default, $factory); } + /** + * @group disconnected + */ + public function testUsesParametersOptionToSetDefaultParameters() + { + $parameters = array('database' => 5, 'password' => 'mypassword'); + + $default = $this->getMock('Predis\Connection\Factory'); + $options = $this->getMock('Predis\Configuration\OptionsInterface'); + + $options->expects($this->once()) + ->method('defined') + ->with('parameters') + ->will($this->returnValue(true)); + + $options->expects($this->once()) + ->method('__get') + ->with('parameters') + ->will($this->returnValue($parameters)); + + $option = new ConnectionFactoryOption(); + $factory = $option->getDefault($options); + + $this->assertSame($parameters, $factory->getDefaultParameters()); + } + /** * @group disconnected */