Add tests for prefixed Predis\PubSub\DispatcherLoop.

This commit is contained in:
Daniele Alessandri
2013-05-31 10:39:46 +02:00
parent 69c66e157f
commit 3dea41aa66
2 changed files with 55 additions and 0 deletions
@@ -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
View File
@@ -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 --------------------------------------------- //
// ******************************************************************** //