Browse Source

Reorganize the Predis\Profile namespace.

The profile factory code has been extrapolated into a the new class
Predis\Profile\Factory (final and with only static methods).
Daniele Alessandri 11 years ago
parent
commit
2a5483df90
57 changed files with 642 additions and 636 deletions
  1. 3 0
      CHANGELOG.md
  2. 10 11
      README.md
  3. 0 1
      examples/MasterSlaveReplicationComplex.php
  4. 0 1
      lib/Predis/Client.php
  5. 4 3
      lib/Predis/ClientInterface.php
  6. 6 7
      lib/Predis/Configuration/ProfileOption.php
  7. 6 7
      lib/Predis/Connection/ConnectionFactory.php
  8. 3 3
      lib/Predis/Pipeline/Atomic.php
  9. 97 0
      lib/Predis/Profile/Factory.php
  10. 11 11
      lib/Predis/Profile/ProfileInterface.php
  11. 146 0
      lib/Predis/Profile/RedisProfile.php
  12. 1 1
      lib/Predis/Profile/RedisUnstable.php
  13. 1 1
      lib/Predis/Profile/RedisVersion120.php
  14. 1 1
      lib/Predis/Profile/RedisVersion200.php
  15. 1 1
      lib/Predis/Profile/RedisVersion220.php
  16. 1 1
      lib/Predis/Profile/RedisVersion240.php
  17. 1 1
      lib/Predis/Profile/RedisVersion260.php
  18. 1 1
      lib/Predis/Profile/RedisVersion280.php
  19. 0 228
      lib/Predis/Profile/ServerProfile.php
  20. 3 4
      tests/PHPUnit/CommandTestCase.php
  21. 4 4
      tests/PHPUnit/ConnectionTestCase.php
  22. 45 63
      tests/PHPUnit/RedisProfileTestCase.php
  23. 0 77
      tests/PHPUnit/ServerVersionTestCase.php
  24. 12 12
      tests/Predis/ClientTest.php
  25. 11 11
      tests/Predis/Cluster/PredisStrategyTest.php
  26. 12 12
      tests/Predis/Cluster/RedisStrategyTest.php
  27. 15 15
      tests/Predis/Collection/Iterator/HashKeyTest.php
  28. 15 15
      tests/Predis/Collection/Iterator/KeyspaceTest.php
  29. 9 9
      tests/Predis/Collection/Iterator/ListKeyTest.php
  30. 15 15
      tests/Predis/Collection/Iterator/SetKeyTest.php
  31. 15 15
      tests/Predis/Collection/Iterator/SortedSetKeyTest.php
  32. 4 4
      tests/Predis/Configuration/OptionsTest.php
  33. 15 15
      tests/Predis/Configuration/ProfileOptionTest.php
  34. 0 2
      tests/Predis/Connection/ComposableStreamConnectionTest.php
  35. 4 4
      tests/Predis/Connection/ConnectionFactoryTest.php
  36. 18 18
      tests/Predis/Connection/MasterSlaveReplicationTest.php
  37. 0 2
      tests/Predis/Connection/PhpiredisConnectionTest.php
  38. 0 2
      tests/Predis/Connection/PhpiredisStreamConnectionTest.php
  39. 7 7
      tests/Predis/Connection/PredisClusterTest.php
  40. 10 10
      tests/Predis/Connection/RedisClusterTest.php
  41. 0 2
      tests/Predis/Connection/StreamConnectionTest.php
  42. 3 3
      tests/Predis/Connection/WebdisConnectionTest.php
  43. 3 3
      tests/Predis/Monitor/ConsumerTest.php
  44. 3 3
      tests/Predis/Pipeline/FireAndForgetTest.php
  45. 2 2
      tests/Predis/Pipeline/PipelineTest.php
  46. 97 0
      tests/Predis/Profile/FactoryTest.php
  47. 2 2
      tests/Predis/Profile/RedisUnstableTest.php
  48. 2 2
      tests/Predis/Profile/RedisVersion120Test.php
  49. 2 2
      tests/Predis/Profile/RedisVersion200Test.php
  50. 2 2
      tests/Predis/Profile/RedisVersion220Test.php
  51. 2 2
      tests/Predis/Profile/RedisVersion240Test.php
  52. 2 2
      tests/Predis/Profile/RedisVersion260Test.php
  53. 2 2
      tests/Predis/Profile/RedisVersion280Test.php
  54. 4 4
      tests/Predis/PubSub/ConsumerTest.php
  55. 0 1
      tests/Predis/PubSub/DispatcherLoopTest.php
  56. 8 8
      tests/Predis/Replication/ReplicationStrategyTest.php
  57. 1 1
      tests/bootstrap.php

+ 3 - 0
CHANGELOG.md

@@ -43,6 +43,9 @@ v0.9.0 (201x-xx-xx)
   have been moved in the new `Predis\Response` namespace and most of them have
   been renamed to make their fully-qualified name shorter and less redundant.
 
+- The profile factory code has been extrapolated from the abstract Redis profile
+  class and it's now in `Predis\Profile\Factory`.
+
 
 v0.8.5 (2013-xx-xx)
 ===============================================================================

+ 10 - 11
README.md

