Pārlūkot izejas kodu

Add tests for prefixed Predis\PubSub\DispatcherLoop.

Daniele Alessandri 11 gadi atpakaļ
vecāks
revīzija
3dea41aa66

+ 42 - 0
tests/Predis/PubSub/DispatcherLoopTest.php

@@ -82,4 +82,46 @@ class DispatcherLoopTest extends StandardTestCase
 
         $this->assertTrue($consumer->ping());
     }
+
+    /**
+     * @group connected
+     */
+    public function testDispatcherLoopAgainstRedisServerWithPrefix()
+    {
+        $parameters = array(
+            'host' => REDIS_SERVER_HOST,
+            'port' => REDIS_SERVER_PORT,
+            'database' => REDIS_SERVER_DBNUM,
+            // Prevents suite from handing on broken test
+            'read_write_timeout' => 2,
+        );
+
+        $options = array('profile' => REDIS_SERVER_VERSION);
+
+        $producerNonPfx = new Client($parameters, $options);
+        $producerNonPfx->connect();
+
+        $producerPfx = new Client($parameters, $options + array('prefix' => 'foobar'));
+        $producerPfx->connect();
+
+        $consumer = new Client($parameters, $options + array('prefix' => 'foobar'));
+        $dispatcher = new DispatcherLoop($consumer);
+
+        $callback = $this->getMock('stdClass', array('__invoke'));
+        $callback->expects($this->exactly(1))
+                 ->method('__invoke')
+                 ->with($this->equalTo('arg:prefixed'))
+                 ->will($this->returnCallback(function ($arg) use ($dispatcher) {
+                     $dispatcher->stop();
+                 }));
+
+        $dispatcher->attachCallback('callback', $callback);
+
+        $producerNonPfx->publish('callback', 'arg:non-prefixed');
+        $producerPfx->publish('callback', 'arg:prefixed');
+
+        $dispatcher->run();
+
+        $this->assertTrue($consumer->ping());
+    }
 }

+ 13 - 0
tests/Predis/PubSub/PubSubContextTest.php

@@ -245,6 +245,19 @@ class PubSubContextTest extends StandardTestCase
         $this->assertFalse($pubsub->valid());
     }
 
+    /**
+     * @group disconnected
+     */
+    public function testGetUnderlyingClientInstance()
+    {
+        $connection = $this->getMock('Predis\Connection\SingleConnectionInterface');
+
+        $client = new Client($connection);
+        $pubsub = new PubSubContext($client);
+
+        $this->assertSame($client, $pubsub->getClient());
+    }
+
     // ******************************************************************** //
     // ---- INTEGRATION TESTS --------------------------------------------- //
     // ******************************************************************** //