Permalink
Browse files

[tests] Rewrite the whole test suite to allow more granular testing.

Fix also a few bugs found while rewriting the test suite.

In order to be able to run integration tests, the test suite requires
a version of Redis >= 2.4.0.

The units have been splitted into several different groups using
PHPUnit @group annotation to allow developers to enable, disable
and combine certain types of tests. The available groups are:

  - disconnected: can run without a Redis server online
  - connected: active connection to a Redis server is required
  - commands: test dedicated to a specific Redis command
  - slow: performs operations that can slow down execution;

A list of the available groups can be obtained by running

  phpunit --list-groups

Groups of tests can be disabled or enabled via the XML configuration
file or the standard command-line test runner. Please note that due
to a bug in PHPUnit, older versions ignore the --group option when
the group is excluded in the XML configuration file. Please refer to
http://github.com/sebastianbergmann/phpunit/issues/320 for details

Integration tests in the @connected group check if the command being
tested is defined in the selected server profile (see the value of
the TEST_SERVER_VERSION constant in phpunit.xml). If the command is
not defined in the target server profile, the integration test is
automatically marked as skipped.

We also provide an helper script in the bin directory that can be
used to automatically generate a file with the scheleton of a test
case for a Redis command by specifying the name of the class in the
Predis\Commands namespace. For example, to generate a test case for
SET (represented by the Predis\Commands\StringSet class):

  ./bin/generate-command-test.php --class=StringSet

The realm of a command is automatically inferred from the name of the
class, but it can be set using the --realm option.
  • Loading branch information...
