Browse Source

Do not accept string or Predis\Profile\ServerProfileInstance in constructor.

To specify a server profile you can just set the "prefix" option in the
client options array passed to the constructor of Predis\Client.
Daniele Alessandri 12 years ago
parent
commit
469f3cc68b

+ 5 - 0
CHANGELOG.md

@@ -21,6 +21,11 @@ v0.8.0 (201x-xx-xx)
   Redis are not generated by connection classes anymore, but are thrown by the
   Redis are not generated by connection classes anymore, but are thrown by the
   client class and other abstractions such as pipeline contexts.
   client class and other abstractions such as pipeline contexts.
 
 
+- The second argument of `Predis\Client` constructor do not accept strings or
+  instances of `Predis\Profile\ServerProfileInterface` anymore. To specify a
+  server profile you must explicitly set `profile` in the array of client
+  options.
+
 - `Predis\Command\ScriptedCommand` internally relies on `EVALSHA` instead of
 - `Predis\Command\ScriptedCommand` internally relies on `EVALSHA` instead of
   `EVAL` thus avoiding to send Lua scripts bodies on each request. The client
   `EVAL` thus avoiding to send Lua scripts bodies on each request. The client
   automatically resends the command falling back to `EVAL` when Redis returns a
   automatically resends the command falling back to `EVAL` when Redis returns a

+ 0 - 3
lib/Predis/Client.php

@@ -72,9 +72,6 @@ class Client implements ClientInterface
         if ($options instanceof ClientOptionsInterface) {
         if ($options instanceof ClientOptionsInterface) {
             return $options;
             return $options;
         }
         }
-        if ($options instanceof ServerProfileInterface || is_string($options)) {
-            return new ClientOptions(array('profile' => $options));
-        }
 
 
         throw new \InvalidArgumentException("Invalid type for client options");
         throw new \InvalidArgumentException("Invalid type for client options");
     }
     }

+ 3 - 22
tests/Predis/ClientTest.php

@@ -196,26 +196,6 @@ class ClientTest extends StandardTestCase
         $this->assertSame($replication, $client->getConnection());
         $this->assertSame($replication, $client->getConnection());
     }
     }
 
 
-    /**
-     * @group disconnected
-     */
-    public function testConstructorWithNullAndStringArgument()
-    {
-        $client = new Client(null, '2.0');
-
-        $this->assertSame($client->getProfile()->getVersion(), ServerProfile::get('2.0')->getVersion());
-    }
-
-    /**
-     * @group disconnected
-     */
-    public function testConstructorWithNullAndProfileArgument()
-    {
-        $client = new Client(null, $arg2 = ServerProfile::get('2.0'));
-
-        $this->assertSame($client->getProfile(), $arg2);
-    }
-
     /**
     /**
      * @group disconnected
      * @group disconnected
      */
      */
@@ -299,7 +279,7 @@ class ClientTest extends StandardTestCase
                 ->with('ping', array())
                 ->with('ping', array())
                 ->will($this->returnValue($ping));
                 ->will($this->returnValue($ping));
 
 
-        $client = new Client(null, $profile);
+        $client = new Client(null, array('profile' => $profile));
         $this->assertSame($ping, $client->createCommand('ping', array()));
         $this->assertSame($ping, $client->createCommand('ping', array()));
     }
     }
 
 
@@ -378,7 +358,8 @@ class ClientTest extends StandardTestCase
                 ->with('ping', array())
                 ->with('ping', array())
                 ->will($this->returnValue($ping));
                 ->will($this->returnValue($ping));
 
 
-        $client = $this->getMock('Predis\Client', array('createCommand'), array($connection, $profile));
+        $options = array('profile' => $profile);
+        $client = $this->getMock('Predis\Client', array('createCommand'), array($connection, $options));
 
 
         $this->assertTrue($client->ping());
         $this->assertTrue($client->ping());
     }
     }

+ 5 - 1
tests/Predis/Iterator/MultiBulkResponseSimpleTest.php

@@ -112,7 +112,11 @@ class MultiBulkResponseSimpleTest extends StandardTestCase
             'read_write_timeout' => 2,
             'read_write_timeout' => 2,
         );
         );
 
 
-        $client = new Client($parameters, REDIS_SERVER_VERSION);
+        $options = array(
+            'profile' => REDIS_SERVER_VERSION,
+        );
+
+        $client = new Client($parameters, $options);
         $client->connect();
         $client->connect();
         $client->select(REDIS_SERVER_DBNUM);
         $client->select(REDIS_SERVER_DBNUM);
         $client->flushdb();
         $client->flushdb();

+ 5 - 1
tests/Predis/Iterator/MultiBulkResponseTupleTest.php

