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 13 năm trước cách đây
mục cha
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
   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
   `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

+ 0 - 3
lib/Predis/Client.php

@@ -72,9 +72,6 @@ class Client implements ClientInterface
         if ($options instanceof ClientOptionsInterface) {
             return $options;
         }
-        if ($options instanceof ServerProfileInterface || is_string($options)) {
-            return new ClientOptions(array('profile' => $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());
     }
 
-    /**
-     * @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
      */
@@ -299,7 +279,7 @@ class ClientTest extends StandardTestCase
                 ->with('ping', array())
                 ->will($this->returnValue($ping));
 
-        $client = new Client(null, $profile);
+        $client = new Client(null, array('profile' => $profile));
         $this->assertSame($ping, $client->createCommand('ping', array()));
     }
 
@@ -378,7 +358,8 @@ class ClientTest extends StandardTestCase
                 ->with('ping', array())
                 ->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());
     }

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

@@ -112,7 +112,11 @@ class MultiBulkResponseSimpleTest extends StandardTestCase
             '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->select(REDIS_SERVER_DBNUM);
         $client->flushdb();

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

@@ -83,7 +83,11 @@ class MultiBulkResponseTupleTest extends StandardTestCase
             '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->select(REDIS_SERVER_DBNUM);
         $client->flushdb();

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

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

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

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

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

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

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

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