diff --git a/phpBB/common.php b/phpBB/common.php
index fc6009eb21..7b6a407c94 100644
--- a/phpBB/common.php
+++ b/phpBB/common.php
@@ -206,9 +206,9 @@ $class_loader = new phpbb_class_loader($phpbb_root_path, '.' . $phpEx);
$class_loader->register();
// set up caching
-$acm = phpbb_cache_factory::create($acm_type)->get_acm();
-$class_loader->set_acm($acm);
-$cache = new phpbb_cache_service($acm);
+$cache_factory = new phpbb_cache_factory($acm_type);
+$class_loader->set_cache($cache_factory->get_driver());
+$cache = $cache_factory->get_service();
// Instantiate some basic classes
$request = new phpbb_request();
diff --git a/phpBB/download/file.php b/phpBB/download/file.php
index 74925fb447..a7e8b9f06c 100644
--- a/phpBB/download/file.php
+++ b/phpBB/download/file.php
@@ -54,9 +54,9 @@ if (isset($_GET['avatar']))
$class_loader->register();
// set up caching
- $acm = phpbb_cache_factory::create($acm_type)->get_acm();
- $class_loader->set_acm($acm);
- $cache = new phpbb_cache_service($acm);
+ $cache_factory = new phpbb_cache_factory($acm_type);
+ $class_loader->set_cache($cache_factory->get_driver());
+ $cache = $cache_factory->get_service();
$db = new $sql_db();
diff --git a/phpBB/includes/cache/factory.php b/phpBB/includes/cache/factory.php
index cc88780bf2..f38e19cbe6 100644
--- a/phpBB/includes/cache/factory.php
+++ b/phpBB/includes/cache/factory.php
@@ -22,31 +22,22 @@ if (!defined('IN_PHPBB'))
class phpbb_cache_factory
{
private $acm_type;
-
+
public function __construct($acm_type)
{
$this->acm_type = $acm_type;
}
-
- public function get_acm()
+
+ public function get_driver()
{
$class_name = 'phpbb_cache_driver_' . $this->acm_type;
return new $class_name();
}
-
+
public function get_service()
{
- $acm = $this->get_acm();
- $service = new phpbb_cache_service($acm);
+ $driver = $this->get_driver();
+ $service = new phpbb_cache_service($driver);
return $service;
}
-
- /**
- * for convenience to allow:
- * $cache = phpbb_cache_factory::create('file')->get_service();
- */
- public static function create($acm_type)
- {
- return new self($acm_type);
- }
}
diff --git a/phpBB/includes/class_loader.php b/phpBB/includes/class_loader.php
index fa121341aa..a28d745983 100644
--- a/phpBB/includes/class_loader.php
+++ b/phpBB/includes/class_loader.php
@@ -33,7 +33,7 @@ class phpbb_class_loader
{
private $phpbb_root_path;
private $php_ext;
- private $acm;
+ private $cache;
private $cached_paths = array();
/**
@@ -42,14 +42,14 @@ class phpbb_class_loader
*
* @param string $phpbb_root_path phpBB's root directory containing includes/
* @param string $php_ext The file extension for PHP files
- * @param phpbb_acm_interface $acm An implementation of the phpBB cache interface.
+ * @param phpbb_cache_driver_interface $cache An implementation of the phpBB cache interface.
*/
- public function __construct($phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $acm = null)
+ public function __construct($phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null)
{
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
- $this->set_acm($acm);
+ $this->set_cache($cache);
}
/**
@@ -57,13 +57,13 @@ class phpbb_class_loader
* the class loader will resolve paths by checking for the existance of every
* directory in the class name every time.
*
- * @param phpbb_acm_interface $acm An implementation of the phpBB cache interface.
+ * @param phpbb_cache_driver_interface $cache An implementation of the phpBB cache interface.
*/
- public function set_acm(phpbb_cache_driver_interface $acm = null)
+ public function set_cache(phpbb_cache_driver_interface $cache = null)
{
- if ($acm)
+ if ($cache)
{
- $this->cached_paths = $acm->get('class_loader');
+ $this->cached_paths = $cache->get('class_loader');
if ($this->cached_paths === false)
{
@@ -71,7 +71,7 @@ class phpbb_class_loader
}
}
- $this->acm = $acm;
+ $this->cache = $cache;
}
/**
@@ -134,10 +134,10 @@ class phpbb_class_loader
return false;
}
- if ($this->acm)
+ if ($this->cache)
{
$this->cached_paths[$class] = $relative_path;
- $this->acm->put('class_loader', $this->cached_paths);
+ $this->cache->put('class_loader', $this->cached_paths);
}
return $path_prefix . $relative_path . $this->php_ext;
diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php
index 961edd589f..f73f7472f0 100644
--- a/phpBB/install/database_update.php
+++ b/phpBB/install/database_update.php
@@ -95,9 +95,9 @@ $class_loader = new phpbb_class_loader($phpbb_root_path, '.' . $phpEx);
$class_loader->register();
// set up caching
-$acm = phpbb_cache_factory::create($acm_type)->get_acm();
-$class_loader->set_acm($acm);
-$cache = new phpbb_cache_service($acm);
+$cache_factory = new phpbb_cache_factory($acm_type);
+$class_loader->set_cache($cache_factory->get_driver());
+$cache = $cache_factory->get_service();
$request = new phpbb_request();
$user = new user();
diff --git a/phpBB/install/index.php b/phpBB/install/index.php
index 6486eb09d8..653268ba68 100644
--- a/phpBB/install/index.php
+++ b/phpBB/install/index.php
@@ -171,9 +171,9 @@ $class_loader = new phpbb_class_loader($phpbb_root_path, '.' . $phpEx);
$class_loader->register();
// set up caching
-$acm = phpbb_cache_factory::create($acm_type)->get_acm();
-$class_loader->set_acm($acm);
-$cache = new phpbb_cache_service($acm);
+$cache_factory = new phpbb_cache_factory('file');
+$class_loader->set_cache($cache_factory->get_driver());
+$cache = $cache_factory->get_service();
$request = new phpbb_request();
@@ -262,7 +262,6 @@ set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handle
$user = new user();
$auth = new auth();
-$cache = new cache();
$template = new template();
// Add own hook handler, if present. :o
diff --git a/phpBB/style.php b/phpBB/style.php
index 418bbb9bab..cff91a2312 100644
--- a/phpBB/style.php
+++ b/phpBB/style.php
@@ -65,9 +65,9 @@ if ($id)
$class_loader->register();
// set up caching
- $acm = phpbb_cache_factory::create($acm_type)->get_acm();
- $class_loader->set_acm($acm);
- $cache = new phpbb_cache_service($acm);
+ $cache_factory = new phpbb_cache_factory($acm_type);
+ $class_loader->set_cache($cache_factory->get_driver());
+ $cache = $cache_factory->get_service();
$request = new phpbb_request();
$db = new $sql_db();
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index d1d8adbdd5..4209c61947 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -16,7 +16,7 @@
./tests/
-
+
./tests/
diff --git a/tests/cache/all_tests.php b/tests/cache/all_tests.php
deleted file mode 100644
index 829d496e5d..0000000000
--- a/tests/cache/all_tests.php
+++ /dev/null
@@ -1,40 +0,0 @@
-addTestSuite('phpbb_cache_test');
-
- return $suite;
- }
-}
-
-if (PHPUnit_MAIN_METHOD == 'phpbb_cache_all_tests::main')
-{
- phpbb_cache_all_tests::main();
-}
diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php
index 220fddfd25..463095f129 100644
--- a/tests/cache/cache_test.php
+++ b/tests/cache/cache_test.php
@@ -2,37 +2,39 @@
/**
*
* @package testing
-* @version $Id$
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
-require_once 'test_framework/framework.php';
+require_once __DIR__ . '/../../phpBB/includes/functions.php';
class phpbb_cache_test extends phpbb_test_case
{
protected function tearDown()
{
- $iterator = new DirectoryIterator('cache/tmp');
+ $iterator = new DirectoryIterator(__DIR__ . '/tmp');
foreach ($iterator as $file)
{
- if (is_file('cache/tmp/' . $file))
+ if (is_file(__DIR__ . '/tmp/' . $file) && $file != '.gitkeep')
{
- unlink('cache/tmp/' . $file);
+ unlink(__DIR__ . '/tmp/' . $file);
}
}
}
- public function test_acm_file()
+ public function test_cache_driver_file()
{
- $acm = new phpbb_cache_driver_file('cache/tmp/');
- $acm->put('test_key', 'test_value');
- $acm->save();
-
+ global $phpEx;
+ $phpEx = 'txt'; // do not store files as .php
+
+ $driver = new phpbb_cache_driver_file(__DIR__ . '/tmp/');
+ $driver->put('test_key', 'test_value');
+ $driver->save();
+
$this->assertEquals(
'test_value',
- $acm->get('test_key'),
+ $driver->get('test_key'),
'File ACM put and get'
);
}
diff --git a/tests/cache/tmp/.gitkeep b/tests/cache/tmp/.gitkeep
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/tests/class_loader/class_loader_test.php b/tests/class_loader/class_loader_test.php
index c01278f914..cc6862dc70 100644
--- a/tests/class_loader/class_loader_test.php
+++ b/tests/class_loader/class_loader_test.php
@@ -2,13 +2,12 @@
/**
*
* @package testing
-* @version $Id$
-* @copyright (c) 2008 phpBB Group
+* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
-require_once __DIR__ . '/cache_mock.php';
+require_once __DIR__ . '/../mock/cache.php';
class phpbb_class_loader_test extends PHPUnit_Framework_TestCase
{
@@ -62,15 +61,7 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase
public function test_resolve_cached()
{
$cacheMap = array('class_loader' => array('phpbb_a_cached_name' => 'a/cached_name'));
-
- $cache = $this->getMock('phpbb_cache_driver_interface',
- array('get', 'put', 'load', 'unload', 'save', 'tidy', 'purge', 'destroy', '_exists',
- 'sql_load', 'sql_save', 'sql_exists', 'sql_fetchrow', 'sql_fetchfield', 'sql_rowseek', 'sql_freeresult'));
- $cache->expects($this->any())
- ->method('get')
- ->will($this->returnCallback(function($var_name) use ($cacheMap) {
- return $cacheMap[$var_name];
- }));
+ $cache = new phpbb_mock_cache($cacheMap);
$prefix = __DIR__ . '/';
$class_loader = new phpbb_class_loader($prefix, '.php', $cache);
@@ -88,5 +79,8 @@ class phpbb_class_loader_test extends PHPUnit_Framework_TestCase
$class_loader->resolve_path('phpbb_a_cached_name'),
'Class in a directory'
);
+
+ $cacheMap['class_loader']['phpbb_dir_class_name'] = 'dir/class_name';
+ $cache->check($this, $cacheMap);
}
}
diff --git a/tests/class_loader/cache_mock.php b/tests/mock/cache.php
similarity index 51%
rename from tests/class_loader/cache_mock.php
rename to tests/mock/cache.php
index 73d1e64cf5..3bfb31f1be 100644
--- a/tests/class_loader/cache_mock.php
+++ b/tests/mock/cache.php
@@ -2,31 +2,44 @@
/**
*
* @package testing
-* @version $Id$
-* @copyright (c) 2008 phpBB Group
+* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
-require '../phpBB/includes/cache/driver/interface.php';
-
-class phpbb_cache_mock implements phpbb_cache_driver_interface
+class phpbb_mock_cache implements phpbb_cache_driver_interface
{
- private $variables = array();
+ protected $data;
- function get($var_name)
+ public function __construct($data = array())
{
- if (isset($this->variables[$var_name]))
+ $this->data = $data;
+ }
+
+ public function get($var_name)
+ {
+ if (isset($this->data[$var_name]))
{
- return $this->variables[$var_name];
+ return $this->data[$var_name];
}
return false;
}
- function put($var_name, $value, $ttl = 0)
+ public function put($var_name, $var, $ttl = 0)
{
- $this->variables[$var_name] = $value;
+ $this->data[$var_name] = $var;
+ }
+
+ public function checkVar(PHPUnit_Framework_Assert $test, $var_name, $data)
+ {
+ $test->assertTrue(isset($this->data[$var_name]));
+ $test->assertEquals($data, $this->data[$var_name]);
+ }
+
+ public function check(PHPUnit_Framework_Assert $test, $data)
+ {
+ $test->assertEquals($data, $this->data);
}
function load()