12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace Predis\Configuration;
- use InvalidArgumentException;
- use PHPUnit_Framework_TestCase as StandardTestCase;
- use stdClass;
- use Predis\Connection\ConnectionFactory;
- class ConnectionFactoryOptionTest extends StandardTestCase
- {
-
- public function testDefaultOptionValue()
- {
- $option = new ConnectionFactoryOption();
- $options = $this->getMock('Predis\Configuration\OptionsInterface');
- $this->assertInstanceOf('Predis\Connection\ConnectionFactory', $option->getDefault($options));
- }
-
- public function testAcceptsNamedArrayWithSchemeToConnectionClassMappings()
- {
- $option = new ConnectionFactoryOption();
- $options = $this->getMock('Predis\Configuration\OptionsInterface');
- $class = get_class($this->getMock('Predis\Connection\SingleConnectionInterface'));
- $value = array('tcp' => $class, 'redis' => $class);
- $default = $this->getMock('Predis\Connection\ConnectionFactoryInterface');
- $default->expects($this->exactly(2))
- ->method('define')
- ->with($this->matchesRegularExpression('/^tcp|redis$/'), $class);
- $option = $this->getMock('Predis\Configuration\ConnectionFactoryOption', array('getDefault'));
- $option->expects($this->once())
- ->method('getDefault')
- ->with($options)
- ->will($this->returnValue($default));
- $this->assertInstanceOf('Predis\Connection\ConnectionFactoryInterface', $factory = $option->filter($options, $value));
- $this->assertSame($default, $factory);
- }
-
- public function testAcceptsConnectionFactoryInstance()
- {
- $option = new ConnectionFactoryOption();
- $options = $this->getMock('Predis\Configuration\OptionsInterface');
- $value = $this->getMock('Predis\Connection\ConnectionFactoryInterface');
- $option = $this->getMock('Predis\Configuration\ConnectionFactoryOption', array('getDefault'));
- $option->expects($this->never())->method('getDefault');
- $this->assertSame($value, $option->filter($options, $value));
- }
-
- public function testThrowsExceptionOnInvalidArguments()
- {
- $option = new ConnectionFactoryOption();
- $options = $this->getMock('Predis\Configuration\OptionsInterface');
- $option->filter($options, new stdClass);
- }
- }
|