[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(); $class_loader->register();
// set up caching // set up caching
$acm = phpbb_cache_factory::create($acm_type)->get_acm(); $cache_factory = new phpbb_cache_factory($acm_type);
$class_loader->set_acm($acm); $class_loader->set_cache($cache_factory->get_driver());
$cache = new phpbb_cache_service($acm); $cache = $cache_factory->get_service();
// Instantiate some basic classes // Instantiate some basic classes
$request = new phpbb_request(); $request = new phpbb_request();

View file

@ -54,9 +54,9 @@ if (isset($_GET['avatar']))
$class_loader->register(); $class_loader->register();
// set up caching // set up caching
$acm = phpbb_cache_factory::create($acm_type)->get_acm(); $cache_factory = new phpbb_cache_factory($acm_type);
$class_loader->set_acm($acm); $class_loader->set_cache($cache_factory->get_driver());
$cache = new phpbb_cache_service($acm); $cache = $cache_factory->get_service();
$db = new $sql_db(); $db = new $sql_db();

View file

@ -22,31 +22,22 @@ if (!defined('IN_PHPBB'))
class phpbb_cache_factory class phpbb_cache_factory
{ {
private $acm_type; private $acm_type;
public function __construct($acm_type) public function __construct($acm_type)
{ {
$this->acm_type = $acm_type; $this->acm_type = $acm_type;
} }
public function get_acm() public function get_driver()
{ {
$class_name = 'phpbb_cache_driver_' . $this->acm_type; $class_name = 'phpbb_cache_driver_' . $this->acm_type;
return new $class_name(); return new $class_name();
} }
public function get_service() public function get_service()
{ {
$acm = $this->get_acm(); $driver = $this->get_driver();
$service = new phpbb_cache_service($acm); $service = new phpbb_cache_service($driver);
return $service; 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 $phpbb_root_path;
private $php_ext; private $php_ext;
private $acm; private $cache;
private $cached_paths = array(); 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 $phpbb_root_path phpBB's root directory containing includes/
* @param string $php_ext The file extension for PHP files * @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->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext; $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 * the class loader will resolve paths by checking for the existance of every
* directory in the class name every time. * 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) 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; return false;
} }
if ($this->acm) if ($this->cache)
{ {
$this->cached_paths[$class] = $relative_path; $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; 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(); $class_loader->register();
// set up caching // set up caching
$acm = phpbb_cache_factory::create($acm_type)->get_acm(); $cache_factory = new phpbb_cache_factory($acm_type);
$class_loader->set_acm($acm); $class_loader->set_cache($cache_factory->get_driver());
$cache = new phpbb_cache_service($acm); $cache = $cache_factory->get_service();
$request = new phpbb_request(); $request = new phpbb_request();
$user = new user(); $user = new user();

View file

@ -171,9 +171,9 @@ $class_loader = new phpbb_class_loader($phpbb_root_path, '.' . $phpEx);
$class_loader->register(); $class_loader->register();
// set up caching // set up caching
$acm = phpbb_cache_factory::create($acm_type)->get_acm(); $cache_factory = new phpbb_cache_factory('file');
$class_loader->set_acm($acm); $class_loader->set_cache($cache_factory->get_driver());
$cache = new phpbb_cache_service($acm); $cache = $cache_factory->get_service();
$request = new phpbb_request(); $request = new phpbb_request();
@ -262,7 +262,6 @@ set_error_handler(defined('PHPBB_MSG_HANDLER') ? PHPBB_MSG_HANDLER : 'msg_handle
$user = new user(); $user = new user();
$auth = new auth(); $auth = new auth();
$cache = new cache();
$template = new template(); $template = new template();
// Add own hook handler, if present. :o // Add own hook handler, if present. :o

View file

@ -65,9 +65,9 @@ if ($id)
$class_loader->register(); $class_loader->register();
// set up caching // set up caching
$acm = phpbb_cache_factory::create($acm_type)->get_acm(); $cache_factory = new phpbb_cache_factory($acm_type);
$class_loader->set_acm($acm); $class_loader->set_cache($cache_factory->get_driver());
$cache = new phpbb_cache_service($acm); $cache = $cache_factory->get_service();
$request = new phpbb_request(); $request = new phpbb_request();
$db = new $sql_db(); $db = new $sql_db();

View file

@ -16,7 +16,7 @@
<directory suffix=".php">./tests/</directory> <directory suffix=".php">./tests/</directory>
</testsuite> </testsuite>
</testsuites> </testsuites>
<filter> <filter>
<blacklist> <blacklist>
<directory>./tests/</directory> <directory>./tests/</directory>

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 * @package testing
* @version $Id$
* @copyright (c) 2010 phpBB Group * @copyright (c) 2010 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License * @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 class phpbb_cache_test extends phpbb_test_case
{ {
protected function tearDown() protected function tearDown()
{ {
$iterator = new DirectoryIterator('cache/tmp'); $iterator = new DirectoryIterator(__DIR__ . '/tmp');
foreach ($iterator as $file) 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/'); global $phpEx;
$acm->put('test_key', 'test_value'); $phpEx = 'txt'; // do not store files as .php
$acm->save();
$driver = new phpbb_cache_driver_file(__DIR__ . '/tmp/');
$driver->put('test_key', 'test_value');
$driver->save();
$this->assertEquals( $this->assertEquals(
'test_value', 'test_value',
$acm->get('test_key'), $driver->get('test_key'),
'File ACM put and get' 'File ACM put and get'
); );
} }

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

View file

@ -2,13 +2,12 @@
/** /**
* *
* @package testing * @package testing
* @version $Id$ * @copyright (c) 2011 phpBB Group
* @copyright (c) 2008 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License * @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 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() public function test_resolve_cached()
{ {
$cacheMap = array('class_loader' => array('phpbb_a_cached_name' => 'a/cached_name')); $cacheMap = array('class_loader' => array('phpbb_a_cached_name' => 'a/cached_name'));
$cache = new phpbb_mock_cache($cacheMap);
$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];
}));
$prefix = __DIR__ . '/'; $prefix = __DIR__ . '/';
$class_loader = new phpbb_class_loader($prefix, '.php', $cache); $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_loader->resolve_path('phpbb_a_cached_name'),
'Class in a directory' '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 * @package testing
* @version $Id$ * @copyright (c) 2011 phpBB Group
* @copyright (c) 2008 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License * @license http://opensource.org/licenses/gpl-license.php GNU Public License
* *
*/ */
require '../phpBB/includes/cache/driver/interface.php'; class phpbb_mock_cache implements phpbb_cache_driver_interface
class phpbb_cache_mock 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; 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() function load()