mirror of
https://github.com/predis/predis.git
synced 2026-10-08 12:57:14 +00:00
Accepts callable as first argument of Predis\Client::__construct().
Users can then use callables to wrap the creation and initialization of the underlying connection with custom strategies:
This commit is contained in:
@@ -197,6 +197,42 @@ class ClientTest extends StandardTestCase
|
||||
$this->assertSame($replication, $client->getConnection());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
public function testConstructorWithCallableArgument()
|
||||
{
|
||||
$connection = $this->getMock('Predis\Connection\ConnectionInterface');
|
||||
|
||||
$callable = $this->getMock('stdClass', array('__invoke'));
|
||||
$callable->expects($this->once())
|
||||
->method('__invoke')
|
||||
->with($this->isInstanceOf('Predis\Option\ClientOptions'))
|
||||
->will($this->returnValue($connection));
|
||||
|
||||
$client = new Client($callable);
|
||||
|
||||
$this->assertSame($connection, $client->getConnection());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
* @expectedException InvalidArgumentException
|
||||
* @expectedExceptionMessage Callable parameters must return instances of Predis\Connection\ConnectionInterface
|
||||
*/
|
||||
public function testConstructorWithCallableArgumentButInvalidReturnType()
|
||||
{
|
||||
$wrongType = $this->getMock('stdClass');
|
||||
|
||||
$callable = $this->getMock('stdClass', array('__invoke'));
|
||||
$callable->expects($this->once())
|
||||
->method('__invoke')
|
||||
->with($this->isInstanceOf('Predis\Option\ClientOptions'))
|
||||
->will($this->returnValue($wrongType));
|
||||
|
||||
$client = new Client($callable);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user