Parcourir la source

Minor changes in checks for transaction support in server profile.

Daniele Alessandri il y a 10 ans
Parent
commit
727072c086

+ 2 - 2
lib/Predis/Transaction/MultiExecContext.php

@@ -123,11 +123,11 @@ class MultiExecContext implements BasicClientInterface, ExecutableContextInterfa
 
         $profile = $client->getProfile();
 
-        if ($profile->supportsCommands(array('multi', 'exec', 'discard')) === false) {
+        if ($profile->supportsCommands(array('MULTI', 'EXEC', 'DISCARD')) === false) {
             throw new NotSupportedException('The current profile does not support MULTI, EXEC and DISCARD');
         }
 
-        $this->canWatch = $profile->supportsCommands(array('watch', 'unwatch'));
+        $this->canWatch = $profile->supportsCommands(array('WATCH', 'UNWATCH'));
     }
 
     /**

+ 20 - 3
tests/Predis/Transaction/MultiExecContextTest.php

@@ -30,8 +30,15 @@ class MultiExecContextTest extends PredisTestCase
      */
     public function testThrowsExceptionOnUnsupportedMultiExecInProfile()
     {
+        $profile = $this->getMock('Predis\Profile\ServerProfileInterface');
+        $profile->expects($this->once())
+                ->method('supportsCommands')
+                ->with(array('MULTI', 'EXEC', 'DISCARD'))
+                ->will($this->returnValue(false));
+
         $connection = $this->getMock('Predis\Connection\SingleConnectionInterface');
-        $client = new Client($connection, array('profile' => '1.2'));
+        $client = new Client($connection, array('profile' => $profile));
+
         $tx = new MultiExecContext($client);
     }
 
@@ -42,10 +49,20 @@ class MultiExecContextTest extends PredisTestCase
      */
     public function testThrowsExceptionOnUnsupportedWatchUnwatchInProfile()
     {
+        $profile = $this->getMock('Predis\Profile\ServerProfileInterface');
+        $profile->expects($this->at(0))
+                ->method('supportsCommands')
+                ->with(array('MULTI', 'EXEC', 'DISCARD'))
+                ->will($this->returnValue(true));
+        $profile->expects($this->at(1))
+                ->method('supportsCommands')
+                ->with(array('WATCH', 'UNWATCH'))
+                ->will($this->returnValue(false));
+
         $connection = $this->getMock('Predis\Connection\SingleConnectionInterface');
-        $client = new Client($connection, array('profile' => '2.0'));
-        $tx = new MultiExecContext($client, array('options' => 'cas'));
+        $client = new Client($connection, array('profile' => $profile));
 
+        $tx = new MultiExecContext($client, array('options' => 'cas'));
         $tx->watch('foo');
     }