[task/acm-refactor] Cleaning up left over mentions of ACM and fixing tests.

PHPBB3-9983
This commit is contained in:
Nils Adermann 2011-01-09 21:09:56 +01:00 committed by Igor Wiedler
parent 9329b16ab1
commit 1aef7eb20e
13 changed files with 76 additions and 117 deletions

View file

@ -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();

View file

@ -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();

View file

@ -28,7 +28,7 @@ class phpbb_cache_factory
$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();
@ -36,17 +36,8 @@ class phpbb_cache_factory
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);
}
}

View file

@ -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;

View file

@ -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();

View file

@ -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

View file

@ -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();

View file

@ -1,40 +0,0 @@
<?php
/**
*
* @package testing
* @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
if (!defined('PHPUnit_MAIN_METHOD'))
{
define('PHPUnit_MAIN_METHOD', 'phpbb_request_all_tests::main');
}
require_once 'test_framework/framework.php';
require_once 'PHPUnit/TextUI/TestRunner.php';
require_once 'cache/cache_test.php';
class phpbb_cache_all_tests
{
public static function main()
{
PHPUnit_TextUI_TestRunner::run(self::suite());
}
public static function suite()
{
$suite = new PHPUnit_Framework_TestSuite('phpBB Cache System');
$suite->addTestSuite('phpbb_cache_test');
return $suite;
}
}
if (PHPUnit_MAIN_METHOD == 'phpbb_cache_all_tests::main')
{
phpbb_cache_all_tests::main();
}

View file

@ -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'
);
}

0
tests/cache/tmp/.gitkeep vendored Normal file
View file

View file

@ -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);
}
}

View file

@ -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)
{
return $this->variables[$var_name];
if (isset($this->data[$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()