Browse Source

Rename Predis\Connection\SingleConnectionInterface::pushInitCommand().

The new name is more explicit as it makes obvious that the commands
added with it will be executed upon connect().
Daniele Alessandri 11 năm trước cách đây
mục cha
commit
6ceebbfbec

+ 4 - 4
lib/Predis/Connection/AbstractConnection.php

@@ -30,7 +30,7 @@ abstract class AbstractConnection implements SingleConnectionInterface
     private $cachedId;
 
     protected $parameters;
-    protected $initCmds = array();
+    protected $initCommands = array();
 
     /**
      * @param ParametersInterface $parameters Initialization parameters for the connection.
@@ -107,9 +107,9 @@ abstract class AbstractConnection implements SingleConnectionInterface
     /**
      * {@inheritdoc}
      */
-    public function pushInitCommand(CommandInterface $command)
+    public function addConnectCommand(CommandInterface $command)
     {
-        $this->initCmds[] = $command;
+        $this->initCommands[] = $command;
     }
 
     /**
@@ -211,6 +211,6 @@ abstract class AbstractConnection implements SingleConnectionInterface
      */
     public function __sleep()
     {
-        return array('parameters', 'initCmds');
+        return array('parameters', 'initCommands');
     }
 }

+ 6 - 4
lib/Predis/Connection/Factory.php

@@ -123,13 +123,15 @@ class Factory implements FactoryInterface
         $parameters = $connection->getParameters();
 
         if (isset($parameters->password)) {
-            $command = new Command\RawCommand(array('AUTH', $parameters->password));
-            $connection->pushInitCommand($command);
+            $connection->addConnectCommand(
+                new Command\RawCommand(array('AUTH', $parameters->password))
+            );
         }
 
         if (isset($parameters->database)) {
-            $command = new Command\RawCommand(array('SELECT', $parameters->database));
-            $connection->pushInitCommand($command);
+            $connection->addConnectCommand(
+                new Command\RawCommand(array('SELECT', $parameters->database))
+            );
         }
     }
 }

+ 2 - 2
lib/Predis/Connection/PhpiredisSocketConnection.php

@@ -299,8 +299,8 @@ class PhpiredisSocketConnection extends AbstractConnection
 
         $this->connectWithTimeout($this->parameters);
 
