123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- namespace Predis\Connection;
- class CompositeStreamConnectionTest extends PredisConnectionTestCase
- {
- const CONNECTION_CLASS = 'Predis\Connection\CompositeStreamConnection';
-
- public function testConstructorDoesNotOpenConnection()
- {
- $connection = new CompositeStreamConnection($this->getParameters());
- $this->assertFalse($connection->isConnected());
- }
-
- public function testSupportsSchemeTCP()
- {
- $parameters = $this->getParameters(array('scheme' => 'tcp'));
- $connection = new StreamConnection($parameters);
- $this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $connection);
- }
-
- public function testSupportsSchemeRedis()
- {
- $parameters = $this->getParameters(array('scheme' => 'redis'));
- $connection = new StreamConnection($parameters);
- $this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $connection);
- }
-
- public function testSupportsSchemeUnix()
- {
- $parameters = $this->getParameters(array('scheme' => 'unix'));
- $connection = new StreamConnection($parameters);
- $this->assertInstanceOf('Predis\Connection\NodeConnectionInterface', $connection);
- }
-
- public function testThrowsExceptionOnInvalidScheme()
- {
- $parameters = $this->getParameters(array('scheme' => 'udp'));
- new CompositeStreamConnection($parameters);
- }
-
- public function testExposesParameters()
- {
- $parameters = $this->getParameters();
- $connection = new CompositeStreamConnection($parameters);
- $this->assertSame($parameters, $connection->getParameters());
- }
-
- public function testCanBeSerialized()
- {
- $parameters = $this->getParameters(array('alias' => 'redis', 'read_write_timeout' => 10));
- $connection = new CompositeStreamConnection($parameters);
- $unserialized = unserialize(serialize($connection));
- $this->assertEquals($connection, $unserialized);
- }
-
-
-
-
- public function testReadsMultibulkResponsesAsIterators()
- {
- $connection = $this->getConnection($profile, true);
- $connection->getProtocol()->useIterableMultibulk(true);
- $connection->executeCommand($profile->createCommand('rpush', array('metavars', 'foo', 'hoge', 'lol')));
- $connection->writeRequest($profile->createCommand('lrange', array('metavars', 0, -1)));
- $this->assertInstanceOf('Predis\Response\Iterator\MultiBulkIterator', $iterator = $connection->read());
- $this->assertSame(array('foo', 'hoge', 'lol'), iterator_to_array($iterator));
- }
-
- public function testThrowsExceptionOnProtocolDesynchronizationErrors()
- {
- $connection = $this->getConnection($profile);
- $stream = $connection->getResource();
- $connection->writeRequest($profile->createCommand('ping'));
- fread($stream, 1);
- $connection->read();
- }
- }
|