* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Predis\Configuration\Option; use PredisTestCase; /** * */ class ClusterTest extends PredisTestCase { /** * @group disconnected */ public function testDefaultOptionValue() { $option = new Cluster(); $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $this->assertInstanceOf('Closure', $initializer = $option->getDefault($options)); $this->assertInstanceOf('Predis\Connection\Cluster\PredisCluster', $initializer($options)); } /** * @group disconnected */ public function testAcceptsCallableAsConnectionInitializer() { $option = new Cluster(); $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $connection = $this->getMockBuilder('Predis\Connection\AggregateConnectionInterface')->getMock(); $callable = $this->getMockBuilder('stdClass') ->setMethods(array('__invoke')) ->getMock(); $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())); } /** * @group disconnected */ public function testThrowsExceptionOnInvalidReturnTypeOfConnectionInitializer() { $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage('Predis\Configuration\Option\Cluster expects a valid connection type returned by callable initializer'); $option = new Cluster(); $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $connection = $this->getMockBuilder('Predis\Connection\NodeConnectionInterface')->getMock(); $callable = $this->getMockBuilder('stdClass') ->setMethods(array('__invoke')) ->getMock(); $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()); } /** * @group disconnected */ public function testAcceptsShortNameStringPredis() { $option = new Cluster(); $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $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())); } /** * @group disconnected */ public function testAcceptsShortNameStringRedis() { $option = new Cluster(); $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $options ->expects($this->at(0)) ->method('__get') ->with('connections') ->will($this->returnValue( $this->getMockBuilder('Predis\Connection\FactoryInterface')->getMock() )); $options ->expects($this->at(1)) ->method('__get') ->with('crc16') ->will($this->returnValue( $this->getMockBuilder('Predis\Cluster\Hash\HashGeneratorInterface')->getMock() )); $this->assertInstanceOf('Closure', $initializer = $option->filter($options, 'redis')); $this->assertInstanceOf('Predis\Connection\Cluster\RedisCluster', $initializer($parameters = array())); } /** * @group disconnected */ public function testThrowsExceptionOnInvalidShortNameString() { $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage('String value for the cluster option must be either `predis` or `redis`'); $option = new Cluster(); $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $option->filter($options, 'unknown'); } /** * @group disconnected */ public function testThrowsExceptionOnInstanceOfClusterInterface() { $this->expectException('InvalidArgumentException'); $this->expectExceptionMessage('Predis\Configuration\Option\Cluster expects a valid callable'); $option = new Cluster(); $options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock(); $connection = $this->getMockBuilder('Predis\Connection\Cluster\ClusterInterface')->getMock(); $option->filter($options, $connection); } }