@@ -16,7 +16,7 @@ More details are available on the [official wiki](http://wiki.github.com/nrk/pre
 
 ## Main features ##
 
-- Wide range of Redis versions supported (from __1.2__ to __2.8__ and unstable) using server profiles.
+- Wide range of Redis versions supported (from __1.2__ to __2.8__ and unstable) using profiles.
 - Smart support for [redis-cluster](http://redis.io/topics/cluster-spec) (Redis >= 3.0).
 - Client-side sharding via consistent hashing or custom distribution strategies.
 - Support for master / slave replication configurations (write on master, read from slaves).
@@ -28,7 +28,7 @@ More details are available on the [official wiki](http://wiki.github.com/nrk/pre
 - Connections to Redis instances are lazily established upon the first call to a command by the client.
 - Ability to connect to Redis using TCP/IP or UNIX domain sockets with support for persistent connections.
 - Ability to specify alternative connection classes to use different types of network or protocol backends.
-- Flexible system to define and register your own set of commands or server profiles to client instances.
+- Flexible system to define and register your own set of commands or profiles to client instances.
 
 
 ## How to use Predis ##
@@ -178,11 +178,10 @@ $redis->newcmd();
 ### Abstraction for handling Lua scripts as plain Redis commands ###
 
 A scripted command in Predis is an abstraction for [Lua scripting](http://redis.io/commands/eval)
-with Redis >= 2.6 that allows to use a Lua script as if it was a plain Redis command registered
-in the server profile being used by the client instance. Internally, scripted commands use
-[EVALSHA](http://redis.io/commands/evalsha) to refer to a Lua script by its SHA1 hash in order
-to save bandwidth, but they are capable of falling back to [EVAL](http://redis.io/commands/eval)
-when needed:
+in Redis >= 2.6 allowing to use a Lua script as if it was a Redis command registered in the profile
+used by the client. Internally scripted commands use [EVALSHA](http://redis.io/commands/evalsha) to
+refer to a Lua script by its SHA1 hash in order to save bandwidth, but they are capable of falling
+back to [EVAL](http://redis.io/commands/eval) when needed:
 
 ```php
 class ListPushRandomValue extends Predis\Command\ScriptedCommand
@@ -220,10 +219,10 @@ Predis has a comprehensive test suite covering every aspect of the library. The
 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 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 `REDIS_SERVER_VERSION` to `dev` in
-the `phpunit.xml` file. More details on testing Predis can be found in [the tests README](tests/README.md).
+suite is configured to execute integration tests using the 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 `REDIS_SERVER_VERSION` to `dev` in the `phpunit.xml`
+file. More details on testing Predis can be found in [the tests README](tests/README.md).
 
 Predis uses Travis CI for continuous integration. You can find the results of the test suite and the build
 history [on its project page](http://travis-ci.org/nrk/predis).

+ 0 - 1
examples/MasterSlaveReplicationComplex.php

@@ -20,7 +20,6 @@ require 'SharedConfigurations.php';
 
 use Predis\Command\ScriptedCommand;
 use Predis\Connection\MasterSlaveReplication;
-use Predis\Profile\ServerProfile;
 use Predis\Replication\ReplicationStrategy;
 
 // ------------------------------------------------------------------------- //

+ 0 - 1
lib/Predis/Client.php

@@ -22,7 +22,6 @@ use Predis\Connection\ConnectionInterface;
 use Predis\Connection\ConnectionParametersInterface;
 use Predis\Monitor;
 use Predis\Pipeline;
-use Predis\Profile\ServerProfile;
 use Predis\PubSub;
 use Predis\Response;
 use Predis\Transaction;

+ 4 - 3
lib/Predis/ClientInterface.php

@@ -11,9 +11,10 @@
 
 namespace Predis;
 
+use Predis\Command\CommandInterface;
 use Predis\Configuration\OptionsInterface;
 use Predis\Connection\ConnectionInterface;
-use Predis\Profile\ServerProfileInterface;
+use Predis\Profile\ProfileInterface;
 
 /**
  * Interface defining the most important parts needed to create an
@@ -27,7 +28,7 @@ interface ClientInterface extends BasicClientInterface
     /**
      * Returns the server profile used by the client.
      *
-     * @return ServerProfileInterface
+     * @return ProfileInterface
      */
     public function getProfile();
 
@@ -60,7 +61,7 @@ interface ClientInterface extends BasicClientInterface
      *
      * @param string $method The name of a Redis command.
      * @param array $arguments The arguments for the command.
-     * @return Command\CommandInterface
+     * @return CommandInterface
      */
     public function createCommand($method, $arguments = array());
 }

+ 6 - 7
lib/Predis/Configuration/ProfileOption.php

@@ -12,8 +12,7 @@
 namespace Predis\Configuration;
 
 use InvalidArgumentException;
-use Predis\Profile\ServerProfile;
-use Predis\Profile\ServerProfileInterface;
+use Predis\Profile;
 
 /**
  * Configures the server profile to be used by the client
@@ -28,9 +27,9 @@ class ProfileOption implements OptionInterface
      * Sets the needed commands processors that should be applied to the profile.
      *
      * @param OptionsInterface $options Client options.
-     * @param ServerProfileInterface $profile Server profile.
+     * @param Profile\ProfileInterface $profile Server profile.
      */
-    protected function setProcessors(OptionsInterface $options, ServerProfileInterface $profile)
+    protected function setProcessors(OptionsInterface $options, Profile\ProfileInterface $profile)
     {
         if (isset($options->prefix)) {
             $profile->setProcessor($options->prefix);
@@ -43,9 +42,9 @@ class ProfileOption implements OptionInterface
     public function filter(OptionsInterface $options, $value)
     {
         if (is_string($value)) {
-            $value = ServerProfile::get($value);
+            $value = Profile\Factory::get($value);
             $this->setProcessors($options, $value);
-        } else if (!$value instanceof ServerProfileInterface) {
+        } else if (!$value instanceof Profile\ProfileInterface) {
             throw new InvalidArgumentException('Invalid value for the profile option');
         }
 
@@ -57,7 +56,7 @@ class ProfileOption implements OptionInterface
      */
     public function getDefault(OptionsInterface $options)
     {
-        $profile = ServerProfile::getDefault();
+        $profile = Profile\Factory::getDefault();
         $this->setProcessors($options, $profile);
 
         return $profile;

+ 6 - 7
lib/Predis/Connection/ConnectionFactory.php

@@ -11,8 +11,7 @@
 
 namespace Predis\Connection;
 
-use Predis\Profile\ServerProfile;
-use Predis\Profile\ServerProfileInterface;
+use Predis\Profile;
 
 /**
  * Provides a default factory for Redis connections that maps URI schemes
@@ -28,9 +27,9 @@ class ConnectionFactory implements ConnectionFactoryInterface
     /**
      * Initializes a new instance of the default connection factory class used by Predis.
      *
-     * @param ServerProfileInterface $profile Server profile used to initialize new connections.
+     * @param Profile\ProfileInterface $profile Server profile used to initialize new connections.
      */
-    public function __construct(ServerProfileInterface $profile = null)
+    public function __construct(Profile\ProfileInterface $profile = null)
     {
         $this->schemes = $this->getDefaultSchemes();
         $this->profile = $profile;
@@ -160,9 +159,9 @@ class ConnectionFactory implements ConnectionFactoryInterface
     /**
      * Sets the server profile used to create initialization commands for connections.
      *
-     * @param ServerProfileInterface $profile Server profile instance.
+     * @param Profile\ProfileInterface $profile Server profile instance.
      */
-    public function setProfile(ServerProfileInterface $profile)
+    public function setProfile(Profile\ProfileInterface $profile)
     {
         $this->profile = $profile;
     }
@@ -170,7 +169,7 @@ class ConnectionFactory implements ConnectionFactoryInterface
     /**
      * Returns the server profile used to create initialization commands for connections.
      *
-     * @return ServerProfileInterface
+     * @return Profile\ProfileInterface
      */
     public function getProfile()
     {

+ 3 - 3
lib/Predis/Pipeline/Atomic.php

@@ -15,7 +15,7 @@ use SplQueue;
 use Predis\ClientException;
 use Predis\Connection\ConnectionInterface;
 use Predis\Connection\SingleConnectionInterface;
-use Predis\Profile\ServerProfileInterface;
+use Predis\Profile;
 use Predis\Response;
 
 /**
@@ -89,9 +89,9 @@ class Atomic extends Pipeline
      * Verifies all the needed preconditions before executing the pipeline.
      *
      * @param ConnectionInterface $connection Connection instance.
-     * @param ServerProfileInterface $profile Server profile.
+     * @param Profile\ProfileInterface $profile Server profile.
      */
-    protected function check(ConnectionInterface $connection, ServerProfileInterface $profile)
+    protected function check(ConnectionInterface $connection, Profile\ProfileInterface $profile)
     {
         if (!$connection instanceof SingleConnectionInterface) {
             $class = __CLASS__;

+ 97 - 0
lib/Predis/Profile/Factory.php

@@ -0,0 +1,97 @@
+<?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\Profile;
+
+use InvalidArgumentException;
+use ReflectionClass;
+use Predis\ClientException;
+
+/**
+ * Base class that implements common functionalities of server profiles.
+ *
+ * @author Daniele Alessandri <suppakilla@gmail.com>
+ */
+final class Factory
+{
+    private static $profiles = array(
+        '1.2'     => 'Predis\Profile\RedisVersion120',
+        '2.0'     => 'Predis\Profile\RedisVersion200',
+        '2.2'     => 'Predis\Profile\RedisVersion220',
+        '2.4'     => 'Predis\Profile\RedisVersion240',
+        '2.6'     => 'Predis\Profile\RedisVersion260',
+        '2.8'     => 'Predis\Profile\RedisVersion280',
+        'default' => 'Predis\Profile\RedisVersion280',
+        'dev'     => 'Predis\Profile\RedisUnstable',
+    );
+
+    /**
+     *
+     */
+    private function __construct()
+    {
+        // NOOP
+    }
+
+    /**
+     * Returns the default server profile.
+     *
+     * @return ProfileInterface
+     */
+    public static function getDefault()
+    {
+        return self::get('default');
+    }
+
+    /**
+     * Returns the development server profile.
+     *
+     * @return ProfileInterface
+     */
+    public static function getDevelopment()
+    {
+        return self::get('dev');
+    }
+
+    /**
+     * Registers a new server profile.
+     *
+     * @param string $alias Profile version or alias.
+     * @param string $profileClass FQN of a class implementing Predis\Profile\ProfileInterface.
+     */
+    public static function define($alias, $profileClass)
+    {
+        $reflection = new ReflectionClass($profileClass);
+
+        if (!$reflection->isSubclassOf('Predis\Profile\ProfileInterface')) {
+            throw new InvalidArgumentException("Cannot register '$profileClass' as it is not a valid profile class");
+        }
+
+        self::$profiles[$alias] = $profileClass;
+    }
+
+    /**
+     * Returns the specified server profile.
+     *
+     * @param string $version Profile version or alias.
+     * @return ProfileInterface
+     */
+    public static function get($version)
+    {
+        if (!isset(self::$profiles[$version])) {
+            throw new ClientException("Unknown server profile: $version");
+        }
+
+        $profile = self::$profiles[$version];
+
+        return new $profile();
+    }
+}

+ 11 - 11
lib/Predis/Profile/ServerProfileInterface.php → lib/Predis/Profile/ProfileInterface.php

@@ -14,16 +14,16 @@ namespace Predis\Profile;
 use Predis\Command\CommandInterface;
 
 /**
- * A server profile defines features and commands supported by certain
- * versions of Redis. Instances of Predis\Client should use a server
- * profile matching the version of Redis in use.
+ * A profile defines all the features and commands supported by certain versions
+ * of Redis. Instances of Predis\Client should use a server profile matching the
+ * version of Redis being used.
  *
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
-interface ServerProfileInterface
+interface ProfileInterface
 {
     /**
-     * Gets a profile version corresponding to a Redis version.
+     * Returns the profile version corresponding to the Redis version.
      *
      * @return string
      */
@@ -32,25 +32,25 @@ interface ServerProfileInterface
     /**
      * Checks if the profile supports the specified command.
      *
-     * @param string $command Command ID.
+     * @param string $commandID Command ID.
      * @return Boolean
      */
-    public function supportsCommand($command);
+    public function supportsCommand($commandID);
 
     /**
      * Checks if the profile supports the specified list of commands.
      *
-     * @param array $commands List of command IDs.
+     * @param array $commandIDs List of command IDs.
      * @return string
      */
-    public function supportsCommands(array $commands);
+    public function supportsCommands(array $commandIDs);
 
     /**
      * Creates a new command instance.
      *
-     * @param string $method Command ID.
+     * @param string $commandID Command ID.
      * @param array $arguments Arguments for the command.
      * @return CommandInterface
      */
-    public function createCommand($method, $arguments = array());
+    public function createCommand($commandID, $arguments = array());
 }

+ 146 - 0
lib/Predis/Profile/RedisProfile.php

@@ -0,0 +1,146 @@
+<?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\Profile;
+
+use InvalidArgumentException;
+use ReflectionClass;
+use Predis\ClientException;
+use Predis\Command\Processor\CommandProcessingInterface;
+use Predis\Command\Processor\CommandProcessorInterface;
+
+/**
+ * Base class that implements common functionalities of server profiles.
+ *
+ * @author Daniele Alessandri <suppakilla@gmail.com>
+ */
+abstract class RedisProfile implements ProfileInterface, CommandProcessingInterface
+{
+    private $commands;
+    private $processor;
+
+    /**
+     *
+     */
+    public function __construct()
+    {
+        $this->commands = $this->getSupportedCommands();
+    }
+
+    /**
+     * Returns a map of all the commands supported by the profile and their
+     * actual PHP classes.
+     *
+     * @return array
+     */
+    protected abstract function getSupportedCommands();
+
+    /**
+     * {@inheritdoc}
+     */
+    public function supportsCommand($commandID)
+    {
+        return isset($this->commands[strtolower($commandID)]);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function supportsCommands(array $commandIDs)
+    {
+        foreach ($commandIDs as $commandID) {
+            if (!$this->supportsCommand($commandID)) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    /**
+     * Returns the FQN of the class that represent the specified command ID
+     * registered in the current server profile.
+     *
+     * @param string $commandID Command ID.
+     * @return string
+     */
+    public function getCommandClass($commandID)
+    {
+        if (isset($this->commands[$commandID = strtolower($commandID)])) {
+            return $this->commands[$commandID];
+        }
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function createCommand($commandID, $arguments = array())
+    {
+        $commandID = strtolower($commandID);
+
+        if (!isset($this->commands[$commandID])) {
+            throw new ClientException("'$commandID' is not a registered Redis command");
+        }
+
+        $commandClass = $this->commands[$commandID];
+        $command = new $commandClass();
+        $command->setArguments($arguments);
+
+        if (isset($this->processor)) {
+            $this->processor->process($command);
+        }
+
+        return $command;
+    }
+
+    /**
+     * Defines a new commands in the server profile.
+     *
+     * @param string $commandID Command ID.
+     * @param string $commandClass FQN of a class implementing Predis\Command\CommandInterface.
+     */
+    public function defineCommand($commandID, $commandClass)
+    {
+        $reflection = new ReflectionClass($commandClass);
+
+        if (!$reflection->isSubclassOf('Predis\Command\CommandInterface')) {
+            throw new InvalidArgumentException("Cannot register '$commandClass' as it is not a valid Redis command");
+        }
+
+        $this->commands[strtolower($commandID)] = $commandClass;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function setProcessor(CommandProcessorInterface $processor = null)
+    {
+        $this->processor = $processor;
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function getProcessor()
+    {
+        return $this->processor;
+    }
+
+    /**
+     * Returns the version of server profile as its string representation.
+     *
+     * @return string
+     */
+    public function __toString()
+    {
+        return $this->getVersion();
+    }
+}

+ 1 - 1
lib/Predis/Profile/ServerVersionNext.php → lib/Predis/Profile/RedisUnstable.php

@@ -16,7 +16,7 @@ namespace Predis\Profile;
  *
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
-class ServerVersionNext extends ServerVersion28
+class RedisUnstable extends RedisVersion280
 {
     /**
      * {@inheritdoc}

+ 1 - 1
lib/Predis/Profile/ServerVersion12.php → lib/Predis/Profile/RedisVersion120.php

@@ -16,7 +16,7 @@ namespace Predis\Profile;
  *
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
-class ServerVersion12 extends ServerProfile
+class RedisVersion120 extends RedisProfile
 {
     /**
      * {@inheritdoc}

+ 1 - 1
lib/Predis/Profile/ServerVersion20.php → lib/Predis/Profile/RedisVersion200.php

@@ -16,7 +16,7 @@ namespace Predis\Profile;
  *
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
-class ServerVersion20 extends ServerProfile
+class RedisVersion200 extends RedisProfile
 {
     /**
      * {@inheritdoc}

+ 1 - 1
lib/Predis/Profile/ServerVersion22.php → lib/Predis/Profile/RedisVersion220.php

@@ -16,7 +16,7 @@ namespace Predis\Profile;
  *
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
-class ServerVersion22 extends ServerProfile
+class RedisVersion220 extends RedisProfile
 {
     /**
      * {@inheritdoc}

+ 1 - 1
lib/Predis/Profile/ServerVersion24.php → lib/Predis/Profile/RedisVersion240.php

@@ -16,7 +16,7 @@ namespace Predis\Profile;
  *
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
-class ServerVersion24 extends ServerProfile
+class RedisVersion240 extends RedisProfile
 {
     /**
      * {@inheritdoc}

+ 1 - 1
lib/Predis/Profile/ServerVersion26.php → lib/Predis/Profile/RedisVersion260.php

@@ -16,7 +16,7 @@ namespace Predis\Profile;
  *
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
-class ServerVersion26 extends ServerProfile
+class RedisVersion260 extends RedisProfile
 {
     /**
      * {@inheritdoc}

+ 1 - 1
lib/Predis/Profile/ServerVersion28.php → lib/Predis/Profile/RedisVersion280.php

@@ -16,7 +16,7 @@ namespace Predis\Profile;
  *
  * @author Daniele Alessandri <suppakilla@gmail.com>
  */
-class ServerVersion28 extends ServerProfile
+class RedisVersion280 extends RedisProfile
 {
     /**
      * {@inheritdoc}

+ 0 - 228
lib/Predis/Profile/ServerProfile.php

@@ -1,228 +0,0 @@
-<?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\Profile;
-
-use Predis\ClientException;
-use Predis\Command\Processor\CommandProcessingInterface;
-use Predis\Command\Processor\CommandProcessorInterface;
-
-/**
- * Base class that implements common functionalities of server profiles.
- *
- * @author Daniele Alessandri <suppakilla@gmail.com>
- */
-abstract class ServerProfile implements ServerProfileInterface, CommandProcessingInterface
-{
-    private static $profiles;
-
-    private $commands;
-    private $processor;
-
-    /**
-     *
-     */
-    public function __construct()
-    {
-        $this->commands = $this->getSupportedCommands();
-    }
-
-    /**
-     * Returns a map of all the commands supported by the profile and their
-     * actual PHP classes.
-     *
-     * @return array
-     */
-    protected abstract function getSupportedCommands();
-
-    /**
-     * Returns the default server profile.
-     *
-     * @return ServerProfileInterface
-     */
-    public static function getDefault()
-    {
-        return self::get('default');
-    }
-
-    /**
-     * Returns the development server profile.
-     *
-     * @return ServerProfileInterface
-     */
-    public static function getDevelopment()
-    {
-        return self::get('dev');
-    }
-
-    /**
-     * Returns a map of all the server profiles supported by default and their
-     * actual PHP classes.
-     *
-     * @return array
-     */
-    private static function getDefaultProfiles()
-    {
-        return array(
-            '1.2'     => 'Predis\Profile\ServerVersion12',
-            '2.0'     => 'Predis\Profile\ServerVersion20',
-            '2.2'     => 'Predis\Profile\ServerVersion22',
-            '2.4'     => 'Predis\Profile\ServerVersion24',
-            '2.6'     => 'Predis\Profile\ServerVersion26',
-            '2.8'     => 'Predis\Profile\ServerVersion28',
-            'default' => 'Predis\Profile\ServerVersion28',
-            'dev'     => 'Predis\Profile\ServerVersionNext',
-        );
-    }
-
-    /**
-     * Registers a new server profile.
-     *
-     * @param string $alias Profile version or alias.
-     * @param string $profileClass FQN of a class implementing Predis\Profile\ServerProfileInterface.
-     */
-    public static function define($alias, $profileClass)
-    {
-        if (!isset(self::$profiles)) {
-            self::$profiles = self::getDefaultProfiles();
-        }
-
-        $profileReflection = new \ReflectionClass($profileClass);
-
-        if (!$profileReflection->isSubclassOf('Predis\Profile\ServerProfileInterface')) {
-            throw new \InvalidArgumentException("Cannot register '$profileClass' as it is not a valid profile class");
-        }
-
-        self::$profiles[$alias] = $profileClass;
-    }
-
-    /**
-     * Returns the specified server profile.
-     *
-     * @param string $version Profile version or alias.
-     * @return ServerProfileInterface
-     */
-    public static function get($version)
-    {
-        if (!isset(self::$profiles)) {
-            self::$profiles = self::getDefaultProfiles();
-        }
-
-        if (!isset(self::$profiles[$version])) {
-            throw new ClientException("Unknown server profile: $version");
-        }
-
-        $profile = self::$profiles[$version];
-
-        return new $profile();
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function supportsCommands(array $commands)
-    {
-        foreach ($commands as $command) {
-            if (!$this->supportsCommand($command)) {
-                return false;
-            }
-        }
-
-        return true;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function supportsCommand($command)
-    {
-        return isset($this->commands[strtolower($command)]);
-    }
-
-    /**
-     * Returns the FQN of the class that represent the specified command ID
-     * registered in the current server profile.
-     *
-     * @param string $command Command ID.
-     * @return string
-     */
-    public function getCommandClass($command)
-    {
-        if (isset($this->commands[$command = strtolower($command)])) {
-            return $this->commands[$command];
-        }
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function createCommand($method, $arguments = array())
-    {
-        $method = strtolower($method);
-
-        if (!isset($this->commands[$method])) {
-            throw new ClientException("'$method' is not a registered Redis command");
-        }
-
-        $commandClass = $this->commands[$method];
-        $command = new $commandClass();
-        $command->setArguments($arguments);
-
-        if (isset($this->processor)) {
-            $this->processor->process($command);
-        }
-
-        return $command;
-    }
-
-    /**
-     * Defines a new commands in the server profile.
-     *
-     * @param string $alias Command ID.
-     * @param string $command FQN of a class implementing Predis\Command\CommandInterface.
-     */
-    public function defineCommand($alias, $command)
-    {
-        $commandReflection = new \ReflectionClass($command);
-
-        if (!$commandReflection->isSubclassOf('Predis\Command\CommandInterface')) {
-            throw new \InvalidArgumentException("Cannot register '$command' as it is not a valid Redis command");
-        }
-
-        $this->commands[strtolower($alias)] = $command;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function setProcessor(CommandProcessorInterface $processor = null)
-    {
-        $this->processor = $processor;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function getProcessor()
-    {
-        return $this->processor;
-    }
-
-    /**
-     * Returns the version of server profile as its string representation.
-     *
-     * @return string
-     */
-    public function __toString()
-    {
-        return $this->getVersion();
-    }
-}

+ 3 - 4
tests/PHPUnit/CommandTestCase.php

@@ -14,8 +14,7 @@ namespace Predis\Command;
 use PHPUnit_Framework_TestCase as StandardTestCase;
 
 use Predis\Client;
-use Predis\Profile\ServerProfile;
-use Predis\Profile\ServerProfileInterface;
+use Predis\Profile;
 
 /**
  *
@@ -51,11 +50,11 @@ abstract class CommandTestCase extends StandardTestCase
     /**
      * Return the server profile used during the tests.
      *
-     * @return ServerProfileInterface
+     * @return Profile\ProfileInterface
      */
     protected function getProfile()
     {
-        return ServerProfile::get(REDIS_SERVER_VERSION);
+        return Profile\Factory::get(REDIS_SERVER_VERSION);
     }
 
     /**

+ 4 - 4
tests/PHPUnit/ConnectionTestCase.php

@@ -13,7 +13,7 @@ namespace Predis\Connection;
 
 use PHPUnit_Framework_TestCase as StandardTestCase;
 
-use Predis\Profile\ServerProfile;
+use Predis\Profile;
 
 /**
  * @group realm-connection
@@ -340,17 +340,17 @@ abstract class ConnectionTestCase extends StandardTestCase
      * Returns a new instance of server profile.
      *
      * @param array $additional Additional connection parameters.
-     * @return ServerProfile
+     * @return Profile\ProfileInterface
      */
     protected function getProfile($version = null)
     {
-        return ServerProfile::get($version ?: REDIS_SERVER_VERSION);
+        return Profile\Factory::get($version ?: REDIS_SERVER_VERSION);
     }
 
     /**
      * Returns a new instance of a connection instance.
      *
-     * @param ServerProfile $profile Reference to the server profile instance.
+     * @param Profile\ProfileInterface $profile Reference to the server profile instance.
      * @param Boolean $initialize Push default initialization commands (SELECT and FLUSHDB).
      * @param array $parameters Additional connection parameters.
      * @return StreamConnection

+ 45 - 63
tests/Predis/Profile/ServerProfileTest.php → tests/PHPUnit/RedisProfileTestCase.php

@@ -18,81 +18,63 @@ use Predis\Command\Processor\ProcessorChain;
 /**
  *
  */
-class ServerProfileTest extends StandardTestCase
+abstract class RedisProfileTestCase extends StandardTestCase
 {
-    const DEFAULT_PROFILE_VERSION = '2.8';
-    const DEVELOPMENT_PROFILE_VERSION = '3.0';
-
     /**
-     * @group disconnected
+     * Returns a new instance of the tested profile.
+     *
+     * @return ProfileInterface
      */
-    public function testGetVersion()
-    {
-        $profile = ServerProfile::get('2.0');
-
-        $this->assertInstanceOf('Predis\Profile\ServerProfileInterface', $profile);
-        $this->assertEquals('2.0', $profile->getVersion());
-    }
+    protected abstract function getProfileInstance();
 
     /**
-     * @group disconnected
+     * Returns the expected version string for the tested profile.
+     *
+     * @return string Version string.
      */
-    public function testGetDefault()
-    {
-        $profile1 = ServerProfile::get(self::DEFAULT_PROFILE_VERSION);
-        $profile2 = ServerProfile::get('default');
-        $profile3 = ServerProfile::getDefault();
-
-        $this->assertInstanceOf('Predis\Profile\ServerProfileInterface', $profile1);
-        $this->assertInstanceOf('Predis\Profile\ServerProfileInterface', $profile2);
-        $this->assertInstanceOf('Predis\Profile\ServerProfileInterface', $profile3);
-        $this->assertEquals($profile1->getVersion(), $profile2->getVersion());
-        $this->assertEquals($profile2->getVersion(), $profile3->getVersion());
-    }
+    protected abstract function getExpectedVersion();
 
     /**
-     * @group disconnected
+     * Returns the expected list of commands supported by the tested profile.
+     *
+     * @return array List of supported commands.
      */
-    public function testGetDevelopment()
-    {
-        $profile1 = ServerProfile::get('dev');
-        $profile2 = ServerProfile::getDevelopment();
-
-        $this->assertInstanceOf('Predis\Profile\ServerProfileInterface', $profile1);
-        $this->assertInstanceOf('Predis\Profile\ServerProfileInterface', $profile2);
-        $this->assertEquals(self::DEVELOPMENT_PROFILE_VERSION, $profile2->getVersion());
-    }
+    protected abstract function getExpectedCommands();
 
     /**
-     * @group disconnected
-     * @expectedException Predis\ClientException
-     * @expectedExceptionMessage Unknown server profile: 1.0
+     * Returns the list of commands supported by the current
+     * server profile.
+     *
+     * @param ProfileInterface $profile Server profile instance.
+     * @return array
      */
-    public function testGetUndefinedProfile()
+    protected function getCommands(ProfileInterface $profile)
     {
-        ServerProfile::get('1.0');
+        $commands = $profile->getSupportedCommands();
+
+        return array_keys($commands);
     }
 
     /**
      * @group disconnected
      */
-    public function testDefineProfile()
+    public function testGetVersion()
     {
-        $profileClass = get_class($this->getMock('Predis\Profile\ServerProfileInterface'));
-
-        ServerProfile::define('mock', $profileClass);
+        $profile = $this->getProfileInstance();
 
-        $this->assertInstanceOf($profileClass, ServerProfile::get('mock'));
+        $this->assertEquals($this->getExpectedVersion(), $profile->getVersion());
     }
 
     /**
      * @group disconnected
-     * @expectedException InvalidArgumentException
-     * @expectedExceptionMessage Cannot register 'stdClass' as it is not a valid profile class
      */
-    public function testDefineInvalidProfile()
+    public function testSupportedCommands()
     {
-        ServerProfile::define('bogus', 'stdClass');
+        $profile = $this->getProfileInstance();
+        $expected = $this->getExpectedCommands();
+        $commands = $this->getCommands($profile);
+
+        $this->assertSame($expected, $commands);
     }
 
     /**
@@ -100,7 +82,7 @@ class ServerProfileTest extends StandardTestCase
      */
     public function testToString()
     {
-        $this->assertEquals('2.0', (string) ServerProfile::get('2.0'));
+        $this->assertEquals($this->getExpectedVersion(), $this->getProfileInstance());
     }
 
     /**
@@ -108,7 +90,7 @@ class ServerProfileTest extends StandardTestCase
      */
     public function testSupportCommand()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = $this->getProfileInstance();
 
         $this->assertTrue($profile->supportsCommand('info'));
         $this->assertTrue($profile->supportsCommand('INFO'));
@@ -122,7 +104,7 @@ class ServerProfileTest extends StandardTestCase
      */
     public function testSupportCommands()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = $this->getProfileInstance();
 
         $this->assertTrue($profile->supportsCommands(array('get', 'set')));
         $this->assertTrue($profile->supportsCommands(array('GET', 'SET')));
@@ -137,7 +119,7 @@ class ServerProfileTest extends StandardTestCase
      */
     public function testGetCommandClass()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = $this->getProfileInstance();
 
         $this->assertSame('Predis\Command\ConnectionPing', $profile->getCommandClass('ping'));
         $this->assertSame('Predis\Command\ConnectionPing', $profile->getCommandClass('PING'));
@@ -151,7 +133,7 @@ class ServerProfileTest extends StandardTestCase
      */
     public function testDefineCommand()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = $this->getProfileInstance();
         $command = $this->getMock('Predis\Command\CommandInterface');
 
         $profile->defineCommand('mock', get_class($command));
@@ -169,7 +151,7 @@ class ServerProfileTest extends StandardTestCase
      */
     public function testDefineInvalidCommand()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = $this->getProfileInstance();
 
         $profile->defineCommand('mock', 'stdClass');
     }
@@ -179,7 +161,7 @@ class ServerProfileTest extends StandardTestCase
      */
     public function testCreateCommandWithoutArguments()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = $this->getProfileInstance();
 
         $command = $profile->createCommand('info');
         $this->assertInstanceOf('Predis\Command\CommandInterface', $command);
@@ -192,7 +174,7 @@ class ServerProfileTest extends StandardTestCase
      */
     public function testCreateCommandWithArguments()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = $this->getProfileInstance();
         $arguments = array('foo', 'bar');
 
         $command = $profile->createCommand('set', $arguments);
@@ -208,7 +190,7 @@ class ServerProfileTest extends StandardTestCase
      */
     public function testCreateUndefinedCommand()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = $this->getProfileInstance();
         $profile->createCommand('unknown');
     }
 
@@ -217,7 +199,7 @@ class ServerProfileTest extends StandardTestCase
      */
     public function testGetDefaultProcessor()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = $this->getProfileInstance();
 
         $this->assertNull($profile->getProcessor());
     }
@@ -229,7 +211,7 @@ class ServerProfileTest extends StandardTestCase
     {
         $processor = $this->getMock('Predis\Command\Processor\CommandProcessorInterface');
 
-        $profile = ServerProfile::getDefault();
+        $profile = $this->getProfileInstance();
         $profile->setProcessor($processor);
 
         $this->assertSame($processor, $profile->getProcessor());
@@ -241,7 +223,7 @@ class ServerProfileTest extends StandardTestCase
     public function testSetAndUnsetProcessor()
     {
         $processor = $this->getMock('Predis\Command\Processor\CommandProcessorInterface');
-        $profile = ServerProfile::getDefault();
+        $profile = $this->getProfileInstance();
 
         $profile->setProcessor($processor);
         $this->assertSame($processor, $profile->getProcessor());
@@ -267,7 +249,7 @@ class ServerProfileTest extends StandardTestCase
                         $cmd->setRawArguments($argsRef = array_map('strtoupper', $cmd->getArguments()));
                     }));
 
-        $profile = ServerProfile::getDefault();
+        $profile = $this->getProfileInstance();
         $profile->setProcessor($processor);
         $command = $profile->createCommand('set', array('foo', 'bar'));
 
@@ -287,7 +269,7 @@ class ServerProfileTest extends StandardTestCase
         $chain->add($processor);
         $chain->add($processor);
 
-        $profile = ServerProfile::getDefault();
+        $profile = $this->getProfileInstance();
         $profile->setProcessor($chain);
         $profile->createCommand('info');
     }

+ 0 - 77
tests/PHPUnit/ServerVersionTestCase.php

@@ -1,77 +0,0 @@
-<?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\Profile;
-
-use PHPUnit_Framework_TestCase as StandardTestCase;
-
-/**
- *
- */
-abstract class ServerVersionTestCase extends StandardTestCase
-{
-    /**
-     * Returns a new instance of the tested profile.
-     *
-     * @return ServerProfileInterface
-     */
-    protected abstract function getProfileInstance();
-
-    /**
-     * Returns the expected version string for the tested profile.
-     *
-     * @return string Version string.
-     */
-    protected abstract function getExpectedVersion();
-
-    /**
-     * Returns the expected list of commands supported by the tested profile.
-     *
-     * @return array List of supported commands.
-     */
-    protected abstract function getExpectedCommands();
-
-    /**
-     * Returns the list of commands supported by the current
-     * server profile.
-     *
-     * @param ServerProfileInterface $profile Server profile instance.
-     * @return array
-     */
-    protected function getCommands(ServerProfileInterface $profile)
-    {
-        $commands = $profile->getSupportedCommands();
-
-        return array_keys($commands);
-    }
-
-    /**
-     * @group disconnected
-     */
-    public function testGetVersion()
-    {
-        $profile = $this->getProfileInstance();
-
-        $this->assertEquals($this->getExpectedVersion(), $profile->getVersion());
-    }
-
-    /**
-     * @group disconnected
-     */
-    public function testSupportedCommands()
-    {
-        $profile = $this->getProfileInstance();
-        $expected = $this->getExpectedCommands();
-        $commands = $this->getCommands($profile);
-
-        $this->assertSame($expected, $commands);
-    }
-}

+ 12 - 12
tests/Predis/ClientTest.php

@@ -16,7 +16,7 @@ use PHPUnit_Framework_TestCase as StandardTestCase;
 use Predis\Connection\ConnectionFactory;
 use Predis\Connection\MasterSlaveReplication;
 use Predis\Connection\PredisCluster;
-use Predis\Profile\ServerProfile;
+use Predis\Profile;
 use Predis\Response;
 
 /**
@@ -39,7 +39,7 @@ class ClientTest extends StandardTestCase
         $this->assertSame($parameters->port, 6379);
 
         $options = $client->getOptions();
-        $this->assertSame($options->profile->getVersion(), ServerProfile::getDefault()->getVersion());
+        $this->assertSame($options->profile->getVersion(), Profile\Factory::getDefault()->getVersion());
 
         $this->assertFalse($client->isConnected());
     }
@@ -59,7 +59,7 @@ class ClientTest extends StandardTestCase
         $this->assertSame($parameters->port, 6379);
 
         $options = $client->getOptions();
-        $this->assertSame($options->profile->getVersion(), ServerProfile::getDefault()->getVersion());
+        $this->assertSame($options->profile->getVersion(), Profile\Factory::getDefault()->getVersion());
 
         $this->assertFalse($client->isConnected());
     }
@@ -79,7 +79,7 @@ class ClientTest extends StandardTestCase
         $this->assertSame($parameters->port, 6379);
 
         $options = $client->getOptions();
-        $this->assertSame($options->profile->getVersion(), ServerProfile::getDefault()->getVersion());
+        $this->assertSame($options->profile->getVersion(), Profile\Factory::getDefault()->getVersion());
 
         $this->assertFalse($client->isConnected());
     }
@@ -245,7 +245,7 @@ class ClientTest extends StandardTestCase
         $client = new Client(null, $arg2);
 
         $profile = $client->getProfile();
-        $this->assertSame($profile->getVersion(), ServerProfile::get('2.0')->getVersion());
+        $this->assertSame($profile->getVersion(), Profile\Factory::get('2.0')->getVersion());
         $this->assertInstanceOf('Predis\Command\Processor\KeyPrefixProcessor', $profile->getProcessor());
         $this->assertSame('prefix:', $profile->getProcessor()->getPrefix());
     }
@@ -359,9 +359,9 @@ class ClientTest extends StandardTestCase
      */
     public function testCreatesNewCommandUsingSpecifiedProfile()
     {
-        $ping = ServerProfile::getDefault()->createCommand('ping', array());
+        $ping = Profile\Factory::getDefault()->createCommand('ping', array());
 
-        $profile = $this->getMock('Predis\Profile\ServerProfileInterface');
+        $profile = $this->getMock('Predis\Profile\ProfileInterface');
         $profile->expects($this->once())
                 ->method('createCommand')
                 ->with('ping', array())
@@ -376,7 +376,7 @@ class ClientTest extends StandardTestCase
      */
     public function testExecuteCommandReturnsParsedReplies()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = Profile\Factory::getDefault();
 
         $ping = $profile->createCommand('ping', array());
         $hgetall = $profile->createCommand('hgetall', array('metavars', 'foo', 'hoge'));
@@ -404,7 +404,7 @@ class ClientTest extends StandardTestCase
      */
     public function testExecuteCommandThrowsExceptionOnRedisError()
     {
-        $ping = ServerProfile::getDefault()->createCommand('ping', array());
+        $ping = Profile\Factory::getDefault()->createCommand('ping', array());
         $expectedResponse = new Response\Error('ERR Operation against a key holding the wrong kind of value');
 
         $connection= $this->getMock('Predis\Connection\ConnectionInterface');
@@ -421,7 +421,7 @@ class ClientTest extends StandardTestCase
      */
     public function testExecuteCommandReturnsErrorResponseOnRedisError()
     {
-        $ping = ServerProfile::getDefault()->createCommand('ping', array());
+        $ping = Profile\Factory::getDefault()->createCommand('ping', array());
         $expectedResponse = new Response\Error('ERR Operation against a key holding the wrong kind of value');
 
         $connection= $this->getMock('Predis\Connection\ConnectionInterface');
@@ -440,7 +440,7 @@ class ClientTest extends StandardTestCase
      */
     public function testCallingRedisCommandExecutesInstanceOfCommand()
     {
-        $ping = ServerProfile::getDefault()->createCommand('ping', array());
+        $ping = Profile\Factory::getDefault()->createCommand('ping', array());
 
         $connection = $this->getMock('Predis\Connection\ConnectionInterface');
         $connection->expects($this->once())
@@ -448,7 +448,7 @@ class ClientTest extends StandardTestCase
                    ->with($this->isInstanceOf('Predis\Command\ConnectionPing'))
                    ->will($this->returnValue('PONG'));
 
-        $profile = $this->getMock('Predis\Profile\ServerProfileInterface');
+        $profile = $this->getMock('Predis\Profile\ProfileInterface');
         $profile->expects($this->once())
                 ->method('createCommand')
                 ->with('ping', array())

+ 11 - 11
tests/Predis/Cluster/PredisStrategyTest.php

@@ -13,7 +13,7 @@ namespace Predis\Cluster;
 
 use PHPUnit_Framework_TestCase as StandardTestCase;
 
-use Predis\Profile\ServerProfile;
+use Predis\Profile;
 
 /**
  *
@@ -55,7 +55,7 @@ class PredisStrategyTest extends StandardTestCase
     public function testReturnsNullOnUnsupportedCommand()
     {
         $strategy = $this->getClusterStrategy();
-        $command = ServerProfile::getDevelopment()->createCommand('ping');
+        $command = Profile\Factory::getDevelopment()->createCommand('ping');
 
         $this->assertNull($strategy->getHash($command));
     }
@@ -66,7 +66,7 @@ class PredisStrategyTest extends StandardTestCase
     public function testFirstKeyCommands()
     {
         $strategy = $this->getClusterStrategy();
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
         $arguments = array('key');
 
         foreach ($this->getExpectedCommands('keys-first') as $commandID) {
@@ -81,7 +81,7 @@ class PredisStrategyTest extends StandardTestCase
     public function testAllKeysCommands()
     {
         $strategy = $this->getClusterStrategy();
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
         $arguments = array('{key}:1', '{key}:2', '{key}:3', '{key}:4');
 
         foreach ($this->getExpectedCommands('keys-all') as $commandID) {
@@ -96,7 +96,7 @@ class PredisStrategyTest extends StandardTestCase
     public function testInterleavedKeysCommands()
     {
         $strategy = $this->getClusterStrategy();
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
         $arguments = array('{key}:1', 'value1', '{key}:2', 'value2');
 
         foreach ($this->getExpectedCommands('keys-interleaved') as $commandID) {
@@ -111,7 +111,7 @@ class PredisStrategyTest extends StandardTestCase
     public function testKeysForBlockingListCommands()
     {
         $strategy = $this->getClusterStrategy();
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
         $arguments = array('{key}:1', '{key}:2', 10);
 
         foreach ($this->getExpectedCommands('keys-blockinglist') as $commandID) {
@@ -126,7 +126,7 @@ class PredisStrategyTest extends StandardTestCase
     public function testKeysForZsetAggregationCommands()
     {
         $strategy = $this->getClusterStrategy();
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
         $arguments = array('{key}:destination', 2, '{key}:1', '{key}:1', array('aggregate' => 'SUM'));
 
         foreach ($this->getExpectedCommands('keys-zaggregated') as $commandID) {
@@ -141,7 +141,7 @@ class PredisStrategyTest extends StandardTestCase
     public function testKeysForBitOpCommand()
     {
         $strategy = $this->getClusterStrategy();
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
         $arguments = array('AND', '{key}:destination', '{key}:src:1', '{key}:src:2');
 
         foreach ($this->getExpectedCommands('keys-bitop') as $commandID) {
@@ -156,7 +156,7 @@ class PredisStrategyTest extends StandardTestCase
     public function testKeysForScriptCommand()
     {
         $strategy = $this->getClusterStrategy();
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
         $arguments = array('%SCRIPT%', 2, '{key}:1', '{key}:2', 'value1', 'value2');
 
         foreach ($this->getExpectedCommands('keys-script') as $commandID) {
@@ -191,7 +191,7 @@ class PredisStrategyTest extends StandardTestCase
     public function testUnsettingCommandHandler()
     {
         $strategy = $this->getClusterStrategy();
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
 
         $strategy->setCommandHandler('set');
         $strategy->setCommandHandler('get', null);
@@ -209,7 +209,7 @@ class PredisStrategyTest extends StandardTestCase
     public function testSettingCustomCommandHandler()
     {
         $strategy = $this->getClusterStrategy();
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
 
         $callable = $this->getMock('stdClass', array('__invoke'));
         $callable->expects($this->once())

+ 12 - 12
tests/Predis/Cluster/RedisStrategyTest.php

@@ -13,7 +13,7 @@ namespace Predis\Cluster;
 
 use PHPUnit_Framework_TestCase as StandardTestCase;
 
-use Predis\Profile\ServerProfile;
+use Predis\Profile;
 
 /**
  *
@@ -49,7 +49,7 @@ class RedisStrategyTest extends StandardTestCase
     public function testReturnsNullOnUnsupportedCommand()
     {
         $strategy = $this->getClusterStrategy();
-        $command = ServerProfile::getDevelopment()->createCommand('ping');
+        $command = Profile\Factory::getDevelopment()->createCommand('ping');
 
         $this->assertNull($strategy->getHash($command));
     }
@@ -60,7 +60,7 @@ class RedisStrategyTest extends StandardTestCase
     public function testFirstKeyCommands()
     {
         $strategy = $this->getClusterStrategy();
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
         $arguments = array('key');
 
         foreach ($this->getExpectedCommands('keys-first') as $commandID) {
@@ -75,7 +75,7 @@ class RedisStrategyTest extends StandardTestCase
     public function testAllKeysCommandsWithOneKey()
     {
         $strategy = $this->getClusterStrategy();
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
         $arguments = array('key');
 
         foreach ($this->getExpectedCommands('keys-all') as $commandID) {
@@ -90,7 +90,7 @@ class RedisStrategyTest extends StandardTestCase
     public function testAllKeysCommandsWithMoreKeys()
     {
         $strategy = $this->getClusterStrategy();
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
         $arguments = array('key1', 'key2');
 
         foreach ($this->getExpectedCommands('keys-all') as $commandID) {
@@ -105,7 +105,7 @@ class RedisStrategyTest extends StandardTestCase
     public function testInterleavedKeysCommandsWithOneKey()
     {
         $strategy = $this->getClusterStrategy();
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
         $arguments = array('key:1', 'value1');
 
         foreach ($this->getExpectedCommands('keys-interleaved') as $commandID) {
@@ -120,7 +120,7 @@ class RedisStrategyTest extends StandardTestCase
     public function testInterleavedKeysCommandsWithMoreKeys()
     {
         $strategy = $this->getClusterStrategy();
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
         $arguments = array('key:1', 'value1', 'key:2', 'value2');
 
         foreach ($this->getExpectedCommands('keys-interleaved') as $commandID) {
@@ -135,7 +135,7 @@ class RedisStrategyTest extends StandardTestCase
     public function testKeysForBlockingListCommandsWithOneKey()
     {
         $strategy = $this->getClusterStrategy();
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
         $arguments = array('key:1', 10);
 
         foreach ($this->getExpectedCommands('keys-blockinglist') as $commandID) {
@@ -150,7 +150,7 @@ class RedisStrategyTest extends StandardTestCase
     public function testKeysForBlockingListCommandsWithMoreKeys()
     {
         $strategy = $this->getClusterStrategy();
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
         $arguments = array('key:1', 'key:2', 10);
 
         foreach ($this->getExpectedCommands('keys-blockinglist') as $commandID) {
@@ -165,7 +165,7 @@ class RedisStrategyTest extends StandardTestCase
     public function testKeysForScriptCommand()
     {
         $strategy = $this->getClusterStrategy();
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
         $arguments = array('%SCRIPT%', 1, 'key:1', 'value1');
 
         foreach ($this->getExpectedCommands('keys-script') as $commandID) {
@@ -200,7 +200,7 @@ class RedisStrategyTest extends StandardTestCase
     public function testUnsettingCommandHandler()
     {
         $strategy = $this->getClusterStrategy();
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
 
         $strategy->setCommandHandler('set');
         $strategy->setCommandHandler('get', null);
@@ -218,7 +218,7 @@ class RedisStrategyTest extends StandardTestCase
     public function testSettingCustomCommandHandler()
     {
         $strategy = $this->getClusterStrategy();
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
 
         $callable = $this->getMock('stdClass', array('__invoke'));
         $callable->expects($this->once())

+ 15 - 15
tests/Predis/Collection/Iterator/HashKeyTest.php

@@ -14,7 +14,7 @@ namespace Predis\Collection\Iterator;
 use PHPUnit_Framework_TestCase as StandardTestCase;
 
 use Predis\Client;
-use Predis\Profile\ServerProfile;
+use Predis\Profile;
 
 /**
  * @group realm-iterators
@@ -26,13 +26,13 @@ class HashKeyTest extends StandardTestCase
      * @expectedException Predis\NotSupportedException
      * @expectedExceptionMessage The specified server profile does not support the `HSCAN` command.
      */
-    public function testThrowsExceptionOnInvalidServerProfile()
+    public function testThrowsExceptionOnInvalidProfile()
     {
         $client = $this->getMock('Predis\ClientInterface');
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.0')));
+               ->will($this->returnValue(Profile\Factory::get('2.0')));
 
         $iterator = new HashKey($client, 'key:hash');
     }
@@ -46,7 +46,7 @@ class HashKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->once())
                ->method('hscan')
                ->with('key:hash', 0, array())
@@ -67,7 +67,7 @@ class HashKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->once())
                ->method('hscan')
                ->with('key:hash', 0, array())
@@ -105,7 +105,7 @@ class HashKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('hscan')
                ->with('key:hash', 0, array())
@@ -149,7 +149,7 @@ class HashKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('hscan')
                ->with('key:hash', 0, array())
@@ -186,7 +186,7 @@ class HashKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('hscan')
                ->with('key:hash', 0, array())
@@ -234,7 +234,7 @@ class HashKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('hscan')
                ->with('key:hash', 0, array('MATCH' => 'field:*'))
@@ -267,7 +267,7 @@ class HashKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('hscan')
                ->with('key:hash', 0, array('MATCH' => 'field:*'))
@@ -306,7 +306,7 @@ class HashKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('hscan')
                ->with('key:hash', 0, array('COUNT' => 2))
@@ -339,7 +339,7 @@ class HashKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('hscan')
                ->with('key:hash', 0, array('COUNT' => 1))
@@ -378,7 +378,7 @@ class HashKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('hscan')
                ->with('key:hash', 0, array('MATCH' => 'field:*', 'COUNT' => 2))
@@ -411,7 +411,7 @@ class HashKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('hscan')
                ->with('key:hash', 0, array('MATCH' => 'field:*', 'COUNT' => 1))
@@ -450,7 +450,7 @@ class HashKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->exactly(2))
                ->method('hscan')
                ->with('key:hash', 0, array())

+ 15 - 15
tests/Predis/Collection/Iterator/KeyspaceTest.php

@@ -14,7 +14,7 @@ namespace Predis\Collection\Iterator;
 use PHPUnit_Framework_TestCase as StandardTestCase;
 
 use Predis\Client;
-use Predis\Profile\ServerProfile;
+use Predis\Profile;
 
 /**
  * @group realm-iterators
@@ -26,13 +26,13 @@ class KeyspaceTest extends StandardTestCase
      * @expectedException Predis\NotSupportedException
      * @expectedExceptionMessage The specified server profile does not support the `SCAN` command.
      */
-    public function testThrowsExceptionOnInvalidServerProfile()
+    public function testThrowsExceptionOnInvalidProfile()
     {
         $client = $this->getMock('Predis\ClientInterface');
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.0')));
+               ->will($this->returnValue(Profile\Factory::get('2.0')));
 
         $iterator = new Keyspace($client);
     }
@@ -46,7 +46,7 @@ class KeyspaceTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->once())
                ->method('scan')
                ->with(0, array())
@@ -67,7 +67,7 @@ class KeyspaceTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->once())
                ->method('scan')
                ->with(0, array())
@@ -103,7 +103,7 @@ class KeyspaceTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('scan')
                ->with(0, array())
@@ -143,7 +143,7 @@ class KeyspaceTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('scan')
                ->with(0, array())
@@ -178,7 +178,7 @@ class KeyspaceTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('scan')
                ->with(0, array())
@@ -222,7 +222,7 @@ class KeyspaceTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('scan')
                ->with(0, array('MATCH' => 'key:*'))
@@ -253,7 +253,7 @@ class KeyspaceTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('scan')
                ->with(0, array('MATCH' => 'key:*'))
@@ -288,7 +288,7 @@ class KeyspaceTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('scan')
                ->with(0, array('COUNT' => 2))
@@ -319,7 +319,7 @@ class KeyspaceTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('scan')
                ->with(0, array('COUNT' => 1))
@@ -354,7 +354,7 @@ class KeyspaceTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('scan')
                ->with(0, array('MATCH' => 'key:*', 'COUNT' => 2))
@@ -385,7 +385,7 @@ class KeyspaceTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('scan')
                ->with(0, array('MATCH' => 'key:*', 'COUNT' => 1))
@@ -420,7 +420,7 @@ class KeyspaceTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->exactly(2))
                ->method('scan')
                ->with(0, array())

+ 9 - 9
tests/Predis/Collection/Iterator/ListKeyTest.php

@@ -14,7 +14,7 @@ namespace Predis\Collection\Iterator;
 use PHPUnit_Framework_TestCase as StandardTestCase;
 
 use Predis\Client;
-use Predis\Profile\ServerProfile;
+use Predis\Profile;
 
 /**
  * @group realm-iterators
@@ -30,7 +30,7 @@ class ListKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::getDefault()));
+               ->will($this->returnValue(Profile\Factory::getDefault()));
         $client->expects($this->once())
                ->method('lrange')
                ->with('key:list', 0, 9)
@@ -51,7 +51,7 @@ class ListKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::getDefault()));
+               ->will($this->returnValue(Profile\Factory::getDefault()));
         $client->expects($this->once())
                ->method('lrange')
                ->with('key:list', 0, 9)
@@ -87,7 +87,7 @@ class ListKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::getDefault()));
+               ->will($this->returnValue(Profile\Factory::getDefault()));
         $client->expects($this->at(1))
                ->method('lrange')
                ->with('key:list', 0, 9)
@@ -120,7 +120,7 @@ class ListKeyTest extends StandardTestCase
         $client = $this->getMock('Predis\ClientInterface');
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::getDefault()));
+               ->will($this->returnValue(Profile\Factory::getDefault()));
 
         $iterator = new ListKey($client, 'key:list', 'wrong');
     }
@@ -135,7 +135,7 @@ class ListKeyTest extends StandardTestCase
         $client = $this->getMock('Predis\ClientInterface');
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::getDefault()));
+               ->will($this->returnValue(Profile\Factory::getDefault()));
 
         $iterator = new ListKey($client, 'key:list', 'wrong');
     }
@@ -149,7 +149,7 @@ class ListKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::getDefault()));
+               ->will($this->returnValue(Profile\Factory::getDefault()));
         $client->expects($this->at(1))
                ->method('lrange')
                ->with('key:list', 0, 4)
@@ -180,7 +180,7 @@ class ListKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::getDefault()));
+               ->will($this->returnValue(Profile\Factory::getDefault()));
         $client->expects($this->at(1))
                ->method('lrange')
                ->with('key:list', 0, 1)
@@ -220,7 +220,7 @@ class ListKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::getDefault()));
+               ->will($this->returnValue(Profile\Factory::getDefault()));
         $client->expects($this->exactly(2))
                ->method('lrange')
                ->with('key:list', 0, 9)

+ 15 - 15
tests/Predis/Collection/Iterator/SetKeyTest.php

@@ -14,7 +14,7 @@ namespace Predis\Collection\Iterator;
 use PHPUnit_Framework_TestCase as StandardTestCase;
 
 use Predis\Client;
-use Predis\Profile\ServerProfile;
+use Predis\Profile;
 
 /**
  * @group realm-iterators
@@ -26,13 +26,13 @@ class SetKeyTest extends StandardTestCase
      * @expectedException Predis\NotSupportedException
      * @expectedExceptionMessage The specified server profile does not support the `SSCAN` command.
      */
-    public function testThrowsExceptionOnInvalidServerProfile()
+    public function testThrowsExceptionOnInvalidProfile()
     {
         $client = $this->getMock('Predis\ClientInterface');
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.0')));
+               ->will($this->returnValue(Profile\Factory::get('2.0')));
 
         $iterator = new SetKey($client, 'key:set');
     }
@@ -46,7 +46,7 @@ class SetKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->once())
                ->method('sscan')
                ->with('key:set', 0, array())
@@ -67,7 +67,7 @@ class SetKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->once())
                ->method('sscan')
                ->with('key:set', 0, array())
@@ -103,7 +103,7 @@ class SetKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('sscan')
                ->with('key:set', 0, array())
@@ -143,7 +143,7 @@ class SetKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('sscan')
                ->with('key:set', 0, array())
@@ -178,7 +178,7 @@ class SetKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('sscan')
                ->with('key:set', 0, array())
@@ -222,7 +222,7 @@ class SetKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('sscan')
                ->with('key:set', 0, array('MATCH' => 'member:*'))
@@ -253,7 +253,7 @@ class SetKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('sscan')
                ->with('key:set', 0, array('MATCH' => 'member:*'))
@@ -288,7 +288,7 @@ class SetKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('sscan')
                ->with('key:set', 0, array('COUNT' => 2))
@@ -319,7 +319,7 @@ class SetKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('sscan')
                ->with('key:set', 0, array('COUNT' => 1))
@@ -354,7 +354,7 @@ class SetKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('sscan')
                ->with('key:set', 0, array('MATCH' => 'member:*', 'COUNT' => 2))
@@ -385,7 +385,7 @@ class SetKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('sscan')
                ->with('key:set', 0, array('MATCH' => 'member:*', 'COUNT' => 1))
@@ -420,7 +420,7 @@ class SetKeyTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->exactly(2))
                ->method('sscan')
                ->with('key:set', 0, array())

+ 15 - 15
tests/Predis/Collection/Iterator/SortedSetKeyTest.php

@@ -14,7 +14,7 @@ namespace Predis\Collection\Iterator;
 use PHPUnit_Framework_TestCase as StandardTestCase;
 
 use Predis\Client;
-use Predis\Profile\ServerProfile;
+use Predis\Profile;
 
 /**
  * @group realm-iterators
@@ -26,13 +26,13 @@ class SortedSetTest extends StandardTestCase
      * @expectedException Predis\NotSupportedException
      * @expectedExceptionMessage The specified server profile does not support the `ZSCAN` command.
      */
-    public function testThrowsExceptionOnInvalidServerProfile()
+    public function testThrowsExceptionOnInvalidProfile()
     {
         $client = $this->getMock('Predis\ClientInterface');
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.0')));
+               ->will($this->returnValue(Profile\Factory::get('2.0')));
 
         $iterator = new SortedSetKey($client, 'key:zset');
     }
@@ -46,7 +46,7 @@ class SortedSetTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->once())
                ->method('zscan')
                ->with('key:zset', 0, array())
@@ -67,7 +67,7 @@ class SortedSetTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->once())
                ->method('zscan')
                ->with('key:zset', 0, array())
@@ -105,7 +105,7 @@ class SortedSetTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('zscan')
                ->with('key:zset', 0, array())
@@ -149,7 +149,7 @@ class SortedSetTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('zscan')
                ->with('key:zset', 0, array())
@@ -186,7 +186,7 @@ class SortedSetTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('zscan')
                ->with('key:zset', 0, array())
@@ -234,7 +234,7 @@ class SortedSetTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('zscan')
                ->with('key:zset', 0, array('MATCH' => 'member:*'))
@@ -267,7 +267,7 @@ class SortedSetTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('zscan')
                ->with('key:zset', 0, array('MATCH' => 'member:*'))
@@ -306,7 +306,7 @@ class SortedSetTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('zscan')
                ->with('key:zset', 0, array('COUNT' => 2))
@@ -339,7 +339,7 @@ class SortedSetTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('zscan')
                ->with('key:zset', 0, array('COUNT' => 1))
@@ -378,7 +378,7 @@ class SortedSetTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('zscan')
                ->with('key:zset', 0, array('MATCH' => 'member:*', 'COUNT' => 2))
@@ -411,7 +411,7 @@ class SortedSetTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->at(1))
                ->method('zscan')
                ->with('key:zset', 0, array('MATCH' => 'member:*', 'COUNT' => 1))
@@ -450,7 +450,7 @@ class SortedSetTest extends StandardTestCase
 
         $client->expects($this->any())
                ->method('getProfile')
-               ->will($this->returnValue(ServerProfile::get('2.8')));
+               ->will($this->returnValue(Profile\Factory::get('2.8')));
         $client->expects($this->exactly(2))
                ->method('zscan')
                ->with('key:zset', 0, array())

+ 4 - 4
tests/Predis/Configuration/OptionsTest.php

@@ -28,7 +28,7 @@ class OptionsTest extends StandardTestCase
         $options = new Options();
 
         $this->assertInstanceOf('Predis\Connection\ConnectionFactoryInterface', $options->connections);
-        $this->assertInstanceOf('Predis\Profile\ServerProfileInterface', $options->profile);
+        $this->assertInstanceOf('Predis\Profile\ProfileInterface', $options->profile);
         $this->assertInstanceOf('Predis\Connection\ClusterConnectionInterface', $options->cluster);
         $this->assertInstanceOf('Predis\Connection\ReplicationConnectionInterface', $options->replication);
         $this->assertTrue($options->exceptions);
@@ -50,7 +50,7 @@ class OptionsTest extends StandardTestCase
         ));
 
         $this->assertInternalType('bool', $options->exceptions);
-        $this->assertInstanceOf('Predis\Profile\ServerProfileInterface', $options->profile);
+        $this->assertInstanceOf('Predis\Profile\ProfileInterface', $options->profile);
         $this->assertInstanceOf('Predis\Command\Processor\CommandProcessorInterface', $options->prefix);
         $this->assertInstanceOf('Predis\Connection\ConnectionFactoryInterface', $options->connections);
         $this->assertInstanceOf('Predis\Connection\ClusterConnectionInterface', $options->cluster);
@@ -122,7 +122,7 @@ class OptionsTest extends StandardTestCase
     {
         $options = new Options();
 
-        $this->assertInstanceOf('Predis\Profile\ServerProfileInterface', $options->getDefault('profile'));
+        $this->assertInstanceOf('Predis\Profile\ProfileInterface', $options->getDefault('profile'));
     }
 
     /**
@@ -140,7 +140,7 @@ class OptionsTest extends StandardTestCase
      */
     public function testLazilyInitializesOptionValueUsingObjectWithInvokeMagicMethod()
     {
-        $profile = $this->getMock('Predis\Profile\ServerProfileInterface');
+        $profile = $this->getMock('Predis\Profile\ProfileInterface');
 
         // NOTE: closure values are covered by this test since they define __invoke().
         $callable = $this->getMock('stdClass', array('__invoke'));

+ 15 - 15
tests/Predis/Configuration/ProfileOptionTest.php

@@ -16,7 +16,7 @@ use PHPUnit_Framework_TestCase as StandardTestCase;
 use stdClass;
 
 use Predis\Command\Processor\KeyPrefixProcessor;
-use Predis\Profile\ServerProfile;
+use Predis\Profile;
 
 /**
  *
@@ -33,19 +33,19 @@ class ProfileOptionTest extends StandardTestCase
 
         $profile = $option->getDefault($options);
 
-        $this->assertInstanceOf('Predis\Profile\ServerProfileInterface', $profile);
-        $this->assertInstanceOf(get_class(ServerProfile::getDefault()), $profile);
+        $this->assertInstanceOf('Predis\Profile\ProfileInterface', $profile);
+        $this->assertInstanceOf(get_class(Profile\Factory::getDefault()), $profile);
         $this->assertNull($profile->getProcessor());
     }
 
     /**
      * @group disconnected
      */
-    public function testAcceptsServerProfileInstanceAsValue()
+    public function testAcceptsProfileInstanceAsValue()
     {
         $option = new ProfileOption();
         $options = $this->getMock('Predis\Configuration\OptionsInterface');
-        $value = ServerProfile::get('2.0');
+        $value = Profile\Factory::get('2.0');
 
         $profile = $option->filter($options, $value);
 
@@ -56,14 +56,14 @@ class ProfileOptionTest extends StandardTestCase
     /**
      * @group disconnected
      */
-    public function testAcceptsStringInterpretedAsServerProfileVersion()
+    public function testAcceptsStringInterpretedAsProfileVersion()
     {
         $option = new ProfileOption();
         $options = $this->getMock('Predis\Configuration\OptionsInterface');
 
         $profile = $option->filter($options, '2.0');
 
-        $this->assertInstanceOf('Predis\Profile\ServerProfileInterface', $profile);
+        $this->assertInstanceOf('Predis\Profile\ProfileInterface', $profile);
         $this->assertEquals('2.0', $profile->getVersion());
         $this->assertNull($profile->getProcessor());
     }
@@ -87,8 +87,8 @@ class ProfileOptionTest extends StandardTestCase
 
         $profile = $option->getDefault($options);
 
-        $this->assertInstanceOf('Predis\Profile\ServerProfileInterface', $profile);
-        $this->assertInstanceOf(get_class(ServerProfile::getDefault()), $profile);
+        $this->assertInstanceOf('Predis\Profile\ProfileInterface', $profile);
+        $this->assertInstanceOf(get_class(Profile\Factory::getDefault()), $profile);
 
         $this->assertInstanceOf('Predis\Command\Processor\KeyPrefixProcessor', $profile->getProcessor());
         $this->assertSame('prefix:', $profile->getProcessor()->getPrefix());
@@ -113,8 +113,8 @@ class ProfileOptionTest extends StandardTestCase
 
         $profile = $option->filter($options, '2.0');
 
-        $this->assertInstanceOf('Predis\Profile\ServerProfileInterface', $profile);
-        $this->assertInstanceOf(get_class(ServerProfile::get('2.0')), $profile);
+        $this->assertInstanceOf('Predis\Profile\ProfileInterface', $profile);
+        $this->assertInstanceOf(get_class(Profile\Factory::get('2.0')), $profile);
 
         $this->assertInstanceOf('Predis\Command\Processor\KeyPrefixProcessor', $profile->getProcessor());
         $this->assertSame('prefix:', $profile->getProcessor()->getPrefix());
@@ -123,19 +123,19 @@ class ProfileOptionTest extends StandardTestCase
     /**
      * @group disconnected
      */
-    public function testDoesNotApplyPrefixOnServerProfileValue()
+    public function testDoesNotApplyPrefixOnProfileValue()
     {
         $option = new ProfileOption();
         $options = $this->getMock('Predis\Configuration\OptionsInterface');
-        $value = ServerProfile::getDefault();
+        $value = Profile\Factory::getDefault();
 
         $options->expects($this->never())->method('__isset');
         $options->expects($this->never())->method('__get');
 
         $profile = $option->filter($options, $value);
 
-        $this->assertInstanceOf('Predis\Profile\ServerProfileInterface', $profile);
-        $this->assertInstanceOf(get_class(ServerProfile::getDefault()), $profile);
+        $this->assertInstanceOf('Predis\Profile\ProfileInterface', $profile);
+        $this->assertInstanceOf(get_class(Profile\Factory::getDefault()), $profile);
         $this->assertNull($profile->getProcessor());
     }
 

+ 0 - 2
tests/Predis/Connection/ComposableStreamConnectionTest.php

@@ -13,8 +13,6 @@ namespace Predis\Connection;
 
 use PHPUnit_Framework_TestCase as StandardTestCase;
 
-use Predis\Profile\ServerProfile;
-
 /**
  *
  */

+ 4 - 4
tests/Predis/Connection/ConnectionFactoryTest.php

@@ -113,7 +113,7 @@ class ConnectionFactoryTest extends StandardTestCase
      */
     public function testCreateConnectionWithoutInitializationCommands()
     {
-        $profile = $this->getMock('Predis\Profile\ServerProfileInterface');
+        $profile = $this->getMock('Predis\Profile\ProfileInterface');
         $profile->expects($this->never())->method('create');
 
         $factory = new ConnectionFactory($profile);
@@ -140,7 +140,7 @@ class ConnectionFactoryTest extends StandardTestCase
             return $command;
         };
 
-        $profile = $this->getMock('Predis\Profile\ServerProfileInterface');
+        $profile = $this->getMock('Predis\Profile\ProfileInterface');
         $profile->expects($this->exactly(2))
                 ->method('createCommand')
                 ->with($this->isType('string'), $this->isType('array'))
@@ -347,12 +347,12 @@ class ConnectionFactoryTest extends StandardTestCase
      * @group disconnected
      * @todo We might want to add a test for SingleConnectionInterface::pushInitCommand().
      */
-    public function testAggregatedConnectionWithServerProfileArgument()
+    public function testAggregatedConnectionWithProfileArgument()
     {
         list(, $connectionClass) = $this->getMockConnectionClass();
 
         $cluster = $this->getMock('Predis\Connection\ClusterConnectionInterface');
-        $profile = $this->getMock('Predis\Profile\ServerProfileInterface');
+        $profile = $this->getMock('Predis\Profile\ProfileInterface');
 
         $factory = $this->getMock('Predis\Connection\ConnectionFactory', array('create'), array($profile));
         $factory->expects($this->exactly(2))

+ 18 - 18
tests/Predis/Connection/MasterSlaveReplicationTest.php

@@ -13,7 +13,7 @@ namespace Predis\Connection;
 
 use PHPUnit_Framework_TestCase as StandardTestCase;
 
-use Predis\Profile\ServerProfile;
+use Predis\Profile;
 use Predis\Replication\ReplicationStrategy;
 
 /**
@@ -217,7 +217,7 @@ class MasterSlaveReplicationTest extends StandardTestCase
      */
     public function testUsesSlavesOnReadOnlyCommands()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = Profile\Factory::getDefault();
 
         $master = $this->getMockConnection('tcp://host1?alias=master');
         $slave1 = $this->getMockConnection('tcp://host2?alias=slave1');
@@ -238,7 +238,7 @@ class MasterSlaveReplicationTest extends StandardTestCase
      */
     public function testUsesMasterOnWriteCommands()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = Profile\Factory::getDefault();
 
         $master = $this->getMockConnection('tcp://host1?alias=master');
         $slave1 = $this->getMockConnection('tcp://host2?alias=slave1');
@@ -259,7 +259,7 @@ class MasterSlaveReplicationTest extends StandardTestCase
      */
     public function testSwitchesFromSlaveToMasterOnWriteCommands()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = Profile\Factory::getDefault();
 
         $master = $this->getMockConnection('tcp://host1?alias=master');
         $slave1 = $this->getMockConnection('tcp://host2?alias=slave1');
@@ -283,9 +283,9 @@ class MasterSlaveReplicationTest extends StandardTestCase
      */
     public function testWritesCommandToCorrectConnection()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = Profile\Factory::getDefault();
         $cmdExists = $profile->createCommand('exists', array('foo'));
-        $cmdSet = $profile->getDefault()->createCommand('set', array('foo', 'bar'));
+        $cmdSet = $profile->createCommand('set', array('foo', 'bar'));
 
         $master = $this->getMockConnection('tcp://host1?alias=master');
         $master->expects($this->once())->method('writeCommand')->with($cmdSet);
@@ -306,9 +306,9 @@ class MasterSlaveReplicationTest extends StandardTestCase
      */
     public function testReadsCommandFromCorrectConnection()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = Profile\Factory::getDefault();
         $cmdExists = $profile->createCommand('exists', array('foo'));
-        $cmdSet = $profile->getDefault()->createCommand('set', array('foo', 'bar'));
+        $cmdSet = $profile->createCommand('set', array('foo', 'bar'));
 
         $master = $this->getMockConnection('tcp://host1?alias=master');
         $master->expects($this->once())->method('readResponse')->with($cmdSet);
@@ -329,9 +329,9 @@ class MasterSlaveReplicationTest extends StandardTestCase
      */
     public function testExecutesCommandOnCorrectConnection()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = Profile\Factory::getDefault();
         $cmdExists = $profile->createCommand('exists', array('foo'));
-        $cmdSet = $profile->getDefault()->createCommand('set', array('foo', 'bar'));
+        $cmdSet = $profile->createCommand('set', array('foo', 'bar'));
 
         $master = $this->getMockConnection('tcp://host1?alias=master');
         $master->expects($this->once())->method('executeCommand')->with($cmdSet);
@@ -352,7 +352,7 @@ class MasterSlaveReplicationTest extends StandardTestCase
      */
     public function testWatchTriggersSwitchToMasterConnection()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = Profile\Factory::getDefault();
         $cmdWatch = $profile->createCommand('watch', array('foo'));
 
         $master = $this->getMockConnection('tcp://host1?alias=master');
@@ -373,7 +373,7 @@ class MasterSlaveReplicationTest extends StandardTestCase
      */
     public function testMultiTriggersSwitchToMasterConnection()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = Profile\Factory::getDefault();
         $cmdMulti = $profile->createCommand('multi');
 
         $master = $this->getMockConnection('tcp://host1?alias=master');
@@ -394,7 +394,7 @@ class MasterSlaveReplicationTest extends StandardTestCase
      */
     public function testEvalTriggersSwitchToMasterConnection()
     {
-        $profile = ServerProfile::get('dev');
+        $profile = Profile\Factory::get('dev');
         $cmdEval = $profile->createCommand('eval', array("return redis.call('info')"));
 
         $master = $this->getMockConnection('tcp://host1?alias=master');
@@ -415,7 +415,7 @@ class MasterSlaveReplicationTest extends StandardTestCase
      */
     public function testSortTriggersSwitchToMasterConnectionOnStoreModifier()
     {
-        $profile = ServerProfile::get('dev');
+        $profile = Profile\Factory::get('dev');
         $cmdSortNormal = $profile->createCommand('sort', array('key'));
         $cmdSortStore = $profile->createCommand('sort', array('key', array('store' => 'key:store')));
 
@@ -440,7 +440,7 @@ class MasterSlaveReplicationTest extends StandardTestCase
      */
     public function testThrowsExceptionOnNonSupportedCommand()
     {
-        $cmd = ServerProfile::getDefault()->createCommand('info');
+        $cmd = Profile\Factory::getDefault()->createCommand('info');
 
         $replication = new MasterSlaveReplication();
         $replication->add($this->getMockConnection('tcp://host1?alias=master'));
@@ -454,7 +454,7 @@ class MasterSlaveReplicationTest extends StandardTestCase
      */
     public function testCanOverrideReadOnlyFlagForCommands()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = Profile\Factory::getDefault();
         $cmdSet = $profile->createCommand('set', array('foo', 'bar'));
         $cmdGet = $profile->createCommand('get', array('foo'));
 
@@ -480,7 +480,7 @@ class MasterSlaveReplicationTest extends StandardTestCase
      */
     public function testAcceptsCallableToOverrideReadOnlyFlagForCommands()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = Profile\Factory::getDefault();
         $cmdExistsFoo = $profile->createCommand('exists', array('foo'));
         $cmdExistsBar = $profile->createCommand('exists', array('bar'));
 
@@ -508,7 +508,7 @@ class MasterSlaveReplicationTest extends StandardTestCase
      */
     public function testCanSetReadOnlyFlagForEvalScripts()
     {
-        $profile = ServerProfile::get('dev');
+        $profile = Profile\Factory::get('dev');
 
         $cmdEval = $profile->createCommand('eval', array($script = "return redis.call('info');"));
         $cmdEvalSha = $profile->createCommand('evalsha', array($scriptSHA1 = sha1($script)));

+ 0 - 2
tests/Predis/Connection/PhpiredisConnectionTest.php

@@ -13,8 +13,6 @@ namespace Predis\Connection;
 
 use PHPUnit_Framework_TestCase as StandardTestCase;
 
-use Predis\Profile\ServerProfile;
-
 /**
  * @group ext-phpiredis
  */

+ 0 - 2
tests/Predis/Connection/PhpiredisStreamConnectionTest.php

@@ -13,8 +13,6 @@ namespace Predis\Connection;
 
 use PHPUnit_Framework_TestCase as StandardTestCase;
 
-use Predis\Profile\ServerProfile;
-
 /**
  * @group ext-phpiredis
  */

+ 7 - 7
tests/Predis/Connection/PredisClusterTest.php

@@ -13,7 +13,7 @@ namespace Predis\Connection;
 
 use PHPUnit_Framework_TestCase as StandardTestCase;
 
-use Predis\Profile\ServerProfile;
+use Predis\Profile;
 
 /**
  *
@@ -224,7 +224,7 @@ class PredisClusterTest extends StandardTestCase
      */
     public function testReturnsCorrectConnectionUsingCommandInstance()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = Profile\Factory::getDefault();
 
         $connection1 = $this->getMockConnection('tcp://host1:7001');
         $connection2 = $this->getMockConnection('tcp://host1:7002');
@@ -261,7 +261,7 @@ class PredisClusterTest extends StandardTestCase
      */
     public function testThrowsExceptionOnNonShardableCommand()
     {
-        $ping = ServerProfile::getDefault()->createCommand('ping');
+        $ping = Profile\Factory::getDefault()->createCommand('ping');
 
         $cluster = new PredisCluster();
         $cluster->add($this->getMockConnection());
@@ -274,7 +274,7 @@ class PredisClusterTest extends StandardTestCase
      */
     public function testWritesCommandToCorrectConnection()
     {
-        $command = ServerProfile::getDefault()->createCommand('get', array('node01:5431'));
+        $command = Profile\Factory::getDefault()->createCommand('get', array('node01:5431'));
 
         $connection1 = $this->getMockConnection('tcp://host1:7001');
         $connection1->expects($this->once())->method('writeCommand')->with($command);
@@ -294,7 +294,7 @@ class PredisClusterTest extends StandardTestCase
      */
     public function testReadsCommandFromCorrectConnection()
     {
-        $command = ServerProfile::getDefault()->createCommand('get', array('node02:3212'));
+        $command = Profile\Factory::getDefault()->createCommand('get', array('node02:3212'));
 
         $connection1 = $this->getMockConnection('tcp://host1:7001');
         $connection1->expects($this->never())->method('readResponse');
@@ -314,7 +314,7 @@ class PredisClusterTest extends StandardTestCase
      */
     public function testExecutesCommandOnCorrectConnection()
     {
-        $command = ServerProfile::getDefault()->createCommand('get', array('node01:5431'));
+        $command = Profile\Factory::getDefault()->createCommand('get', array('node01:5431'));
 
         $connection1 = $this->getMockConnection('tcp://host1:7001');
         $connection1->expects($this->once())->method('executeCommand')->with($command);
@@ -334,7 +334,7 @@ class PredisClusterTest extends StandardTestCase
      */
     public function testExecuteCommandOnEachNode()
     {
-        $ping = ServerProfile::getDefault()->createCommand('ping', array());
+        $ping = Profile\Factory::getDefault()->createCommand('ping', array());
 
         $connection1 = $this->getMock('Predis\Connection\SingleConnectionInterface');
         $connection1->expects($this->once())

+ 10 - 10
tests/Predis/Connection/RedisClusterTest.php

@@ -13,7 +13,7 @@ namespace Predis\Connection;
 
 use PHPUnit_Framework_TestCase as StandardTestCase;
 
-use Predis\Profile\ServerProfile;
+use Predis\Profile;
 use Predis\Response;
 
 /**
@@ -326,7 +326,7 @@ class RedisClusterTest extends StandardTestCase
      */
     public function testReturnsCorrectConnectionUsingCommandInstance()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = Profile\Factory::getDefault();
 
         $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
         $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380');
@@ -358,7 +358,7 @@ class RedisClusterTest extends StandardTestCase
      */
     public function testWritesCommandToCorrectConnection()
     {
-        $command = ServerProfile::getDefault()->createCommand('get', array('node:1001'));
+        $command = Profile\Factory::getDefault()->createCommand('get', array('node:1001'));
 
         $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
         $connection1->expects($this->once())->method('writeCommand')->with($command);
@@ -378,7 +378,7 @@ class RedisClusterTest extends StandardTestCase
      */
     public function testReadsCommandFromCorrectConnection()
     {
-        $command = ServerProfile::getDefault()->createCommand('get', array('node:1050'));
+        $command = Profile\Factory::getDefault()->createCommand('get', array('node:1050'));
 
         $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
         $connection1->expects($this->never())->method('readResponse');
@@ -398,7 +398,7 @@ class RedisClusterTest extends StandardTestCase
      */
     public function testDoesNotSupportKeyTags()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = Profile\Factory::getDefault();
 
         $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
         $connection2 = $this->getMockConnection('tcp://127.0.0.1:6380');
@@ -425,7 +425,7 @@ class RedisClusterTest extends StandardTestCase
     {
         $askResponse = new Response\Error('ASK 1970 127.0.0.1:6380');
 
-        $command = ServerProfile::getDefault()->createCommand('get', array('node:1001'));
+        $command = Profile\Factory::getDefault()->createCommand('get', array('node:1001'));
 
         $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
         $connection1->expects($this->exactly(2))
@@ -458,7 +458,7 @@ class RedisClusterTest extends StandardTestCase
     {
         $askResponse = new Response\Error('ASK 1970 127.0.0.1:6381');
 
-        $command = ServerProfile::getDefault()->createCommand('get', array('node:1001'));
+        $command = Profile\Factory::getDefault()->createCommand('get', array('node:1001'));
 
         $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
         $connection1->expects($this->exactly(2))
@@ -498,7 +498,7 @@ class RedisClusterTest extends StandardTestCase
     {
         $movedResponse = new Response\Error('MOVED 1970 127.0.0.1:6380');
 
-        $command = ServerProfile::getDefault()->createCommand('get', array('node:1001'));
+        $command = Profile\Factory::getDefault()->createCommand('get', array('node:1001'));
 
         $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
         $connection1->expects($this->exactly(1))
@@ -532,7 +532,7 @@ class RedisClusterTest extends StandardTestCase
     {
         $movedResponse = new Response\Error('MOVED 1970 127.0.0.1:6381');
 
-        $command = ServerProfile::getDefault()->createCommand('get', array('node:1001'));
+        $command = Profile\Factory::getDefault()->createCommand('get', array('node:1001'));
 
         $connection1 = $this->getMockConnection('tcp://127.0.0.1:6379');
         $connection1->expects($this->once())
@@ -572,7 +572,7 @@ class RedisClusterTest extends StandardTestCase
      */
     public function testThrowsExceptionOnNonSupportedCommand()
     {
-        $ping = ServerProfile::getDefault()->createCommand('ping');
+        $ping = Profile\Factory::getDefault()->createCommand('ping');
 
         $cluster = new RedisCluster();
         $cluster->add($this->getMockConnection('tcp://127.0.0.1:6379'));

+ 0 - 2
tests/Predis/Connection/StreamConnectionTest.php

@@ -13,8 +13,6 @@ namespace Predis\Connection;
 
 use PHPUnit_Framework_TestCase as StandardTestCase;
 
-use Predis\Profile\ServerProfile;
-
 /**
  *
  */

+ 3 - 3
tests/Predis/Connection/WebdisConnectionTest.php

@@ -13,7 +13,7 @@ namespace Predis\Connection;
 
 use PHPUnit_Framework_TestCase as StandardTestCase;
 
-use Predis\Profile\ServerProfile;
+use Predis\Profile;
 
 /**
  * @group ext-curl
@@ -185,11 +185,11 @@ class WebdisConnectionTest extends StandardTestCase
      * Returns a new instance of server profile.
      *
      * @param array $additional Additional connection parameters.
-     * @return ServerProfile
+     * @return Profile\ProfileInterface
      */
     protected function getProfile($version = null)
     {
-        return ServerProfile::get($version ?: REDIS_SERVER_VERSION);
+        return Profile\Factory::get($version ?: REDIS_SERVER_VERSION);
     }
 
     /**

+ 3 - 3
tests/Predis/Monitor/ConsumerTest.php

@@ -14,7 +14,7 @@ namespace Predis\Monitor;
 use PHPUnit_Framework_TestCase as StandardTestCase;
 
 use Predis\Client;
-use Predis\Profile\ServerProfile;
+use Predis\Profile;
 use Predis\Monitor\Consumer as MonitorConsumer;
 
 /**
@@ -29,7 +29,7 @@ class ConsumerTest extends StandardTestCase
      */
     public function testMonitorConsumerRequireMonitorCommand()
     {
-        $profile = $this->getMock('Predis\Profile\ServerProfileInterface');
+        $profile = $this->getMock('Predis\Profile\ProfileInterface');
         $profile->expects($this->once())
                 ->method('supportsCommand')
                 ->with('monitor')
@@ -57,7 +57,7 @@ class ConsumerTest extends StandardTestCase
      */
     public function testConstructorStartsConsumer()
     {
-        $cmdMonitor = ServerProfile::getDefault()->createCommand('monitor');
+        $cmdMonitor = Profile\Factory::getDefault()->createCommand('monitor');
 
         $connection = $this->getMock('Predis\Connection\SingleConnectionInterface');
 

+ 3 - 3
tests/Predis/Pipeline/FireAndForgetTest.php

@@ -15,7 +15,7 @@ use PHPUnit_Framework_TestCase as StandardTestCase;
 
 use SplQueue;
 use Predis\Client;
-use Predis\Profile\ServerProfile;
+use Predis\Profile;
 
 /**
  *
@@ -27,7 +27,7 @@ class FireAndForgetTest extends StandardTestCase
      */
     public function testPipelineWithSingleConnection()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = Profile\Factory::getDefault();
 
         $connection = $this->getMock('Predis\Connection\SingleConnectionInterface');
         $connection->expects($this->exactly(3))->method('writeCommand');
@@ -47,7 +47,7 @@ class FireAndForgetTest extends StandardTestCase
      */
     public function testSwitchesToMasterWithReplicationConnection()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = Profile\Factory::getDefault();
 
         $connection = $this->getMock('Predis\Connection\ReplicationConnectionInterface');
         $connection->expects($this->once())

+ 2 - 2
tests/Predis/Pipeline/PipelineTest.php

@@ -15,7 +15,7 @@ use PHPUnit_Framework_TestCase as StandardTestCase;
 
 use Predis\Client;
 use Predis\ClientException;
-use Predis\Profile\ServerProfile;
+use Predis\Profile;
 use Predis\Response;
 
 /**
@@ -133,7 +133,7 @@ class PipelineTest extends StandardTestCase
      */
     public function testExecuteCommandDoesNotSendCommandsWithoutExecute()
     {
-        $profile = ServerProfile::getDefault();
+        $profile = Profile\Factory::getDefault();
 
         $connection = $this->getMock('Predis\Connection\SingleConnectionInterface');
         $connection->expects($this->never())->method('writeCommand');

+ 97 - 0
tests/Predis/Profile/FactoryTest.php

@@ -0,0 +1,97 @@
+<?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\Profile;
+
+use PHPUnit_Framework_TestCase as StandardTestCase;
+
+use Predis\Command\Processor\ProcessorChain;
+
+/**
+ *
+ */
+class FactoryTest extends StandardTestCase
+{
+    const DEFAULT_PROFILE_VERSION = '2.8';
+    const DEVELOPMENT_PROFILE_VERSION = '3.0';
+
+    /**
+     * @group disconnected
+     */
+    public function testGetVersion()
+    {
+        $profile = Factory::get('2.0');
+
+        $this->assertInstanceOf('Predis\Profile\ProfileInterface', $profile);
+        $this->assertEquals('2.0', $profile->getVersion());
+    }
+
+    /**
+     * @group disconnected
+     */
+    public function testGetDefault()
+    {
+        $profile1 = Factory::get(self::DEFAULT_PROFILE_VERSION);
+        $profile2 = Factory::get('default');
+        $profile3 = Factory::getDefault();
+
+        $this->assertInstanceOf('Predis\Profile\ProfileInterface', $profile1);
+        $this->assertInstanceOf('Predis\Profile\ProfileInterface', $profile2);
+        $this->assertInstanceOf('Predis\Profile\ProfileInterface', $profile3);
+        $this->assertEquals($profile1->getVersion(), $profile2->getVersion());
+        $this->assertEquals($profile2->getVersion(), $profile3->getVersion());
+    }
+
+    /**
+     * @group disconnected
+     */
+    public function testGetDevelopment()
+    {
+        $profile1 = Factory::get('dev');
+        $profile2 = Factory::getDevelopment();
+
+        $this->assertInstanceOf('Predis\Profile\ProfileInterface', $profile1);
+        $this->assertInstanceOf('Predis\Profile\ProfileInterface', $profile2);
+        $this->assertEquals(self::DEVELOPMENT_PROFILE_VERSION, $profile2->getVersion());
+    }
+
+    /**
+     * @group disconnected
+     * @expectedException Predis\ClientException
+     * @expectedExceptionMessage Unknown server profile: 1.0
+     */
+    public function testGetUndefinedProfile()
+    {
+        Factory::get('1.0');
+    }
+
+    /**
+     * @group disconnected
+     */
+    public function testDefineProfile()
+    {
+        $profileClass = get_class($this->getMock('Predis\Profile\ProfileInterface'));
+
+        Factory::define('mock', $profileClass);
+
+        $this->assertInstanceOf($profileClass, Factory::get('mock'));
+    }
+
+    /**
+     * @group disconnected
+     * @expectedException InvalidArgumentException
+     * @expectedExceptionMessage Cannot register 'stdClass' as it is not a valid profile class
+     */
+    public function testDefineInvalidProfile()
+    {
+        Factory::define('bogus', 'stdClass');
+    }
+}

+ 2 - 2
tests/Predis/Profile/ServerVersionNextTest.php → tests/Predis/Profile/RedisUnstableTest.php

@@ -14,14 +14,14 @@ namespace Predis\Profile;
 /**
  *
  */
-class ServerVersionNextTest extends ServerVersionTestCase
+class RedisUnstableTest extends RedisProfileTestCase
 {
     /**
      * {@inheritdoc}
      */
     public function getProfileInstance()
     {
-        return new ServerVersionNext();
+        return new RedisUnstable();
     }
 
     /**

+ 2 - 2
tests/Predis/Profile/ServerVersion12Test.php → tests/Predis/Profile/RedisVersion120Test.php

@@ -14,14 +14,14 @@ namespace Predis\Profile;
 /**
  *
  */
-class ServerVersion12Test extends ServerVersionTestCase
+class RedisVersion120Test extends RedisProfileTestCase
 {
     /**
      * {@inheritdoc}
      */
     public function getProfileInstance()
     {
-        return new ServerVersion12();
+        return new RedisVersion120();
     }
 
     /**

+ 2 - 2
tests/Predis/Profile/ServerVersion20Test.php → tests/Predis/Profile/RedisVersion200Test.php

@@ -14,14 +14,14 @@ namespace Predis\Profile;
 /**
  *
  */
-class ServerVersion20Test extends ServerVersionTestCase
+class RedisVersion200Test extends RedisProfileTestCase
 {
     /**
      * {@inheritdoc}
      */
     public function getProfileInstance()
     {
-        return new ServerVersion20();
+        return new RedisVersion200();
     }
 
     /**

+ 2 - 2
tests/Predis/Profile/ServerVersion22Test.php → tests/Predis/Profile/RedisVersion220Test.php

@@ -14,14 +14,14 @@ namespace Predis\Profile;
 /**
  *
  */
-class ServerVersion22Test extends ServerVersionTestCase
+class RedisVersion220Test extends RedisProfileTestCase
 {
     /**
      * {@inheritdoc}
      */
     public function getProfileInstance()
     {
-        return new ServerVersion22();
+        return new RedisVersion220();
     }
 
     /**

+ 2 - 2
tests/Predis/Profile/ServerVersion24Test.php → tests/Predis/Profile/RedisVersion240Test.php

@@ -14,14 +14,14 @@ namespace Predis\Profile;
 /**
  *
  */
-class ServerVersion24Test extends ServerVersionTestCase
+class RedisVersion240Test extends RedisProfileTestCase
 {
     /**
      * {@inheritdoc}
      */
     public function getProfileInstance()
     {
-        return new ServerVersion24();
+        return new RedisVersion240();
     }
 
     /**

+ 2 - 2
tests/Predis/Profile/ServerVersion26Test.php → tests/Predis/Profile/RedisVersion260Test.php

@@ -14,14 +14,14 @@ namespace Predis\Profile;
 /**
  *
  */
-class ServerVersion26Test extends ServerVersionTestCase
+class RedisVersion260Test extends RedisProfileTestCase
 {
     /**
      * {@inheritdoc}
      */
     public function getProfileInstance()
     {
-        return new ServerVersion26();
+        return new RedisVersion260();
     }
 
     /**

+ 2 - 2
tests/Predis/Profile/ServerVersion28Test.php → tests/Predis/Profile/RedisVersion280Test.php

@@ -14,14 +14,14 @@ namespace Predis\Profile;
 /**
  *
  */
-class ServerVersion28Test extends ServerVersionTestCase
+class RedisVersion280Test extends RedisProfileTestCase
 {
     /**
      * {@inheritdoc}
      */
     public function getProfileInstance()
     {
-        return new ServerVersion28();
+        return new RedisVersion280();
     }
 
     /**

+ 4 - 4
tests/Predis/PubSub/ConsumerTest.php

@@ -14,7 +14,7 @@ namespace Predis\PubSub;
 use PHPUnit_Framework_TestCase as StandardTestCase;
 
 use Predis\Client;
-use Predis\Profile\ServerProfile;
+use Predis\Profile;
 use Predis\PubSub\Consumer as PubSubConsumer;
 
 /**
@@ -29,7 +29,7 @@ class ConsumerTest extends StandardTestCase
      */
     public function testPubSubConsumerRequirePubSubRelatedCommand()
     {
-        $profile = $this->getMock('Predis\Profile\ServerProfileInterface');
+        $profile = $this->getMock('Predis\Profile\ProfileInterface');
         $profile->expects($this->any())
                 ->method('supportsCommands')
                 ->will($this->returnValue(false));
@@ -69,7 +69,7 @@ class ConsumerTest extends StandardTestCase
      */
     public function testConstructorWithSubscriptionsStartsConsumer()
     {
-        $profile = ServerProfile::get(REDIS_SERVER_VERSION);
+        $profile = Profile\Factory::get(REDIS_SERVER_VERSION);
 
         $cmdSubscribe = $profile->createCommand('subscribe', array('channel:foo'));
         $cmdPsubscribe = $profile->createCommand('psubscribe', array('channels:*'));
@@ -111,7 +111,7 @@ class ConsumerTest extends StandardTestCase
      */
     public function testStoppingConsumerWithFalseSendsUnsubscriptions()
     {
-        $profile = ServerProfile::get(REDIS_SERVER_VERSION);
+        $profile = Profile\Factory::get(REDIS_SERVER_VERSION);
         $classUnsubscribe = $profile->getCommandClass('unsubscribe');
         $classPunsubscribe = $profile->getCommandClass('punsubscribe');
 

+ 0 - 1
tests/Predis/PubSub/DispatcherLoopTest.php

@@ -14,7 +14,6 @@ namespace Predis\PubSub;
 use PHPUnit_Framework_TestCase as StandardTestCase;
 
 use Predis\Client;
-use Predis\Profile\ServerProfile;
 
 /**
  * @group realm-pubsub

+ 8 - 8
tests/Predis/Replication/ReplicationStrategyTest.php

@@ -14,7 +14,7 @@ namespace Predis\Replication;
 use PHPUnit_Framework_TestCase as StandardTestCase;
 
 use Predis\Command\CommandInterface;
-use Predis\Profile\ServerProfile;
+use Predis\Profile;
 
 /**
  *
@@ -26,7 +26,7 @@ class ReplicationStrategyTest extends StandardTestCase
      */
     public function testReadCommands()
     {
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
         $strategy = new ReplicationStrategy();
 
         foreach ($this->getExpectedCommands('read') as $commandId) {
@@ -40,7 +40,7 @@ class ReplicationStrategyTest extends StandardTestCase
      */
     public function testWriteCommands()
     {
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
         $strategy = new ReplicationStrategy();
 
         foreach ($this->getExpectedCommands('write') as $commandId) {
@@ -54,7 +54,7 @@ class ReplicationStrategyTest extends StandardTestCase
      */
     public function testDisallowedCommands()
     {
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
         $strategy = new ReplicationStrategy();
 
         foreach ($this->getExpectedCommands('disallowed') as $commandId) {
@@ -68,7 +68,7 @@ class ReplicationStrategyTest extends StandardTestCase
      */
     public function testSortCommand()
     {
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
         $strategy = new ReplicationStrategy();
 
         $cmdReadSort = $profile->createCommand('SORT', array('key:list'));
@@ -85,7 +85,7 @@ class ReplicationStrategyTest extends StandardTestCase
      */
     public function testUsingDisallowedCommandThrowsException()
     {
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
         $strategy = new ReplicationStrategy();
 
         $command = $profile->createCommand('INFO');
@@ -150,7 +150,7 @@ class ReplicationStrategyTest extends StandardTestCase
     public function testCanUseCallableToCheckCommand()
     {
         $strategy = new ReplicationStrategy();
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
 
         $strategy->setCommandReadOnly('SET', function ($command) {
             return $command->getArgument(1) === true;
@@ -169,7 +169,7 @@ class ReplicationStrategyTest extends StandardTestCase
     public function testSetLuaScriptAsReadOperation()
     {
         $strategy = new ReplicationStrategy();
-        $profile = ServerProfile::getDevelopment();
+        $profile = Profile\Factory::getDevelopment();
 
         $writeScript = 'redis.call("set", "foo", "bar")';
         $readScript = 'return true';

+ 1 - 1
tests/bootstrap.php

@@ -14,5 +14,5 @@ require __DIR__.'/../autoload.php';
 require __DIR__.'/PHPUnit/ArrayHasSameValuesConstraint.php';
 require __DIR__.'/PHPUnit/CommandTestCase.php';
 require __DIR__.'/PHPUnit/ConnectionTestCase.php';
-require __DIR__.'/PHPUnit/ServerVersionTestCase.php';
+require __DIR__.'/PHPUnit/RedisProfileTestCase.php';
 require __DIR__.'/PHPUnit/DistributorTestCase.php';