123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?php
- namespace Predis\Configuration\Option;
- use PredisTestCase;
- class ClusterTest extends PredisTestCase
- {
-
- public function testDefaultOptionValue()
- {
- $option = new Cluster();
- $options = $this->getMock('Predis\Configuration\OptionsInterface');
- $this->assertInstanceOf('Closure', $initializer = $option->getDefault($options));
- $this->assertInstanceOf('Predis\Connection\Cluster\PredisCluster', $initializer($options));
- }
-
- public function testAcceptsCallableAsConnectionInitializer()
- {
- $option = new Cluster();
- $options = $this->getMock('Predis\Configuration\OptionsInterface');
- $connection = $this->getMock('Predis\Connection\AggregateConnectionInterface');
- $callable = $this->getMock('stdClass', array('__invoke'));
- $callable
- ->expects($this->once())
- ->method('__invoke')
- ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
- ->will($this->returnValue($connection));
- $this->assertInstanceOf('Closure', $initializer = $option->filter($options, $callable));
- $this->assertSame($connection, $initializer($parameters = array()));
- }
-
- public function testThrowsExceptionOnInvalidReturnTypeOfConnectionInitializer()
- {
- $option = new Cluster();
- $options = $this->getMock('Predis\Configuration\OptionsInterface');
- $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
- $callable = $this->getMock('stdClass', array('__invoke'));
- $callable
- ->expects($this->once())
- ->method('__invoke')
- ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
- ->will($this->returnValue($connection));
- $this->assertInstanceOf('Closure', $initializer = $option->filter($options, $callable));
- $initializer($parameters = array());
- }
-
- public function testAcceptsShortNameStringPredis()
- {
- $option = new Cluster();
- $options = $this->getMock('Predis\Configuration\OptionsInterface');
- $options
- ->expects($this->never())
- ->method('__get')
- ->with('connections');
- $this->assertInstanceOf('Closure', $initializer = $option->filter($options, 'predis'));
- $this->assertInstanceOf('Predis\Connection\Cluster\PredisCluster', $initializer($parameters = array()));
- }
-
- public function testAcceptsShortNameStringRedis()
- {
- $option = new Cluster();
- $options = $this->getMock('Predis\Configuration\OptionsInterface');
- $options
- ->expects($this->once())
- ->method('__get')
- ->with('connections')
- ->will($this->returnValue(
- $this->getMock('Predis\Connection\FactoryInterface')
- ));
- $this->assertInstanceOf('Closure', $initializer = $option->filter($options, 'redis'));
- $this->assertInstanceOf('Predis\Connection\Cluster\RedisCluster', $initializer($parameters = array()));
- }
-
- public function testThrowsExceptionOnInvalidShortNameString()
- {
- $option = new Cluster();
- $options = $this->getMock('Predis\Configuration\OptionsInterface');
- $option->filter($options, 'unknown');
- }
-
- public function testThrowsExceptionOnInstanceOfClusterInterface()
- {
- $option = new Cluster();
- $options = $this->getMock('Predis\Configuration\OptionsInterface');
- $connection = $this->getMock('Predis\Connection\Cluster\ClusterInterface');
- $option->filter($options, $connection);
- }
- }
|