Bladeren bron

Cannot execute with a transaction block after using fluent interface style with Predis\MultiExecBlock.

Daniele Alessandri 14 jaren geleden
bovenliggende
commit
030d9740bd
2 gewijzigde bestanden met toevoegingen van 17 en 2 verwijderingen
  1. 9 2
      lib/Predis.php
  2. 8 0
      test/PredisClientFeatures.php

+ 9 - 2
lib/Predis.php

@@ -929,8 +929,15 @@ class MultiExecBlock {
                 "Cannot invoke 'execute' or 'exec' inside an active client transaction block"
             );
         }
-        if ($block && !is_callable($block)) {
-            throw new \InvalidArgumentException('Argument passed must be a callable object');
+        if ($block) {
+            if (!is_callable($block)) {
+                throw new \InvalidArgumentException('Argument passed must be a callable object');
+            }
+            if (count($this->_commands) > 0) {
+                throw new ClientException(
+                    'Cannot execute a transaction block after using fluent interface'
+                );
+            }
         }
         if (isset($this->_options['retry']) && !isset($block)) {
             $this->discard();

+ 8 - 0
test/PredisClientFeatures.php

@@ -524,6 +524,14 @@ class PredisClientFeaturesTestSuite extends PHPUnit_Framework_TestCase {
         $this->assertEquals('bar', $replies[2]);
     }
 
+    /**
+     * @expectedException Predis\ClientException
+     */
+    function testMultiExecBlock_CannotMixFluentInterfaceAndAnonymousBlock() {
+        $emptyBlock = function($tx) { };
+        $tx = RC::getConnection()->multiExec()->get('foo')->execute($emptyBlock);
+    }
+
     function testMultiExecBlock_EmptyCallableBlock() {
         $client = RC::getConnection();
         $client->flushdb();