From 64827a6623c9a916d41c2ef5bf2c2092a3008722 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 29 Aug 2011 18:43:45 -0400 Subject: [PATCH] [feature/extension-manager] Test creation of new extension finder cache PHPBB3-10323 --- phpBB/includes/extension/finder.php | 5 ----- tests/extension/finder_test.php | 31 ++++++++++++++++++++++++++++- tests/mock/cache.php | 12 +++++++++++ 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/extension/finder.php b/phpBB/includes/extension/finder.php index d25823ca43..b3cdbd6ab9 100644 --- a/phpBB/includes/extension/finder.php +++ b/phpBB/includes/extension/finder.php @@ -283,11 +283,6 @@ class phpbb_extension_finder if ($cache && $this->cache) { - if ($this->cached_queries === false) - { - $this->cached_queries = array(); - } - $this->cached_queries[$query] = $files; $this->cache->put('_extension_finder', $this->cached_queries); } diff --git a/tests/extension/finder_test.php b/tests/extension/finder_test.php index 4acfe53937..fb2faaf5c0 100644 --- a/tests/extension/finder_test.php +++ b/tests/extension/finder_test.php @@ -122,6 +122,36 @@ class phpbb_extension_finder_test extends phpbb_test_case ); } + public function test_get_classes_create_cache() + { + $cache = new phpbb_mock_cache; + $finder = new phpbb_extension_finder($this->extension_manager, dirname(__FILE__) . '/includes/', $cache); + $files = $finder->suffix('_class.php')->get_files(); + + sort($files); + + $expected_files = array( + 'ext/bar/my/hidden_class.php', + 'ext/foo/a_class.php', + 'ext/foo/b_class.php', + ); + + $query = array( + 'default_path' => false, + 'default_suffix' => '_class.php', + 'default_prefix' => false, + 'default_directory' => false, + 'suffix' => '_class.php', + 'prefix' => false, + 'directory' => false, + ); + + $this->assertEquals($expected_files, $files); + $cache->checkAssociativeVar($this, '_extension_finder', array( + md5(serialize($query)) => $expected_files, + )); + } + public function test_cached_get_files() { $query = array( @@ -134,7 +164,6 @@ class phpbb_extension_finder_test extends phpbb_test_case 'directory' => false, ); - $finder = new phpbb_extension_finder($this->extension_manager, dirname(__FILE__) . '/includes/', new phpbb_mock_cache(array( '_extension_finder' => array( md5(serialize($query)) => array('file_name'), diff --git a/tests/mock/cache.php b/tests/mock/cache.php index 989180c256..b745123801 100644 --- a/tests/mock/cache.php +++ b/tests/mock/cache.php @@ -59,6 +59,18 @@ class phpbb_mock_cache implements phpbb_cache_driver_interface $test->assertEquals($data, $this->data[$var_name]); } + public function checkAssociativeVar(PHPUnit_Framework_Assert $test, $var_name, $data) + { + $test->assertTrue(isset($this->data[$var_name])); + + foreach ($this->data[$var_name] as &$content) + { + sort($content); + } + + $test->assertEquals($data, $this->data[$var_name]); + } + public function checkVarUnset(PHPUnit_Framework_Assert $test, $var_name) { $test->assertFalse(isset($this->data[$var_name]));