Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[HttpKernel] RedisProfilerStorage - Fix falling unit tests when Redis extension is not available #4164

Merged
merged 1 commit into from

3 participants

@pulzarraider

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
Todo: -

Fix error of my PR #4150

Unit tests were falling if Redis extension was not available. It was caused by using Redis constants.

@fabpot fabpot referenced this pull request from a commit
@fabpot fabpot merged branch pulzarraider/redis_const_profiler_fix (PR #4164)
Commits
-------

991474b [HttpKernel] RedisProfilerStorage - Fix falling unit tests when Redis extension is not available

Discussion
----------

[HttpKernel] RedisProfilerStorage - Fix falling unit tests when Redis extension is not available

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
Todo: -

Fix error of my PR #4150

Unit tests were falling if Redis extension was not available. It was caused by using Redis constants.
cbf16fe
@fabpot fabpot merged commit 991474b into from
@jakzal
Collaborator

Wouldn't it be better to disable the tests if extension is not present (since the class cannot be used in such environment anyway)? This is how it's done in NativeRedisSessionHandler tests.

@pulzarraider

NativeRedisSessionHandler is a bit different. Unfortunately, it will be very complicated to simulate its functionality without Redis extension.

But in ProfilerStorage is situation easier. Redis/Memcache(d) are used here only to store data with basic methods. This can be simulated with simple mock objects. I changed Redis/Memcache(d) storages this way to be testable without presence of these specific extensions. It makes testing faster (if you have those extensions) and it may help developers extending and changing ProfilerStorage in the future easier even if they don't have those extensions or no access to redis/memcache server.

@mmucklo mmucklo referenced this pull request from a commit
@fabpot fabpot merged branch pulzarraider/redis_const_profiler_fix (PR #4164)
Commits
-------

991474b [HttpKernel] RedisProfilerStorage - Fix falling unit tests when Redis extension is not available

Discussion
----------

[HttpKernel] RedisProfilerStorage - Fix falling unit tests when Redis extension is not available

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: -
Todo: -

Fix error of my PR #4150

Unit tests were falling if Redis extension was not available. It was caused by using Redis constants.
00d43c6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 30, 2012
  1. @pulzarraider
This page is out of date. Refresh to see the latest.
Showing with 16 additions and 11 deletions.
  1. +16 −11 src/Symfony/Component/HttpKernel/Profiler/RedisProfilerStorage.php
View
27 src/Symfony/Component/HttpKernel/Profiler/RedisProfilerStorage.php
@@ -22,6 +22,11 @@ class RedisProfilerStorage implements ProfilerStorageInterface
{
const TOKEN_PREFIX = 'sf_profiler_';
+ const REDIS_OPT_SERIALIZER = 1;
+ const REDIS_OPT_PREFIX = 2;
+ const REDIS_SERIALIZER_NONE = 0;
+ const REDIS_SERIALIZER_PHP = 1;
+
protected $dsn;
protected $lifetime;
@@ -51,7 +56,7 @@ public function find($ip, $url, $limit, $method)
{
$indexName = $this->getIndexName();
- if (!$indexContent = $this->getValue($indexName, Redis::SERIALIZER_NONE)) {
+ if (!$indexContent = $this->getValue($indexName, self::REDIS_SERIALIZER_NONE)) {
return array();
}
@@ -103,7 +108,7 @@ public function purge()
// delete only items from index
$indexName = $this->getIndexName();
- $indexContent = $this->getValue($indexName, Redis::SERIALIZER_NONE);
+ $indexContent = $this->getValue($indexName, self::REDIS_SERIALIZER_NONE);
if (!$indexContent) {
return false;
@@ -137,7 +142,7 @@ public function read($token)
return false;
}
- $profile = $this->getValue($this->getItemName($token), Redis::SERIALIZER_PHP);
+ $profile = $this->getValue($this->getItemName($token), self::REDIS_SERIALIZER_PHP);
if (false !== $profile) {
$profile = $this->createProfileFromData($token, $profile);
@@ -162,7 +167,7 @@ public function write(Profile $profile)
'time' => $profile->getTime(),
);
- if ($this->setValue($this->getItemName($profile->getToken()), $data, $this->lifetime, Redis::SERIALIZER_PHP)) {
+ if ($this->setValue($this->getItemName($profile->getToken()), $data, $this->lifetime, self::REDIS_SERIALIZER_PHP)) {
// Add to index
$indexName = $this->getIndexName();
@@ -203,7 +208,7 @@ protected function getRedis()
$redis = new Redis;
$redis->connect($host, $port);
- $redis->setOption(Redis::OPT_PREFIX, self::TOKEN_PREFIX);
+ $redis->setOption(self::REDIS_OPT_PREFIX, self::TOKEN_PREFIX);
$this->redis = $redis;
}
@@ -243,7 +248,7 @@ private function createProfileFromData($token, $data, $parent = null)
continue;
}
- if (!$childProfileData = $this->getValue($this->getItemName($token), Redis::SERIALIZER_PHP)) {
+ if (!$childProfileData = $this->getValue($this->getItemName($token), self::REDIS_SERIALIZER_PHP)) {
continue;
}
@@ -306,10 +311,10 @@ private function isItemNameValid($name)
*
* @return mixed
*/
- private function getValue($key, $serializer = Redis::SERIALIZER_NONE)
+ private function getValue($key, $serializer = self::REDIS_SERIALIZER_NONE)
{
$redis = $this->getRedis();
- $redis->setOption(Redis::OPT_SERIALIZER, $serializer);
+ $redis->setOption(self::REDIS_OPT_SERIALIZER, $serializer);
return $redis->get($key);
}
@@ -324,10 +329,10 @@ private function getValue($key, $serializer = Redis::SERIALIZER_NONE)
*
* @return Boolean
*/
- private function setValue($key, $value, $expiration = 0, $serializer = Redis::SERIALIZER_NONE)
+ private function setValue($key, $value, $expiration = 0, $serializer = self::REDIS_SERIALIZER_NONE)
{
$redis = $this->getRedis();
- $redis->setOption(Redis::OPT_SERIALIZER, $serializer);
+ $redis->setOption(self::REDIS_OPT_SERIALIZER, $serializer);
return $redis->setex($key, $expiration, $value);
}
@@ -344,7 +349,7 @@ private function setValue($key, $value, $expiration = 0, $serializer = Redis::SE
private function appendValue($key, $value, $expiration = 0)
{
$redis = $this->getRedis();
- $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_NONE);
+ $redis->setOption(self::REDIS_OPT_SERIALIZER, self::REDIS_SERIALIZER_NONE);
if ($redis->exists($key)) {
$redis->append($key, $value);
Something went wrong with that request. Please try again.