@@ -83,7 +83,11 @@ class MultiBulkResponseTupleTest extends StandardTestCase
             'read_write_timeout' => 2,
             'read_write_timeout' => 2,
         );
         );
 
 
-        $client = new Client($parameters, REDIS_SERVER_VERSION);
+        $options = array(
+            'profile' => REDIS_SERVER_VERSION,
+        );
+
+        $client = new Client($parameters, $options);
         $client->connect();
         $client->connect();
         $client->select(REDIS_SERVER_DBNUM);
         $client->select(REDIS_SERVER_DBNUM);
         $client->flushdb();
         $client->flushdb();

+ 3 - 2
tests/Predis/Monitor/MonitorContextTest.php

@@ -166,12 +166,13 @@ class MonitorContextTest extends StandardTestCase
             'read_write_timeout' => 2,
             'read_write_timeout' => 2,
         );
         );
 
 
+        $options = array('profile' => REDIS_SERVER_VERSION);
         $echoed = array();
         $echoed = array();
 
 
-        $producer = new Client($parameters, REDIS_SERVER_VERSION);
+        $producer = new Client($parameters, $options);
         $producer->connect();
         $producer->connect();
 
 
-        $consumer = new Client($parameters, REDIS_SERVER_VERSION);
+        $consumer = new Client($parameters, $options);
         $consumer->connect();
         $consumer->connect();
 
 
         $monitor = new MonitorContext($consumer);
         $monitor = new MonitorContext($consumer);

+ 4 - 2
tests/Predis/PubSub/DispatcherLoopTest.php

@@ -38,10 +38,12 @@ class DispatcherLoopTest extends StandardTestCase
             'read_write_timeout' => 2,
             'read_write_timeout' => 2,
         );
         );
 
 
-        $producer = new Client($parameters, REDIS_SERVER_VERSION);
+        $options = array('profile' => REDIS_SERVER_VERSION);
+
+        $producer = new Client($parameters, $options);
         $producer->connect();
         $producer->connect();
 
 
-        $consumer = new Client($parameters, REDIS_SERVER_VERSION);
+        $consumer = new Client($parameters, $options);
         $consumer->connect();
         $consumer->connect();
 
 
         $dispatcher = new DispatcherLoop($consumer);
         $dispatcher = new DispatcherLoop($consumer);

+ 3 - 2
tests/Predis/PubSub/PubSubContextTest.php

@@ -262,12 +262,13 @@ class PubSubContextTest extends StandardTestCase
             'read_write_timeout' => 2,
             'read_write_timeout' => 2,
         );
         );
 
 
+        $options = array('profile' => REDIS_SERVER_VERSION);
         $messages = array();
         $messages = array();
 
 
-        $producer = new Client($parameters, REDIS_SERVER_VERSION);
+        $producer = new Client($parameters, $options);
         $producer->connect();
         $producer->connect();
 
 
-        $consumer = new Client($parameters, REDIS_SERVER_VERSION);
+        $consumer = new Client($parameters, $options);
         $consumer->connect();
         $consumer->connect();
 
 
         $pubsub = new PubSubContext($consumer);
         $pubsub = new PubSubContext($consumer);

+ 2 - 2
tests/Predis/Transaction/MultiExecContextTest.php

@@ -31,7 +31,7 @@ class MultiExecContextTest extends StandardTestCase
     public function testThrowsExceptionOnUnsupportedMultiExecInProfile()
     public function testThrowsExceptionOnUnsupportedMultiExecInProfile()
     {
     {
         $connection = $this->getMock('Predis\Connection\SingleConnectionInterface');
         $connection = $this->getMock('Predis\Connection\SingleConnectionInterface');
-        $client = new Client($connection, '1.2');
+        $client = new Client($connection, array('profile' => '1.2'));
         $tx = new MultiExecContext($client);
         $tx = new MultiExecContext($client);
     }
     }
 
 
@@ -43,7 +43,7 @@ class MultiExecContextTest extends StandardTestCase
     public function testThrowsExceptionOnUnsupportedWatchUnwatchInProfile()
     public function testThrowsExceptionOnUnsupportedWatchUnwatchInProfile()
     {
     {
         $connection = $this->getMock('Predis\Connection\SingleConnectionInterface');
         $connection = $this->getMock('Predis\Connection\SingleConnectionInterface');
-        $client = new Client($connection, '2.0');
+        $client = new Client($connection, array('profile' => '2.0'));
         $tx = new MultiExecContext($client, array('options' => 'cas'));
         $tx = new MultiExecContext($client, array('options' => 'cas'));
 
 
         $tx->watch('foo');
         $tx->watch('foo');