-        if ($this->initCmds) {
-            foreach ($this->initCmds as $command) {
+        if ($this->initCommands) {
+            foreach ($this->initCommands as $command) {
                 $this->executeCommand($command);
             }
         }

+ 1 - 1
lib/Predis/Connection/SingleConnectionInterface.php

@@ -47,7 +47,7 @@ interface SingleConnectionInterface extends ConnectionInterface
      *
      * @param CommandInterface $command Instance of a Redis command.
      */
-    public function pushInitCommand(CommandInterface $command);
+    public function addConnectCommand(CommandInterface $command);
 
     /**
      * Reads a response from the server.

+ 2 - 2
lib/Predis/Connection/StreamConnection.php

@@ -130,8 +130,8 @@ class StreamConnection extends AbstractConnection
     {
         parent::connect();
 
-        if ($this->initCmds) {
-            foreach ($this->initCmds as $command) {
+        if ($this->initCommands) {
+            foreach ($this->initCommands as $command) {
                 $this->executeCommand($command);
             }
         }

+ 1 - 1
lib/Predis/Connection/WebdisConnection.php

@@ -296,7 +296,7 @@ class WebdisConnection implements SingleConnectionInterface
     /**
      * {@inheritdoc}
      */
-    public function pushInitCommand(CommandInterface $command)
+    public function addConnectCommand(CommandInterface $command)
     {
         $this->throwNotSupportedException(__FUNCTION__);
     }

+ 2 - 2
tests/PHPUnit/PredisConnectionTestCase.php

@@ -198,8 +198,8 @@ abstract class PredisConnectionTestCase extends PredisTestCase
                 ->method('getArguments')
                 ->will($this->returnValue(array('ECHOED')));
 
-        $connection->pushInitCommand($cmdPing);
-        $connection->pushInitCommand($cmdEcho);
+        $connection->addConnectCommand($cmdPing);
+        $connection->addConnectCommand($cmdEcho);
 
         $connection->connect();
     }

+ 7 - 2
tests/Predis/Connection/ComposableStreamConnectionTest.php

@@ -111,8 +111,13 @@ class ComposableStreamConnectionTest extends PredisConnectionTestCase
         $connection = new ComposableStreamConnection($parameters);
 
         if ($initialize) {
-            $connection->pushInitCommand($profile->createCommand('select', array($parameters->database)));
-            $connection->pushInitCommand($profile->createCommand('flushdb'));
+            $connection->addConnectCommand(
+                $profile->createCommand('select', array($parameters->database))
+            );
+
+            $connection->addConnectCommand(
+                $profile->createCommand('flushdb')
+            );
         }
 
         return $connection;

+ 2 - 2
tests/Predis/Connection/FactoryTest.php

@@ -139,10 +139,10 @@ class FactoryTest extends PredisTestCase
                    ->method('getParameters')
                    ->will($this->returnValue($parameters));
         $connection->expects($this->at(1))
-                   ->method('pushInitCommand')
+                   ->method('addConnectCommand')
                    ->with($this->isRedisCommand('AUTH', array('foobar')));
         $connection->expects($this->at(2))
-                   ->method('pushInitCommand')
+                   ->method('addConnectCommand')
                    ->with($this->isRedisCommand('SELECT', array(0)));
 
         $factory = new Factory();

+ 7 - 2
tests/Predis/Connection/PhpiredisSocketConnectionTest.php

@@ -117,8 +117,13 @@ class PhpiredisSocketConnectionTest extends PredisConnectionTestCase
         $connection = new PhpiredisSocketConnection($parameters);
 
         if ($initialize) {
-            $connection->pushInitCommand($profile->createCommand('select', array($parameters->database)));
-            $connection->pushInitCommand($profile->createCommand('flushdb'));
+            $connection->addConnectCommand(
+                $profile->createCommand('select', array($parameters->database))
+            );
+
+            $connection->addConnectCommand(
+                $profile->createCommand('flushdb')
+            );
         }
 
         return $connection;

+ 7 - 2
tests/Predis/Connection/PhpiredisStreamConnectionTest.php

@@ -136,8 +136,13 @@ class PhpiredisStreamConnectionTest extends PredisConnectionTestCase
         $connection = new PhpiredisStreamConnection($parameters);
 
         if ($initialize) {
-            $connection->pushInitCommand($profile->createCommand('select', array($parameters->database)));
-            $connection->pushInitCommand($profile->createCommand('flushdb'));
+            $connection->addConnectCommand(
+                $profile->createCommand('select', array($parameters->database))
+            );
+
+            $connection->addConnectCommand(
+                $profile->createCommand('flushdb')
+            );
         }
 
         return $connection;

+ 7 - 2
tests/Predis/Connection/StreamConnectionTest.php

@@ -114,8 +114,13 @@ class StreamConnectionTest extends PredisConnectionTestCase
         $connection = new StreamConnection($parameters);
 
         if ($initialize) {
-            $connection->pushInitCommand($profile->createCommand('select', array($parameters->database)));
-            $connection->pushInitCommand($profile->createCommand('flushdb'));
+            $connection->addConnectCommand(
+                $profile->createCommand('select', array($parameters->database))
+            );
+
+            $connection->addConnectCommand(
+                $profile->createCommand('flushdb')
+            );
         }
 
         return $connection;

+ 4 - 3
tests/Predis/Connection/WebdisConnectionTest.php

@@ -68,12 +68,13 @@ class WebdisConnectionTest extends PredisTestCase
     /**
      * @group disconnected
      * @expectedException Predis\NotSupportedException
-     * @expectedExceptionMessage The method Predis\Connection\WebdisConnection::pushInitCommand() is not supported
+     * @expectedExceptionMessage The method Predis\Connection\WebdisConnection::addConnectCommand() is not supported
+     *
      */
-    public function testPushingInitCommandsIsNotSupported()
+    public function testAddingConnectCommandsIsNotSupported()
     {
         $connection = new WebdisConnection($this->getParameters());
-        $connection->pushInitCommand($this->getProfile()->createCommand('ping'));
+        $connection->addConnectCommand($this->getProfile()->createCommand('ping'));
     }
 
     /**