Merge remote-tracking branch 'github/pr/639' into main

This commit is contained in:
Daniele Alessandri
2020-08-18 16:03:10 +02:00
177 changed files with 1649 additions and 1043 deletions
@@ -53,9 +53,14 @@ class KeyPrefixProcessorTest extends PredisTestCase
{
$prefix = 'prefix:';
$command = $this->getMock('Predis\Command\PrefixableCommandInterface');
$command->expects($this->never())->method('getId');
$command->expects($this->once())->method('prefixKeys')->with($prefix);
$command = $this->getMockBuilder('Predis\Command\PrefixableCommandInterface')->getMock();
$command
->expects($this->never())
->method('getId');
$command
->expects($this->once())
->method('prefixKeys')
->with($prefix);
$processor = new KeyPrefixProcessor($prefix);
@@ -67,12 +72,13 @@ class KeyPrefixProcessorTest extends PredisTestCase
*/
public function testSkipNotPrefixableCommands()
{
$command = $this->getMock('Predis\Command\CommandInterface');
$command = $this->getMockBuilder('Predis\Command\CommandInterface')->getMock();
$command->expects($this->once())
->method('getId')
->will($this->returnValue('unknown'));
$command->expects($this->never())
->method('getArguments');
->method('getId')
->will($this->returnValue('unknown'));
$command
->expects($this->never())
->method('getArguments');
$processor = new KeyPrefixProcessor('prefix');
@@ -287,13 +293,16 @@ class KeyPrefixProcessorTest extends PredisTestCase
{
$command = $this->getCommandInstance('NEWCMD', array('key', 'value'));
$callable = $this->getMock('stdClass', array('__invoke'));
$callable->expects($this->once())
->method('__invoke')
->with($command, 'prefix:')
->will($this->returnCallback(function ($command, $prefix) {
$command->setRawArguments(array('prefix:key', 'value'));
}));
$callable = $this->getMockBuilder('stdClass')
->setMethods(array('__invoke'))
->getMock();
$callable
->expects($this->once())
->method('__invoke')
->with($command, 'prefix:')
->will($this->returnCallback(function ($command, $prefix) {
$command->setRawArguments(array('prefix:key', 'value'));
}));
$processor = new KeyPrefixProcessor('prefix:');
$processor->setCommandHandler('NEWCMD', $callable);
@@ -309,13 +318,16 @@ class KeyPrefixProcessorTest extends PredisTestCase
{
$command = $this->getCommandInstance('SET', array('key', 'value'));
$callable = $this->getMock('stdClass', array('__invoke'));
$callable->expects($this->once())
->method('__invoke')
->with($command, 'prefix:')
->will($this->returnCallback(function ($command, $prefix) {
$command->setRawArguments(array('prefix:key', 'value'));
}));
$callable = $this->getMockBuilder('stdClass')
->setMethods(array('__invoke'))
->getMock();
$callable
->expects($this->once())
->method('__invoke')
->with($command, 'prefix:')
->will($this->returnCallback(function ($command, $prefix) {
$command->setRawArguments(array('prefix:key', 'value'));
}));
$processor = new KeyPrefixProcessor('prefix:');
$processor->setCommandHandler('SET', $callable);
@@ -340,11 +352,12 @@ class KeyPrefixProcessorTest extends PredisTestCase
/**
* @group disconnected
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Callback must be a valid callable object or NULL
*/
public function testCannotDefineCommandHandlerWithInvalidType()
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Callback must be a valid callable object or NULL');
$processor = new KeyPrefixProcessor('prefix:');
$processor->setCommandHandler('NEWCMD', new \stdClass());
}