1 parent dd20e85 commit 371ac917777ddd6e0fc6eb672df0dfd0e175deb1 @nrk committed Dec 3, 2011
Showing with 24,387 additions and 3,911 deletions.
  1. +0 −1 .gitignore
  2. +1 −2 .travis.yml
  3. +23 −10 README.md
  4. +0 −8 TODO
  5. +237 −0 bin/generate-command-test.php
  6. +1 −1 examples/ServerSideScripting.php
  7. +1 −6 lib/Predis/Autoloader.php
  8. +2 −4 lib/Predis/Client.php
  9. +0 −8 lib/Predis/Commands/HashDelete.php
  10. +1 −0 lib/Predis/Commands/KeyKeysV12x.php
  11. +1 −1 lib/Predis/Commands/KeyRandom.php
  12. +12 −0 lib/Predis/Commands/ListPopFirstBlocking.php
  13. +6 −6 lib/Predis/Commands/PrefixHelpers.php
  14. +4 −3 lib/Predis/Commands/PrefixableCommand.php
  15. +2 −1 lib/Predis/Commands/Processors/ProcessorChain.php
  16. +10 −0 lib/Predis/Commands/PubSubUnsubscribe.php
  17. +13 −7 lib/Predis/Commands/ScriptedCommand.php
  18. +1 −1 lib/Predis/Commands/ServerEval.php
  19. +1 −1 lib/Predis/Commands/ServerInfo.php
  20. +5 −1 lib/Predis/Commands/ServerInfoV26x.php
  21. +0 −8 lib/Predis/Commands/SetAdd.php
  22. +0 −8 lib/Predis/Commands/SetRemove.php
  23. +10 −8 lib/Predis/Commands/ZSetAdd.php
  24. +0 −8 lib/Predis/Commands/ZSetRemove.php
  25. +1 −1 lib/Predis/Iterators/MultiBulkResponseSimple.php
  26. +10 −2 lib/Predis/Iterators/MultiBulkResponseTuple.php
  27. +2 −6 lib/Predis/MonitorContext.php
  28. +3 −4 lib/Predis/Network/ConnectionBase.php
  29. +5 −4 lib/Predis/Network/PhpiredisConnection.php
  30. +8 −6 lib/Predis/Network/PredisCluster.php
  31. +1 −0 lib/Predis/Network/StreamConnection.php
  32. +10 −8 lib/Predis/Network/WebdisConnection.php
  33. +22 −0 lib/Predis/NotSupportedException.php
  34. +7 −5 lib/Predis/Options/ClientCluster.php
  35. +8 −0 lib/Predis/Options/ClientConnectionFactory.php
  36. +1 −1 lib/Predis/Options/CustomOption.php
  37. +13 −3 lib/Predis/Pipeline/PipelineContext.php
  38. +17 −9 lib/Predis/Profiles/ServerProfile.php
  39. +73 −73 lib/Predis/Profiles/ServerVersion12.php
  40. +105 −105 lib/Predis/Profiles/ServerVersion20.php
  41. +120 −120 lib/Predis/Profiles/ServerVersion22.php
  42. +121 −121 lib/Predis/Profiles/ServerVersion24.php
  43. +10 −10 lib/Predis/Profiles/ServerVersionNext.php
  44. +1 −2 lib/Predis/PubSub/DispatcherLoop.php
  45. +24 −14 lib/Predis/PubSub/PubSubContext.php
  46. +9 −23 lib/Predis/Transaction/MultiExecContext.php
  47. +23 −6 phpunit.xml.dist
  48. +0 −830 test/ClientFeaturesTest.php
  49. +0 −283 test/PredisShared.php
  50. +0 −2,181 test/RedisCommandsTest.php
  51. +52 −0 tests/PHPUnit/ArrayHasSameValuesConstraint.php
  52. +174 −0 tests/PHPUnit/CommandTestCase.php
  53. +387 −0 tests/PHPUnit/ConnectionTestCase.php
  54. +67 −0 tests/PHPUnit/DistributionStrategyTestCase.php
  55. +77 −0 tests/PHPUnit/ServerVersionTestCase.php
  56. +43 −0 tests/Predis/ClientExceptionTest.php
  57. +647 −0 tests/Predis/ClientTest.php
  58. +216 −0 tests/Predis/Commands/CommandTest.php
  59. +64 −0 tests/Predis/Commands/ConnectionAuthTest.php
  60. +76 −0 tests/Predis/Commands/ConnectionEchoTest.php
  61. +71 −0 tests/Predis/Commands/ConnectionPingTest.php
  62. +72 −0 tests/Predis/Commands/ConnectionQuitTest.php
  63. +86 −0 tests/Predis/Commands/ConnectionSelectTest.php
  64. +114 −0 tests/Predis/Commands/HashDeleteTest.php
  65. +103 −0 tests/Predis/Commands/HashExistsTest.php
  66. +104 −0 tests/Predis/Commands/HashGetAllTest.php
  67. +120 −0 tests/Predis/Commands/HashGetMultipleTest.php
  68. +100 −0 tests/Predis/Commands/HashGetTest.php
  69. +125 −0 tests/Predis/Commands/HashIncrementByFloatTest.php
  70. +125 −0 tests/Predis/Commands/HashIncrementByTest.php
  71. +104 −0 tests/Predis/Commands/HashKeysTest.php
  72. +99 −0 tests/Predis/Commands/HashLengthTest.php
  73. +126 −0 tests/Predis/Commands/HashSetMultipleTest.php
  74. +103 −0 tests/Predis/Commands/HashSetPreserveTest.php
  75. +102 −0 tests/Predis/Commands/HashSetTest.php
  76. +104 −0 tests/Predis/Commands/HashValuesTest.php
  77. +108 −0 tests/Predis/Commands/KeyDeleteTest.php
  78. +97 −0 tests/Predis/Commands/KeyExistsTest.php
  79. +119 −0 tests/Predis/Commands/KeyExpireAtTest.php
  80. +132 −0 tests/Predis/Commands/KeyExpireTest.php
  81. +94 −0 tests/Predis/Commands/KeyKeysTest.php
  82. +80 −0 tests/Predis/Commands/KeyKeysV12xTest.php
  83. +110 −0 tests/Predis/Commands/KeyMoveTest.php
  84. +112 −0 tests/Predis/Commands/KeyPersistTest.php
  85. +109 −0 tests/Predis/Commands/KeyPreciseExpireAtTest.php
  86. +134 −0 tests/Predis/Commands/KeyPreciseExpireTest.php
  87. +109 −0 tests/Predis/Commands/KeyPreciseTimeToLiveTest.php
  88. +87 −0 tests/Predis/Commands/KeyRandomTest.php
  89. +100 −0 tests/Predis/Commands/KeyRenamePreserveTest.php
  90. +99 −0 tests/Predis/Commands/KeyRenameTest.php
  91. +270 −0 tests/Predis/Commands/KeySortTest.php
  92. +109 −0 tests/Predis/Commands/KeyTimeToLiveTest.php
  93. +98 −0 tests/Predis/Commands/KeyTypeTest.php
  94. +115 −0 tests/Predis/Commands/ListIndexTest.php
  95. +123 −0 tests/Predis/Commands/ListInsertTest.php
  96. +110 −0 tests/Predis/Commands/ListLengthTest.php
  97. +94 −0 tests/Predis/Commands/ListPopFirstBlockingTest.php
  98. +110 −0 tests/Predis/Commands/ListPopFirstTest.php
  99. +94 −0 tests/Predis/Commands/ListPopLastBlockingTest.php
  100. +75 −0 tests/Predis/Commands/ListPopLastPushHeadBlockingTest.php
  101. +144 −0 tests/Predis/Commands/ListPopLastPushHeadTest.php
  102. +110 −0 tests/Predis/Commands/ListPopLastTest.php
  103. +113 −0 tests/Predis/Commands/ListPushHeadTest.php
  104. +111 −0 tests/Predis/Commands/ListPushHeadXTest.php
  105. +113 −0 tests/Predis/Commands/ListPushTailTest.php
  106. +111 −0 tests/Predis/Commands/ListPushTailXTest.php
  107. +154 −0 tests/Predis/Commands/ListRangeTest.php
  108. +138 −0 tests/Predis/Commands/ListRemoveTest.php
  109. +112 −0 tests/Predis/Commands/ListSetTest.php
  110. +144 −0 tests/Predis/Commands/ListTrimTest.php
  111. +84 −0 tests/Predis/Commands/PrefixHelpersTest.php
  112. +54 −0 tests/Predis/Commands/PrefixableCommandTest.php
  113. +83 −0 tests/Predis/Commands/Processors/KeyPrefixProcessorTest.php
  114. +170 −0 tests/Predis/Commands/Processors/ProcessorChainTest.php
  115. +87 −0 tests/Predis/Commands/PubSubPublishTest.php
  116. +173 −0 tests/Predis/Commands/PubSubSubscribeByPatternTest.php
  117. +173 −0 tests/Predis/Commands/PubSubSubscribeTest.php
  118. +141 −0 tests/Predis/Commands/PubSubUnsubscribeByPatternTest.php
  119. +139 −0 tests/Predis/Commands/PubSubUnsubscribeTest.php
  120. +101 −0 tests/Predis/Commands/ScriptedCommandTest.php
  121. +56 −0 tests/Predis/Commands/ServerBackgroundRewriteAOFTest.php
  122. +56 −0 tests/Predis/Commands/ServerBackgroundSaveTest.php
  123. +142 −0 tests/Predis/Commands/ServerClientTest.php
  124. +173 −0 tests/Predis/Commands/ServerConfigTest.php
  125. +67 −0 tests/Predis/Commands/ServerDatabaseSizeTest.php
  126. +118 −0 tests/Predis/Commands/ServerEvalSHATest.php
  127. +122 −0 tests/Predis/Commands/ServerEvalTest.php
  128. +56 −0 tests/Predis/Commands/ServerFlushAllTest.php
  129. +69 −0 tests/Predis/Commands/ServerFlushDatabaseTest.php
  130. +289 −0 tests/Predis/Commands/ServerInfoTest.php
  131. +307 −0 tests/Predis/Commands/ServerInfoV26xTest.php
  132. +66 −0 tests/Predis/Commands/ServerLastSaveTest.php
  133. +69 −0 tests/Predis/Commands/ServerMonitorTest.php
  134. +115 −0 tests/Predis/Commands/ServerObjectTest.php
  135. +56 −0 tests/Predis/Commands/ServerSaveTest.php
  136. +110 −0 tests/Predis/Commands/ServerScriptTest.php
  137. +48 −0 tests/Predis/Commands/ServerShutdownTest.php
  138. +87 −0 tests/Predis/Commands/ServerSlaveOfTest.php
  139. +119 −0 tests/Predis/Commands/ServerSlowlogTest.php
  140. +112 −0 tests/Predis/Commands/SetAddTest.php
  141. +108 −0 tests/Predis/Commands/SetCardinalityTest.php
  142. +131 −0 tests/Predis/Commands/SetDifferenceStoreTest.php
  143. +133 −0 tests/Predis/Commands/SetDifferenceTest.php
  144. +144 −0 tests/Predis/Commands/SetIntersectionStoreTest.php
  145. +144 −0 tests/Predis/Commands/SetIntersectionTest.php
  146. +112 −0 tests/Predis/Commands/SetIsMemberTest.php
  147. +104 −0 tests/Predis/Commands/SetMembersTest.php
  148. +120 −0 tests/Predis/Commands/SetMoveTest.php
  149. +101 −0 tests/Predis/Commands/SetPopTest.php
  150. +109 −0 tests/Predis/Commands/SetRandomMemberTest.php
  151. +116 −0 tests/Predis/Commands/SetRemoveTest.php
  152. +131 −0 tests/Predis/Commands/SetUnionStoreTest.php
  153. +133 −0 tests/Predis/Commands/SetUnionTest.php
  154. +111 −0 tests/Predis/Commands/StringAppendTest.php
  155. +136 −0 tests/Predis/Commands/StringDecrementByTest.php
  156. +123 −0 tests/Predis/Commands/StringDecrementTest.php
  157. +129 −0 tests/Predis/Commands/StringGetBitTest.php
  158. +127 −0 tests/Predis/Commands/StringGetMultipleTest.php
  159. +114 −0 tests/Predis/Commands/StringGetRangeTest.php
  160. +100 −0 tests/Predis/Commands/StringGetSetTest.php
  161. +121 −0 tests/Predis/Commands/StringGetTest.php
  162. +136 −0 tests/Predis/Commands/StringIncrementByFloatTest.php
  163. +136 −0 tests/Predis/Commands/StringIncrementByTest.php
  164. +110 −0 tests/Predis/Commands/StringIncrementTest.php
  165. +130 −0 tests/Predis/Commands/StringPreciseSetExpireTest.php
  166. +145 −0 tests/Predis/Commands/StringSetBitTest.php
  167. +128 −0 tests/Predis/Commands/StringSetExpireTest.php
  168. +113 −0 tests/Predis/Commands/StringSetMultiplePreserveTest.php
  169. +99 −0 tests/Predis/Commands/StringSetMultipleTest.php
  170. +139 −0 tests/Predis/Commands/StringSetRangeTest.php
  171. +85 −0 tests/Predis/Commands/StringSetTest.php
  172. +110 −0 tests/Predis/Commands/StringStrlenTest.php
  173. +77 −0 tests/Predis/Commands/StringSubstrTest.php
  174. +82 −0 tests/Predis/Commands/TransactionDiscardTest.php
  175. +114 −0 tests/Predis/Commands/TransactionExecTest.php
  176. +93 −0 tests/Predis/Commands/TransactionMultiTest.php
  177. +86 −0 tests/Predis/Commands/TransactionUnwatchTest.php
  178. +134 −0 tests/Predis/Commands/TransactionWatchTest.php
  179. +125 −0 tests/Predis/Commands/ZSetAddTest.php
  180. +99 −0 tests/Predis/Commands/ZSetCardinalityTest.php
  181. +132 −0 tests/Predis/Commands/ZSetCountTest.php
  182. +99 −0 tests/Predis/Commands/ZSetIncrementByTest.php
  183. +193 −0 tests/Predis/Commands/ZSetIntersectionStoreTest.php
  184. +230 −0 tests/Predis/Commands/ZSetRangeByScoreTest.php
  185. +153 −0 tests/Predis/Commands/ZSetRangeTest.php
  186. +102 −0 tests/Predis/Commands/ZSetRankTest.php
  187. +114 −0 tests/Predis/Commands/ZSetRemoveRangeByRankTest.php
  188. +114 −0 tests/Predis/Commands/ZSetRemoveRangeByScoreTest.php
  189. +101 −0 tests/Predis/Commands/ZSetRemoveTest.php
  190. +230 −0 tests/Predis/Commands/ZSetReverseRangeByScoreTest.php
  191. +153 −0 tests/Predis/Commands/ZSetReverseRangeTest.php
  192. +102 −0 tests/Predis/Commands/ZSetReverseRankTest.php
  193. +102 −0 tests/Predis/Commands/ZSetScoreTest.php
  194. +210 −0 tests/Predis/Commands/ZSetUnionStoreTest.php
  195. +98 −0 tests/Predis/CommunicationExceptionTest.php
  196. +353 −0 tests/Predis/ConnectionFactoryTest.php
  197. +225 −0 tests/Predis/ConnectionParametersTest.php
  198. +31 −0 tests/Predis/Distribution/EmptyRingExceptionTest.php
  199. +132 −0 tests/Predis/Distribution/HashRingTest.php
  200. +133 −0 tests/Predis/Distribution/KetamaPureRingTest.php
  201. +96 −0 tests/Predis/HelpersTest.php
  202. +123 −0 tests/Predis/Iterators/MultiBulkResponseSimpleTest.php
  203. +94 −0 tests/Predis/Iterators/MultiBulkResponseTupleTest.php
  204. +171 −0 tests/Predis/MonitorContextTest.php
  205. +31 −0 tests/Predis/Network/ConnectionExceptionTest.php
  206. +117 −0 tests/Predis/Network/PhpiredisConnectionTest.php
  207. +311 −0 tests/Predis/Network/PredisClusterTest.php
  208. +111 −0 tests/Predis/Network/StreamConnectionTest.php
  209. +198 −0 tests/Predis/Network/WebdisConnectionTest.php
  210. +125 −0 tests/Predis/Options/ClientClusterTest.php
  211. +117 −0 tests/Predis/Options/ClientConnectionFactoryTest.php
  212. +79 −0 tests/Predis/Options/ClientOptionsTest.php
  213. +59 −0 tests/Predis/Options/ClientPrefixTest.php
  214. +172 −0 tests/Predis/Options/ClientProfileTest.php
  215. +114 −0 tests/Predis/Options/CustomOptionTest.php
  216. +79 −0 tests/Predis/Options/OptionTest.php
  217. +420 −0 tests/Predis/Pipeline/PipelineContextTest.php
  218. +33 −0 tests/Predis/PredisExceptionTest.php
  219. +265 −0 tests/Predis/Profiles/ServerProfileTest.php
  220. +116 −0 tests/Predis/Profiles/ServerVersion12Test.php
  221. +148 −0 tests/Predis/Profiles/ServerVersion20Test.php
  222. +163 −0 tests/Predis/Profiles/ServerVersion22Test.php
  223. +164 −0 tests/Predis/Profiles/ServerVersion24Test.php
  224. +173 −0 tests/Predis/Profiles/ServerVersionNextTest.php
  225. +31 −0 tests/Predis/Protocol/ProtocolExceptionTest.php
  226. +83 −0 tests/Predis/PubSub/DispatcherLoopTest.php
  227. +294 −0 tests/Predis/PubSub/PubSubContextTest.php
  228. +63 −0 tests/Predis/ResponseErrorTest.php
  229. +51 −0 tests/Predis/ResponseQueuedTest.php
  230. +69 −0 tests/Predis/ServerExceptionTest.php
  231. +36 −0 tests/Predis/Transaction/AbortedMultiExecExceptionTest.php
  232. +726 −0 tests/Predis/Transaction/MultiExecContextTest.php
  233. +88 −0 tests/README.md
  234. +6 −1 {test → tests}/bootstrap.php
