Bläddra i källkod

[tests] Add missing tests for SETNX.

For some obscure reason Predis/Command/StringSetPreserve had no tests.
Daniele Alessandri 11 år sedan
förälder
incheckning
00247abc50
1 ändrade filer med 71 tillägg och 0 borttagningar
  1. 71 0
      tests/Predis/Command/StringSetPreserveTest.php

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

@@ -0,0 +1,71 @@
+<?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 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'));
+    }
+}