From 64c2ecd4d9e767360a638007f6f63ff6d36c5746 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 11 Aug 2016 13:20:56 -0700 Subject: [PATCH] CRM-19130 - Add test for regression in CRM_Core_BAO_Cache The earlier patch for CRM-19130 broke support for reading individual items from the SQL cache. Although the test-suite hits the cache layer a lot (e.g. CRM_Utils_Cache_SqlGroupTest), the bug wasn't exposed by other tests because (a) caches are replicated in-memory and in SQL (b) caches are often read in batch mode. This explicitly flushes the in-memory cache and reads the SQL cache. --- CRM/Utils/Cache.php | 4 +- tests/phpunit/CRM/Core/BAO/CacheTest.php | 50 ++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tests/phpunit/CRM/Core/BAO/CacheTest.php diff --git a/CRM/Utils/Cache.php b/CRM/Utils/Cache.php index 8c04a9e81a..9b093a88f7 100644 --- a/CRM/Utils/Cache.php +++ b/CRM/Utils/Cache.php @@ -36,12 +36,14 @@ */ class CRM_Utils_Cache { /** + * (Quasi-Private) Treat this as private. It is marked public to facilitate testing. + * * We only need one instance of this object. So we use the singleton * pattern and cache the instance in this variable * * @var object */ - static private $_singleton = NULL; + public static $_singleton = NULL; /** * Constructor. diff --git a/tests/phpunit/CRM/Core/BAO/CacheTest.php b/tests/phpunit/CRM/Core/BAO/CacheTest.php new file mode 100644 index 0000000000..dee3f60681 --- /dev/null +++ b/tests/phpunit/CRM/Core/BAO/CacheTest.php @@ -0,0 +1,50 @@ + 'def'); + CRM_Core_BAO_Cache::setItem($originalValue, __CLASS__, 'testSetGetItem'); + + $return_1 = CRM_Core_BAO_Cache::getItem(__CLASS__, 'testSetGetItem'); + $this->assertEquals($originalValue, $return_1); + + // Wipe out any in-memory copies of the cache. Check to see if the SQL + // read is correct. + + CRM_Core_BAO_Cache::$_cache = NULL; + CRM_Utils_Cache::$_singleton = NULL; + $return_2 = CRM_Core_BAO_Cache::getItem(__CLASS__, 'testSetGetItem'); + $this->assertEquals($originalValue, $return_2); + } + +} -- 2.25.1