|
@@ -24,12 +24,22 @@ class ScriptCommandTest extends PredisTestCase
|
|
|
/**
|
|
|
* @group disconnected
|
|
|
*/
|
|
|
- public function testGetArguments()
|
|
|
+ public function testGetId()
|
|
|
+ {
|
|
|
+ $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript'));
|
|
|
+
|
|
|
+ $this->assertSame('EVALSHA', $command->getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @group disconnected
|
|
|
+ */
|
|
|
+ public function testGetScriptHash()
|
|
|
{
|
|
|
$arguments = array('key1', 'key2', 'value1', 'value2');
|
|
|
|
|
|
$command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount'));
|
|
|
- $command->expects($this->once())
|
|
|
+ $command->expects($this->exactly(2))
|
|
|
->method('getScript')
|
|
|
->will($this->returnValue(self::LUA_SCRIPT));
|
|
|
$command->expects($this->once())
|
|
@@ -37,13 +47,13 @@ class ScriptCommandTest extends PredisTestCase
|
|
|
->will($this->returnValue(2));
|
|
|
$command->setArguments($arguments);
|
|
|
|
|
|
- $this->assertSame(array_merge(array(self::LUA_SCRIPT_SHA1, 2), $arguments), $command->getArguments());
|
|
|
+ $this->assertSame(self::LUA_SCRIPT_SHA1, $command->getScriptHash());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @group disconnected
|
|
|
*/
|
|
|
- public function testGetArgumentsWithNegativeKeysCount()
|
|
|
+ public function testGetKeys()
|
|
|
{
|
|
|
$arguments = array('key1', 'key2', 'value1', 'value2');
|
|
|
|
|
@@ -51,37 +61,53 @@ class ScriptCommandTest extends PredisTestCase
|
|
|
$command->expects($this->once())
|
|
|
->method('getScript')
|
|
|
->will($this->returnValue(self::LUA_SCRIPT));
|
|
|
- $command->expects($this->once())
|
|
|
+ $command->expects($this->exactly(2))
|
|
|
->method('getKeysCount')
|
|
|
- ->will($this->returnValue(-2));
|
|
|
+ ->will($this->returnValue(2));
|
|
|
$command->setArguments($arguments);
|
|
|
|
|
|
- $this->assertSame(array_merge(array(self::LUA_SCRIPT_SHA1, 2), $arguments), $command->getArguments());
|
|
|
+ $this->assertSame(array('key1', 'key2'), $command->getKeys());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @group disconnected
|
|
|
*/
|
|
|
- public function testGetArgumentsWithZeroKeysCount()
|
|
|
+ public function testGetKeysWithZeroKeysCount()
|
|
|
{
|
|
|
$arguments = array('value1', 'value2', 'value3');
|
|
|
|
|
|
- $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount'));
|
|
|
+ $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript'));
|
|
|
$command->expects($this->once())
|
|
|
->method('getScript')
|
|
|
->will($this->returnValue(self::LUA_SCRIPT));
|
|
|
+ $command->setArguments($arguments);
|
|
|
+
|
|
|
+ $this->assertSame(array(), $command->getKeys());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @group disconnected
|
|
|
+ */
|
|
|
+ public function testGetKeysWithNegativeKeysCount()
|
|
|
+ {
|
|
|
+ $arguments = array('key1', 'key2', 'value1', 'value2');
|
|
|
+
|
|
|
+ $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount'));
|
|
|
$command->expects($this->once())
|
|
|
+ ->method('getScript')
|
|
|
+ ->will($this->returnValue(self::LUA_SCRIPT));
|
|
|
+ $command->expects($this->exactly(2))
|
|
|
->method('getKeysCount')
|
|
|
- ->will($this->returnValue(0));
|
|
|
+ ->will($this->returnValue(-2));
|
|
|
$command->setArguments($arguments);
|
|
|
|
|
|
- $this->assertSame(array_merge(array(self::LUA_SCRIPT_SHA1, 0), $arguments), $command->getArguments());
|
|
|
+ $this->assertSame(array('key1', 'key2'), $command->getKeys());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @group disconnected
|
|
|
*/
|
|
|
- public function testGetKeys()
|
|
|
+ public function testGetArguments()
|
|
|
{
|
|
|
$arguments = array('key1', 'key2', 'value1', 'value2');
|
|
|
|
|
@@ -89,18 +115,18 @@ class ScriptCommandTest extends PredisTestCase
|
|
|
$command->expects($this->once())
|
|
|
->method('getScript')
|
|
|
->will($this->returnValue(self::LUA_SCRIPT));
|
|
|
- $command->expects($this->exactly(2))
|
|
|
+ $command->expects($this->once())
|
|
|
->method('getKeysCount')
|
|
|
->will($this->returnValue(2));
|
|
|
$command->setArguments($arguments);
|
|
|
|
|
|
- $this->assertSame(array('key1', 'key2'), $command->getKeys());
|
|
|
+ $this->assertSame(array_merge(array(self::LUA_SCRIPT_SHA1, 2), $arguments), $command->getArguments());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @group disconnected
|
|
|
*/
|
|
|
- public function testGetKeysWithZeroKeysCount()
|
|
|
+ public function testGetArgumentsWithZeroKeysCount()
|
|
|
{
|
|
|
$arguments = array('value1', 'value2', 'value3');
|
|
|
|
|
@@ -108,18 +134,15 @@ class ScriptCommandTest extends PredisTestCase
|
|
|
$command->expects($this->once())
|
|
|
->method('getScript')
|
|
|
->will($this->returnValue(self::LUA_SCRIPT));
|
|
|
- $command->expects($this->exactly(2))
|
|
|
- ->method('getKeysCount')
|
|
|
- ->will($this->returnValue(0));
|
|
|
$command->setArguments($arguments);
|
|
|
|
|
|
- $this->assertSame(array(), $command->getKeys());
|
|
|
+ $this->assertSame(array_merge(array(self::LUA_SCRIPT_SHA1, 0), $arguments), $command->getArguments());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @group disconnected
|
|
|
*/
|
|
|
- public function testGetKeysWithNegativeKeysCount()
|
|
|
+ public function testGetArgumentsWithNegativeKeysCount()
|
|
|
{
|
|
|
$arguments = array('key1', 'key2', 'value1', 'value2');
|
|
|
|
|
@@ -127,23 +150,42 @@ class ScriptCommandTest extends PredisTestCase
|
|
|
$command->expects($this->once())
|
|
|
->method('getScript')
|
|
|
->will($this->returnValue(self::LUA_SCRIPT));
|
|
|
- $command->expects($this->exactly(2))
|
|
|
+ $command->expects($this->once())
|
|
|
->method('getKeysCount')
|
|
|
->will($this->returnValue(-2));
|
|
|
$command->setArguments($arguments);
|
|
|
|
|
|
- $this->assertSame(array('key1', 'key2'), $command->getKeys());
|
|
|
+ $this->assertSame(array_merge(array(self::LUA_SCRIPT_SHA1, 2), $arguments), $command->getArguments());
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @group disconnected
|
|
|
*/
|
|
|
- public function testGetScriptHash()
|
|
|
+ public function testGetEvalArguments()
|
|
|
{
|
|
|
$arguments = array('key1', 'key2', 'value1', 'value2');
|
|
|
|
|
|
$command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount'));
|
|
|
+ $command->expects($this->exactly(2))
|
|
|
+ ->method('getScript')
|
|
|
+ ->will($this->returnValue(self::LUA_SCRIPT));
|
|
|
$command->expects($this->once())
|
|
|
+ ->method('getKeysCount')
|
|
|
+ ->will($this->returnValue(2));
|
|
|
+ $command->setArguments($arguments);
|
|
|
+
|
|
|
+ $this->assertSame(array_merge(array(self::LUA_SCRIPT, 2), $arguments), $command->getEvalArguments());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @group disconnected
|
|
|
+ */
|
|
|
+ public function testGetEvalCommand()
|
|
|
+ {
|
|
|
+ $arguments = array('key1', 'key2', 'value1', 'value2');
|
|
|
+
|
|
|
+ $command = $this->getMock('Predis\Command\ScriptCommand', array('getScript', 'getKeysCount'));
|
|
|
+ $command->expects($this->exactly(2))
|
|
|
->method('getScript')
|
|
|
->will($this->returnValue(self::LUA_SCRIPT));
|
|
|
$command->expects($this->once())
|
|
@@ -151,6 +193,8 @@ class ScriptCommandTest extends PredisTestCase
|
|
|
->will($this->returnValue(2));
|
|
|
$command->setArguments($arguments);
|
|
|
|
|
|
- $this->assertSame(self::LUA_SCRIPT_SHA1, $command->getScriptHash());
|
|
|
+ $evalCMD = new RawCommand('EVAL', array_merge(array(self::LUA_SCRIPT, 2), $arguments));
|
|
|
+
|
|
|
+ $this->assertRedisCommand($evalCMD, $command->getEvalCommand());
|
|
|
}
|
|
|
}
|