View
@@ -1,3 +1,2 @@
phpunit.xml
experiments/
-test/enable.tests
View
@@ -2,8 +2,7 @@ language: php
php:
- 5.3
- 5.4
-before_script: touch test/enable.tests
branches:
only:
- master
- - version-0.6
+ - v0.7
View
@@ -148,27 +148,40 @@ $redis->newcmd();
```
-## Development ##
+## Test suite ##
-Predis is fully backed up by a test suite which tries to cover all the aspects of the
-client library and the interaction of every single command with a Redis server. If you
-want to work on Predis, it is highly recommended that you first run the test suite to
-be sure that everything is OK, and report strange behaviours or bugs.
+__ATTENTION__: Do not run the test suite shipped with Predis against instances of
+Redis running in production environments or containing data you are interested in!
-When modifying Predis please be sure that no warnings or notices are emitted by PHP
+Predis has a comprehensive test suite covering every aspect of the library. The suite
+performs integration tests against a running instance of Redis (>= 2.4.0 is required)
+to verify the correct behaviour of the implementation of each command and automatically
+skips commands that are not defined in the selected version of Redis. If you do not have
+Redis up and running, integration tests can be disabled. By default, the test suite is
+configured to execute integration tests using the server profile for Redis v2.4 (which
+is the current stable version of Redis). You can optionally run the suite against a
+Redis instance built from the `unstable` branch with the development profile by changing
+the `TEST_SERVER_VERSION` to `dev` in the `phpunit.xml` file. More details about testing
+Predis are available in `tests/README.md`.
+
+## Contributing ##
+
+If you want to work on Predis, it is highly recommended that you first run the test
+suite in order to check that everything is OK, and report strange behaviours or bugs.
+
+When modifying Predis please make sure that no warnings or notices are emitted by PHP
by running the interpreter in your development environment with the `error_reporting`
variable set to `E_ALL | E_STRICT`.
The recommended way to contribute to Predis is to fork the project on GitHub, create
new topic branches on your newly created repository to fix or add features and then
-open a new pull request with a description of the applied changes. Obviously, you can
-use any other Git hosting provider of your preference. Diff patches will be accepted
-too, even though they are not the preferred way to contribute to Predis.
+open a new pull request with a description of the applied changes. Obviously, you
+can use any other Git hosting provider of your preference.
## Dependencies ##
-- PHP >= 5.3.0
+- PHP >= 5.3.2
- PHPUnit >= 3.5.0 (needed to run the test suite)
## Links ##
View
8 TODO
@@ -2,13 +2,5 @@
* Implement smart and transparent support for redis-cluster.
-* Switch to smaller test units and add more granular tests that try to cover
- every single class.
-
* Documentation! The README is obviously not enought to show how to use Predis
as it does not cover all of its features.
-
-* Missing tests for commands:
- PUBLISH, SUBSCRIBE, UNSUBSCRIBE, PSUBSCRIBE, PUNSUBSCRIBE, DEBUG, OBJECT,
- CLIENT, CONFIG GET, CONFIG SET, CONFIG RESETSTAT, SLOWLOG, SCRIPT, PTTL,
- PSETEX, PEXPIRE, PEXPIREAT, INCRBYFLOAT, HINCRBYFLOAT
@@ -0,0 +1,237 @@
+#!/usr/bin/env php
+<?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.
+ */
+
+use Predis\Commands\ICommand;
+use Predis\Commands\IPrefixable;
+
+class CommandTestCaseGenerator
+{
+ private $options;
+
+ public function __construct(Array $options)
+ {
+ if (!isset($options['class'])) {
+ throw new RuntimeException("Missing 'class' option.");
+ }
+ $this->options = $options;
+ }
+
+ public static function fromCommandLine()
+ {
+ $parameters = array(
+ 'c:' => 'class:',
+ 'r::' => 'realm::',
+ 'o::' => 'output::',
+ 'x::' => 'overwrite::'
+ );
+
+ $getops = getopt(implode(array_keys($parameters)), $parameters);
+
+ $options = array(
+ 'overwrite' => false,
+ 'tests' => __DIR__.'/../tests',
+ );
+
+ foreach ($getops as $option => $value) {
+ switch ($option) {
+ case 'c':
+ case 'class':
+ $options['class'] = $value;
+ break;
+
+ case 'r':
+ case 'realm':
+ $options['realm'] = $value;
+ break;
+
+ case 'o':
+ case 'output':
+ $options['output'] = $value;
+ break;
+
+ case 'x':
+ case 'overwrite':
+ $options['overwrite'] = true;
+ break;
+ }
+ }
+
+ if (!isset($options['class'])) {
+ throw new RuntimeException("Missing 'class' option.");
+ }
+
+ $options['fqn'] = "Predis\\Commands\\{$options['class']}";
+ $options['path'] = "Predis/Commands/{$options['class']}.php";
+
+ $source = __DIR__.'/../lib/'.$options['path'];
+ if (!file_exists($source)) {
+ throw new RuntimeException("Cannot find class file for {$options['fqn']} in $source.");
+ }
+
+ if (!isset($options['output'])) {
+ $options['output'] = sprintf("%s/%s", $options['tests'], str_replace('.php', 'Test.php', $options['path']));
+ }
+
+ return new self($options);
+ }
+
+ protected function getTestRealm()
+ {
+ if (isset($this->options['realm'])) {
+ if (!$this->options['realm']) {
+ throw new RuntimeException('Invalid value for realm has been sepcified (empty).');
+ }
+ return $this->options['realm'];
+ }
+
+ $class = array_pop(explode('\\', $this->options['fqn']));
+ list($realm,) = preg_split('/([[:upper:]][[:lower:]]+)/', $class, 2, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
+
+ return strtolower($realm);
+ }
+
+ public function generate()
+ {
+ $reflection = new ReflectionClass($class = $this->options['fqn']);
+
+ if (!$reflection->isInstantiable()) {
+ throw new RuntimeException("Class $class must be instantiable, abstract classes or interfaces are not allowed.");
+ }
+ if (!$reflection->implementsInterface('Predis\Commands\ICommand')) {
+ throw new RuntimeException("Class $class must implement the Predis\Commands\ICommand interface.");
+ }
+
+ $instance = $reflection->newInstance();
+ $buffer = $this->getTestCaseBuffer($instance);
+
+ return $buffer;
+ }
+
+ public function save()
+ {
+ $options = $this->options;
+ if (file_exists($options['output']) && !$options['overwrite']) {
+ throw new RuntimeException("File {$options['output']} already exist. Specify the --overwrite option to overwrite the existing file.");
+ }
+ file_put_contents($options['output'], $this->generate());
+ }
+
+ protected function getTestCaseBuffer(ICommand $instance)
+ {
+ $id = $instance->getId();
+ $fqn = get_class($instance);
+ $class = array_pop(explode('\\', $fqn)) . "Test";
+ $realm = $this->getTestRealm();
+
+ $buffer =<<<PHP
+<?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\Commands;
+
+use \PHPUnit_Framework_TestCase as StandardTestCase;
+
+/**
+ * @group commands
+ * @group realm-$realm
+ */
+class $class extends CommandTestCase
+{
+ /**
+ * {@inheritdoc}
+ */
+ protected function getExpectedCommand()
+ {
+ return '$fqn';
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ protected function getExpectedId()
+ {
+ return '$id';
+ }
+
+ /**
+ * @group disconnected
+ */
+ public function testFilterArguments()
+ {
+ \$this->markTestIncomplete('This test has not been implemented yet.');
+
+ \$arguments = array(/* add arguments */);
+ \$expected = array(/* add arguments */);
+
+ \$command = \$this->getCommand();
+ \$command->setArguments(\$arguments);
+
+ \$this->assertSame(\$expected, \$command->getArguments());
+ }
+
+ /**
+ * @group disconnected
+ */
+ public function testParseResponse()
+ {
+ \$this->markTestIncomplete('This test has not been implemented yet.');
+
+ \$raw = null;
+ \$expected = null;
+
+ \$command = \$this->getCommand();
+
+ \$this->assertSame(\$expected, \$command->parseResponse(\$raw));
+ }
+
+PHP;
+
+ if ($instance instanceof IPrefixable) {
+ $buffer .=<<<PHP
+
+ /**
+ * @group disconnected
+ */
+ public function testPrefixKeys()
+ {
+ \$this->markTestIncomplete('This test has not been implemented yet.');
+
+ \$arguments = array(/* add arguments */);
+ \$expected = array(/* add arguments */);
+
+ \$command = \$this->getCommandWithArgumentsArray(\$arguments);
+ \$command->prefixKeys('prefix:');
+
+ \$this->assertSame(\$expected, \$command->getArguments());
+ }
+
+PHP;
+ }
+
+ return "$buffer}\n";
+ }
+}
+
+// ------------------------------------------------------------------------- //
+
+require __DIR__.'/../autoload.php';
+
+$generator = CommandTestCaseGenerator::fromCommandLine();
+$generator->save();
@@ -20,7 +20,7 @@
class IncrementExistingKey extends ScriptedCommand
{
- protected function keysCount()
+ public function getKeysCount()
{
return 1;
}
@@ -52,11 +52,6 @@ public function autoload($className)
$relativeClassName = substr($className, strlen($this->prefix));
$classNameParts = explode('\\', $relativeClassName);
- $path = $this->baseDir .
- DIRECTORY_SEPARATOR .
- implode(DIRECTORY_SEPARATOR, $classNameParts) .
- '.php';
-
- require_once $path;
+ require_once $this->baseDir.DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $classNameParts).'.php';
}
}
View
@@ -191,11 +191,9 @@ public function getConnection($id = null)
{
if (isset($id)) {
if (!Helpers::isCluster($this->connection)) {
- throw new ClientException(
- 'Retrieving connections by alias is supported only with clustered connections'
- );
+ $message = 'Retrieving connections by alias is supported only with clustered connections';
+ throw new NotSupportedException($message);
}
-
return $this->connection->getConnectionById($id);
}
@@ -34,12 +34,4 @@ protected function filterArguments(Array $arguments)
{
return Helpers::filterVariadicValues($arguments);
}
-
- /**
- * {@inheritdoc}
- */
- public function parseResponse($data)
- {
- return (bool) $data;
- }
}
@@ -14,6 +14,7 @@
/**
* @link http://redis.io/commands/keys
* @author Daniele Alessandri <suppakilla@gmail.com>
+ * @deprecated
*/
class KeyKeysV12x extends KeyKeys
{
@@ -15,7 +15,7 @@
* @link http://redis.io/commands/randomkey
* @author Daniele Alessandri <suppakilla@gmail.com>
*/
-class KeyRandom extends PrefixableCommand
+class KeyRandom extends Command
{
/**
* {@inheritdoc}
Oops, something went wrong.

0 comments on commit 371ac91

Please sign in to comment.