浏览代码

[tests] Add missing tests for SETNX.

For some obscure reason Predis/Command/StringSetPreserve had no tests.
Daniele Alessandri 11 年之前
父节点
当前提交
d53069f096
共有 1 个文件被更改,包括 96 次插入0 次删除
  1. 96 0
      tests/Predis/Command/StringSetPreserveTest.php

+ 96 - 0
tests/Predis/Command/StringSetPreserveTest.php

@@ -0,0 +1,96 @@
+<?php
+
+/*
+ * This file is part of the Predis package.
+ *
+ * (c) Daniele Alessandri <suppakilla@gmail.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Predis\Command;
+
+use PHPUnit_Framework_TestCase as StandardTestCase;
+
+/**
+ * @group commands
+ * @group realm-string
+ */
+class StringSetPreserveTest extends CommandTestCase
+{
+    /**
+     * {@inheritdoc}
+     */
+    protected function getExpectedCommand()
+    {
+        return 'Predis\Command\StringSetPreserve';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    protected function getExpectedId()
+    {
+        return 'SETNX';
+    }
+
+    /**
+     * @group disconnected
+     */
+    public function testFilterArguments()
+    {
+        $arguments = array('foo', 'bar');
+        $expected = array('foo', 'bar');
+
+        $command = $this->getCommand();
+        $command->setArguments($arguments);
+
+        $this->assertSame($expected, $command->getArguments());
+    }
+
+    /**
+     * @group disconnected
+     */
+    public function testParseResponse()
+    {
+        $this->assertTrue($this->getCommand()->parseResponse(1));
+    }
+
+    /**
+     * @group disconnected
+     */
+    public function testPrefixKeys()
+    {
+        $arguments = array('key', 'value');
+        $expected = array('prefix:key', 'value');
+
+        $command = $this->getCommandWithArgumentsArray($arguments);
+        $command->prefixKeys('prefix:');
+
+        $this->assertSame($expected, $command->getArguments());
+    }
+
+    /**
+     * @group disconnected
+     */
+    public function testPrefixKeysIgnoredOnEmptyArguments()
+    {
+        $command = $this->getCommand();
+        $command->prefixKeys('prefix:');
+
+        $this->assertSame(array(), $command->getArguments());
+    }
+
+    /**
+     * @group connected
+     */
+    public function testSetStringValue()
+    {
+        $redis = $this->getClient();
+
+        $this->assertTrue($redis->setnx('foo', 'bar'));
+        $this->assertFalse($redis->setnx('foo', 'barbar'));
+        $this->assertEquals('bar', $redis->get('foo'));
+    }
+}