Browse Source

Rename IOption::validate() to IOption::filter().

Daniele Alessandri 13 years ago
parent
commit
1d6d0f3555

+ 1 - 1
lib/Predis/Options/ClientCluster.php

@@ -39,7 +39,7 @@ class ClientCluster extends Option
     /**
     /**
      * {@inheritdoc}
      * {@inheritdoc}
      */
      */
-    public function validate(IClientOptions $options, $value)
+    public function filter(IClientOptions $options, $value)
     {
     {
         if (is_callable($value)) {
         if (is_callable($value)) {
             return $this->checkInstance(call_user_func($value, $options));
             return $this->checkInstance(call_user_func($value, $options));

+ 1 - 1
lib/Predis/Options/ClientConnectionFactory.php

@@ -24,7 +24,7 @@ class ClientConnectionFactory extends Option
     /**
     /**
      * {@inheritdoc}
      * {@inheritdoc}
      */
      */
-    public function validate(IClientOptions $options, $value)
+    public function filter(IClientOptions $options, $value)
     {
     {
         if ($value instanceof IConnectionFactory) {
         if ($value instanceof IConnectionFactory) {
             return $value;
             return $value;

+ 2 - 2
lib/Predis/Options/ClientOptions.php

@@ -12,7 +12,7 @@
 namespace Predis\Options;
 namespace Predis\Options;
 
 
 /**
 /**
- * Class that manages validation and conversion of client options.
+ * Class that manages client options with filtering and conversion.
  *
  *
  * @author Daniele Alessandri <suppakilla@gmail.com>
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
  */
@@ -60,7 +60,7 @@ class ClientOptions implements IClientOptions
             if (isset($handlers[$option])) {
             if (isset($handlers[$option])) {
                 $handler = $handlers[$option];
                 $handler = $handlers[$option];
                 $handlers[$option] = function($options) use($handler, $value) {
                 $handlers[$option] = function($options) use($handler, $value) {
-                    return $handler->validate($options, $value);
+                    return $handler->filter($options, $value);
                 };
                 };
             }
             }
             else {
             else {

+ 1 - 1
lib/Predis/Options/ClientPrefix.php

@@ -23,7 +23,7 @@ class ClientPrefix extends Option
     /**
     /**
      * {@inheritdoc}
      * {@inheritdoc}
      */
      */
-    public function validate(IClientOptions $options, $value)
+    public function filter(IClientOptions $options, $value)
     {
     {
         return new KeyPrefixProcessor($value);
         return new KeyPrefixProcessor($value);
     }
     }

+ 1 - 1
lib/Predis/Options/ClientProfile.php

@@ -24,7 +24,7 @@ class ClientProfile extends Option
     /**
     /**
      * {@inheritdoc}
      * {@inheritdoc}
      */
      */
-    public function validate(IClientOptions $options, $value)
+    public function filter(IClientOptions $options, $value)
     {
     {
         if (is_string($value)) {
         if (is_string($value)) {
             $value = ServerProfile::get($value);
             $value = ServerProfile::get($value);

+ 8 - 8
lib/Predis/Options/CustomOption.php

@@ -18,7 +18,7 @@ namespace Predis\Options;
  */
  */
 class CustomOption implements IOption
 class CustomOption implements IOption
 {
 {
-    private $validate;
+    private $filter;
     private $default;
     private $default;
 
 
     /**
     /**
@@ -26,8 +26,8 @@ class CustomOption implements IOption
      */
      */
     public function __construct(Array $options = array())
     public function __construct(Array $options = array())
     {
     {
-        $this->validate = $this->filterCallable($options, 'validate');
-        $this->default  = $this->filterCallable($options, 'default');
+        $this->filter = $this->ensureCallable($options, 'filter');
+        $this->default  = $this->ensureCallable($options, 'default');
     }
     }
 
 
     /**
     /**
@@ -36,7 +36,7 @@ class CustomOption implements IOption
      * @param array $options Array of options
      * @param array $options Array of options
      * @param string $key Target option.
      * @param string $key Target option.
      */
      */
-    private function filterCallable($options, $key)
+    private function ensureCallable($options, $key)
     {
     {
         if (!isset($options[$key])) {
         if (!isset($options[$key])) {
             return;
             return;
@@ -53,13 +53,13 @@ class CustomOption implements IOption
     /**
     /**
      * {@inheritdoc}
      * {@inheritdoc}
      */
      */
-    public function validate(IClientOptions $options, $value)
+    public function filter(IClientOptions $options, $value)
     {
     {
         if (isset($value)) {
         if (isset($value)) {
-            if ($this->validate === null) {
+            if ($this->filter === null) {
                 return $value;
                 return $value;
             }
             }
-            $validator = $this->validate;
+            $validator = $this->filter;
 
 
             return $validator($options, $value);
             return $validator($options, $value);
         }
         }
@@ -84,7 +84,7 @@ class CustomOption implements IOption
     public function __invoke(IClientOptions $options, $value)
     public function __invoke(IClientOptions $options, $value)
     {
     {
         if (isset($value)) {
         if (isset($value)) {
-            return $this->validate($options, $value);
+            return $this->filter($options, $value);
         }
         }
 
 
         return $this->getDefault($options);
         return $this->getDefault($options);

+ 3 - 3
lib/Predis/Options/IOption.php

@@ -19,12 +19,12 @@ namespace Predis\Options;
 interface IOption
 interface IOption
 {
 {
     /**
     /**
-     * Validates (and optionally converts) the passed value.
+     * Filters (and optionally converts) the passed value.
      *
      *
      * @param mixed $value Input value.
      * @param mixed $value Input value.
      * @return mixed
      * @return mixed
      */
      */
-    public function validate(IClientOptions $options, $value);
+    public function filter(IClientOptions $options, $value);
 
 
     /**
     /**
      * Returns a default value for the option.
      * Returns a default value for the option.
@@ -35,7 +35,7 @@ interface IOption
     public function getDefault(IClientOptions $options);
     public function getDefault(IClientOptions $options);
 
 
     /**
     /**
-     * Validates a value and, if no value is specified, returns
+     * Filters a value and, if no value is specified, returns
      * the default one defined by the option.
      * the default one defined by the option.
      *
      *
      * @param mixed $value Input value.
      * @param mixed $value Input value.

+ 2 - 2
lib/Predis/Options/Option.php

@@ -21,7 +21,7 @@ class Option implements IOption
     /**
     /**
      * {@inheritdoc}
      * {@inheritdoc}
      */
      */
-    public function validate(IClientOptions $options, $value)
+    public function filter(IClientOptions $options, $value)
     {
     {
         return $value;
         return $value;
     }
     }
@@ -40,7 +40,7 @@ class Option implements IOption
     public function __invoke(IClientOptions $options, $value)
     public function __invoke(IClientOptions $options, $value)
     {
     {
         if (isset($value)) {
         if (isset($value)) {
-            return $this->validate($options, $value);
+            return $this->filter($options, $value);
         }
         }
 
 
         return $this->getDefault($options);
         return $this->getDefault($options);

+ 7 - 7
tests/Predis/Options/ClientClusterTest.php

@@ -28,7 +28,7 @@ class ClientClusterTest extends StandardTestCase
         $options = $this->getMock('Predis\Options\IClientOptions');
         $options = $this->getMock('Predis\Options\IClientOptions');
         $option = new ClientCluster();
         $option = new ClientCluster();
 
 
-        $cluster = $option->validate($options, $clusterClass);
+        $cluster = $option->filter($options, $clusterClass);
 
 
         $this->assertInstanceOf('Predis\Network\IConnectionCluster', $cluster);
         $this->assertInstanceOf('Predis\Network\IConnectionCluster', $cluster);
     }
     }
@@ -41,7 +41,7 @@ class ClientClusterTest extends StandardTestCase
         $options = $this->getMock('Predis\Options\IClientOptions');
         $options = $this->getMock('Predis\Options\IClientOptions');
         $option = new ClientCluster();
         $option = new ClientCluster();
 
 
-        $cluster = $option->validate($options, 'predis');
+        $cluster = $option->filter($options, 'predis');
 
 
         $this->assertInstanceOf('Predis\Network\IConnectionCluster', $cluster);
         $this->assertInstanceOf('Predis\Network\IConnectionCluster', $cluster);
     }
     }
@@ -62,7 +62,7 @@ class ClientClusterTest extends StandardTestCase
         $options = $this->getMock('Predis\Options\IClientOptions');
         $options = $this->getMock('Predis\Options\IClientOptions');
         $option = new ClientCluster();
         $option = new ClientCluster();
 
 
-        $cluster = $option->validate($options, $initializer);
+        $cluster = $option->filter($options, $initializer);
 
 
         $this->assertInstanceOf('Predis\Network\IConnectionCluster', $cluster);
         $this->assertInstanceOf('Predis\Network\IConnectionCluster', $cluster);
         $this->assertSame($value, $cluster);
         $this->assertSame($value, $cluster);
@@ -79,7 +79,7 @@ class ClientClusterTest extends StandardTestCase
         $options = $this->getMock('Predis\Options\IClientOptions');
         $options = $this->getMock('Predis\Options\IClientOptions');
         $option = new ClientCluster();
         $option = new ClientCluster();
 
 
-        $option->validate($options, $connectionClass);
+        $option->filter($options, $connectionClass);
     }
     }
 
 
     /**
     /**
@@ -92,7 +92,7 @@ class ClientClusterTest extends StandardTestCase
         $options = $this->getMock('Predis\Options\IClientOptions');
         $options = $this->getMock('Predis\Options\IClientOptions');
         $option = new ClientCluster();
         $option = new ClientCluster();
 
 
-        $option->validate($options, 'unknown');
+        $option->filter($options, 'unknown');
     }
     }
 
 
     /**
     /**
@@ -107,7 +107,7 @@ class ClientClusterTest extends StandardTestCase
         $options = $this->getMock('Predis\Options\IClientOptions');
         $options = $this->getMock('Predis\Options\IClientOptions');
         $option = new ClientCluster();
         $option = new ClientCluster();
 
 
-        $option->validate($options, $value);
+        $option->filter($options, $value);
     }
     }
 
 
     /**
     /**
@@ -120,6 +120,6 @@ class ClientClusterTest extends StandardTestCase
         $options = $this->getMock('Predis\Options\IClientOptions');
         $options = $this->getMock('Predis\Options\IClientOptions');
         $option = new ClientCluster();
         $option = new ClientCluster();
 
 
-        $option->validate($options, new \stdClass());
+        $option->filter($options, new \stdClass());
     }
     }
 }
 }

+ 8 - 8
tests/Predis/Options/ClientConnectionFactoryTest.php

@@ -41,7 +41,7 @@ class ClientConnectionFactoryTest extends StandardTestCase
                ->with($options)
                ->with($options)
                ->will($this->returnValue($default));
                ->will($this->returnValue($default));
 
 
-        $factory = $option->validate($options, $value);
+        $factory = $option->filter($options, $value);
 
 
         $this->assertInstanceOf('Predis\IConnectionFactory', $factory);
         $this->assertInstanceOf('Predis\IConnectionFactory', $factory);
         $this->assertSame($default, $factory);
         $this->assertSame($default, $factory);
@@ -58,7 +58,7 @@ class ClientConnectionFactoryTest extends StandardTestCase
         $option = $this->getMock('Predis\Options\ClientConnectionFactory', array('getDefault'));
         $option = $this->getMock('Predis\Options\ClientConnectionFactory', array('getDefault'));
         $option->expects($this->never())->method('getDefault');
         $option->expects($this->never())->method('getDefault');
 
 
-        $this->assertSame($value, $option->validate($options, $value));
+        $this->assertSame($value, $option->filter($options, $value));
     }
     }
 
 
     /**
     /**
@@ -72,7 +72,7 @@ class ClientConnectionFactoryTest extends StandardTestCase
         $option = $this->getMock('Predis\Options\ClientConnectionFactory', array('getDefault'));
         $option = $this->getMock('Predis\Options\ClientConnectionFactory', array('getDefault'));
         $option->expects($this->never())->method('getDefault');
         $option->expects($this->never())->method('getDefault');
 
 
-        $this->assertInstanceOf($factory, $option->validate($options, $factory));
+        $this->assertInstanceOf($factory, $option->filter($options, $factory));
     }
     }
 
 
     /**
     /**
@@ -85,7 +85,7 @@ class ClientConnectionFactoryTest extends StandardTestCase
         $options = $this->getMock('Predis\Options\IClientOptions');
         $options = $this->getMock('Predis\Options\IClientOptions');
         $option = new ClientConnectionFactory();
         $option = new ClientConnectionFactory();
 
 
-        $option->validate($options, new \stdClass());
+        $option->filter($options, new \stdClass());
     }
     }
 
 
     /**
     /**
@@ -96,17 +96,17 @@ class ClientConnectionFactoryTest extends StandardTestCase
         $value = $this->getMock('Predis\IConnectionFactory');
         $value = $this->getMock('Predis\IConnectionFactory');
         $options = $this->getMock('Predis\Options\IClientOptions');
         $options = $this->getMock('Predis\Options\IClientOptions');
 
 
-        $option = $this->getMock('Predis\Options\ClientConnectionFactory', array('validate', 'getDefault'));
+        $option = $this->getMock('Predis\Options\ClientConnectionFactory', array('filter', 'getDefault'));
         $option->expects($this->once())
         $option->expects($this->once())
-               ->method('validate')
+               ->method('filter')
                ->with($options, $value)
                ->with($options, $value)
                ->will($this->returnValue($value));
                ->will($this->returnValue($value));
         $option->expects($this->never())->method('getDefault');
         $option->expects($this->never())->method('getDefault');
 
 
         $this->assertInstanceOf('Predis\IConnectionFactory', $option($options, $value));
         $this->assertInstanceOf('Predis\IConnectionFactory', $option($options, $value));
 
 
-        $option = $this->getMock('Predis\Options\ClientConnectionFactory', array('validate', 'getDefault'));
-        $option->expects($this->never())->method('validate');
+        $option = $this->getMock('Predis\Options\ClientConnectionFactory', array('filter', 'getDefault'));
+        $option->expects($this->never())->method('filter');
         $option->expects($this->once())
         $option->expects($this->once())
                ->method('getDefault')
                ->method('getDefault')
                ->with($options)
                ->with($options)

+ 1 - 1
tests/Predis/Options/ClientPrefixTest.php

@@ -27,7 +27,7 @@ class ClientPrefixTest extends StandardTestCase
         $options = $this->getMock('Predis\Options\IClientOptions');
         $options = $this->getMock('Predis\Options\IClientOptions');
         $option = new ClientPrefix();
         $option = new ClientPrefix();
 
 
-        $return = $option->validate($options, $value);
+        $return = $option->filter($options, $value);
 
 
         $this->assertInstanceOf('Predis\Commands\Processors\ICommandProcessor', $return);
         $this->assertInstanceOf('Predis\Commands\Processors\ICommandProcessor', $return);
         $this->assertInstanceOf('Predis\Commands\Processors\KeyPrefixProcessor', $return);
         $this->assertInstanceOf('Predis\Commands\Processors\KeyPrefixProcessor', $return);

+ 6 - 6
tests/Predis/Options/ClientProfileTest.php

@@ -29,7 +29,7 @@ class ClientProfileTest extends StandardTestCase
         $options = $this->getMock('Predis\Options\IClientOptions');
         $options = $this->getMock('Predis\Options\IClientOptions');
         $option = new ClientProfile();
         $option = new ClientProfile();
 
 
-        $profile = $option->validate($options, '2.0');
+        $profile = $option->filter($options, '2.0');
 
 
         $this->assertInstanceOf('Predis\Profiles\IServerProfile', $profile);
         $this->assertInstanceOf('Predis\Profiles\IServerProfile', $profile);
         $this->assertEquals('2.0', $profile->getVersion());
         $this->assertEquals('2.0', $profile->getVersion());
@@ -45,7 +45,7 @@ class ClientProfileTest extends StandardTestCase
         $options = $this->getMock('Predis\Options\IClientOptions');
         $options = $this->getMock('Predis\Options\IClientOptions');
         $option = new ClientProfile();
         $option = new ClientProfile();
 
 
-        $profile = $option->validate($options, $value);
+        $profile = $option->filter($options, $value);
 
 
         $this->assertInstanceOf('Predis\Profiles\IServerProfile', $profile);
         $this->assertInstanceOf('Predis\Profiles\IServerProfile', $profile);
         $this->assertEquals('2.0', $profile->getVersion());
         $this->assertEquals('2.0', $profile->getVersion());
@@ -62,7 +62,7 @@ class ClientProfileTest extends StandardTestCase
         $options = $this->getMock('Predis\Options\IClientOptions');
         $options = $this->getMock('Predis\Options\IClientOptions');
         $option = new ClientProfile();
         $option = new ClientProfile();
 
 
-        $option->validate($options, new \stdClass());
+        $option->filter($options, new \stdClass());
     }
     }
 
 
     /**
     /**
@@ -105,7 +105,7 @@ class ClientProfileTest extends StandardTestCase
      * @group disconnected
      * @group disconnected
      * @todo Can't we when trap __isset when mocking an interface? Doesn't seem to work here.
      * @todo Can't we when trap __isset when mocking an interface? Doesn't seem to work here.
      */
      */
-    public function testValidateSetsPrefixProcessorFromClientOptions()
+    public function testFilterSetsPrefixProcessorFromClientOptions()
     {
     {
         $options = $this->getMock('Predis\Options\ClientOptions', array('__isset', '__get'));
         $options = $this->getMock('Predis\Options\ClientOptions', array('__isset', '__get'));
         $options->expects($this->once())
         $options->expects($this->once())
@@ -119,7 +119,7 @@ class ClientProfileTest extends StandardTestCase
 
 
         $option = new ClientProfile();
         $option = new ClientProfile();
 
 
-        $profile = $option->validate($options, '2.0');
+        $profile = $option->filter($options, '2.0');
 
 
         $this->assertInstanceOf('Predis\Profiles\IServerProfile', $profile);
         $this->assertInstanceOf('Predis\Profiles\IServerProfile', $profile);
         $this->assertEquals('2.0', $profile->getVersion());
         $this->assertEquals('2.0', $profile->getVersion());
@@ -164,7 +164,7 @@ class ClientProfileTest extends StandardTestCase
 
 
         $option = new ClientProfile();
         $option = new ClientProfile();
 
 
-        $profile = $option->validate($options, ServerProfile::getDefault());
+        $profile = $option->filter($options, ServerProfile::getDefault());
 
 
         $this->assertInstanceOf('Predis\Profiles\IServerProfile', $profile);
         $this->assertInstanceOf('Predis\Profiles\IServerProfile', $profile);
         $this->assertNull($profile->getProcessor());
         $this->assertNull($profile->getProcessor());

+ 14 - 14
tests/Predis/Options/CustomOptionTest.php

@@ -22,9 +22,9 @@ class CustomOptionTest extends StandardTestCase
      * @group disconnected
      * @group disconnected
      * @expectedException InvalidArgumentException
      * @expectedException InvalidArgumentException
      */
      */
-    public function testConstructorAcceptsOnlyCallablesForValidate()
+    public function testConstructorAcceptsOnlyCallablesForFilter()
     {
     {
-        $option = new CustomOption(array('validate' => new \stdClass()));
+        $option = new CustomOption(array('filter' => new \stdClass()));
     }
     }
 
 
     /**
     /**
@@ -49,12 +49,12 @@ class CustomOptionTest extends StandardTestCase
     /**
     /**
      * @group disconnected
      * @group disconnected
      */
      */
-    public function testValidateWithoutCallbackReturnsValue()
+    public function testFilterWithoutCallbackReturnsValue()
     {
     {
         $options = $this->getMock('Predis\Options\IClientOptions');
         $options = $this->getMock('Predis\Options\IClientOptions');
         $option = new CustomOption();
         $option = new CustomOption();
 
 
-        $this->assertEquals('test', $option->validate($options, 'test'));
+        $this->assertEquals('test', $option->filter($options, 'test'));
     }
     }
 
 
     /**
     /**
@@ -71,22 +71,22 @@ class CustomOptionTest extends StandardTestCase
     /**
     /**
      * @group disconnected
      * @group disconnected
      */
      */
-    public function testInvokeCallsValidateCallback()
+    public function testInvokeCallsFilterCallback()
     {
     {
         $value = 'test';
         $value = 'test';
 
 
         $options = $this->getMock('Predis\Options\IClientOptions');
         $options = $this->getMock('Predis\Options\IClientOptions');
 
 
-        $validate = $this->getMock('stdClass', array('__invoke'));
-        $validate->expects($this->once())
-                 ->method('__invoke')
-                 ->with($this->isInstanceOf('Predis\Options\IClientOptions'), $value)
-                 ->will($this->returnValue(true));
+        $filter = $this->getMock('stdClass', array('__invoke'));
+        $filter->expects($this->once())
+               ->method('__invoke')
+               ->with($this->isInstanceOf('Predis\Options\IClientOptions'), $value)
+               ->will($this->returnValue(true));
 
 
         $default = $this->getMock('stdClass', array('__invoke'));
         $default = $this->getMock('stdClass', array('__invoke'));
         $default->expects($this->never())->method('__invoke');
         $default->expects($this->never())->method('__invoke');
 
 
-        $option = new CustomOption(array('validate' => $validate, 'default' => $default));
+        $option = new CustomOption(array('filter' => $filter, 'default' => $default));
 
 
         $this->assertTrue($option($options, $value));
         $this->assertTrue($option($options, $value));
     }
     }
@@ -98,8 +98,8 @@ class CustomOptionTest extends StandardTestCase
     {
     {
         $options = $this->getMock('Predis\Options\IClientOptions');
         $options = $this->getMock('Predis\Options\IClientOptions');
 
 
-        $validate = $this->getMock('stdClass', array('__invoke'));
-        $validate->expects($this->never())->method('__invoke');
+        $filter = $this->getMock('stdClass', array('__invoke'));
+        $filter->expects($this->never())->method('__invoke');
 
 
         $default = $this->getMock('stdClass', array('__invoke'));
         $default = $this->getMock('stdClass', array('__invoke'));
         $default->expects($this->once())
         $default->expects($this->once())
@@ -107,7 +107,7 @@ class CustomOptionTest extends StandardTestCase
                 ->with($this->isInstanceOf('Predis\Options\IClientOptions'))
                 ->with($this->isInstanceOf('Predis\Options\IClientOptions'))
                 ->will($this->returnValue(true));
                 ->will($this->returnValue(true));
 
 
-        $option = new CustomOption(array('validate' => $validate, 'default' => $default));
+        $option = new CustomOption(array('filter' => $filter, 'default' => $default));
 
 
         $this->assertTrue($option($options, null));
         $this->assertTrue($option($options, null));
     }
     }

+ 5 - 5
tests/Predis/Options/OptionTest.php

@@ -27,7 +27,7 @@ class OptionTest extends StandardTestCase
         $options = $this->getMock('Predis\Options\IClientOptions');
         $options = $this->getMock('Predis\Options\IClientOptions');
         $option = new Option();
         $option = new Option();
 
 
-        $this->assertSame($value, $option->validate($options, $value));
+        $this->assertSame($value, $option->filter($options, $value));
     }
     }
 
 
     /**
     /**
@@ -49,9 +49,9 @@ class OptionTest extends StandardTestCase
         $value = new \stdClass();
         $value = new \stdClass();
         $options = $this->getMock('Predis\Options\IClientOptions');
         $options = $this->getMock('Predis\Options\IClientOptions');
 
 
-        $option = $this->getMock('Predis\Options\Option', array('validate', 'getDefault'));
+        $option = $this->getMock('Predis\Options\Option', array('filter', 'getDefault'));
         $option->expects($this->once())
         $option->expects($this->once())
-               ->method('validate')
+               ->method('filter')
                ->with($options, $value)
                ->with($options, $value)
                ->will($this->returnValue($value));
                ->will($this->returnValue($value));
         $option->expects($this->never())->method('getDefault');
         $option->expects($this->never())->method('getDefault');
@@ -67,8 +67,8 @@ class OptionTest extends StandardTestCase
         $expected = new \stdClass();
         $expected = new \stdClass();
         $options = $this->getMock('Predis\Options\IClientOptions');
         $options = $this->getMock('Predis\Options\IClientOptions');
 
 
-        $option = $this->getMock('Predis\Options\Option', array('validate', 'getDefault'));
-        $option->expects($this->never())->method('validate');
+        $option = $this->getMock('Predis\Options\Option', array('filter', 'getDefault'));
+        $option->expects($this->never())->method('filter');
         $option->expects($this->once())
         $option->expects($this->once())
                ->method('getDefault')
                ->method('getDefault')
                ->with($options)
                ->with($options)