From 8de411cc25e0a72dea858e247e7200df2fbccfea Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 27 Jan 2011 18:26:58 -0500 Subject: [PATCH 1/3] [ticket/10013] Changed cache test to use tests/tmp/cache as cache directory This is the first step of making the test suite use a single directory for writing files to, this directory being tests/tmp. The cache test, instead of tests/cache/tmp, now writes to tests/tmp/cache. Also remove cache directory in setUp method, in case an earlier test run did not complete successfully and the cache directory was not cleaned up. Finally, this change makes the cache test take responsibility over the entire contents of its cache directory. PHPBB3-10013 --- .gitignore | 1 + tests/cache/cache_test.php | 40 ++++++++++++++++++++++++++++++++++---- tests/cache/tmp/.gitkeep | 0 3 files changed, 37 insertions(+), 4 deletions(-) delete mode 100644 tests/cache/tmp/.gitkeep diff --git a/.gitignore b/.gitignore index c417bf01c1..dcdfd3c386 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ phpBB/images/avatars/upload/* phpBB/store/* tests/phpbb_unit_tests.sqlite2 tests/test_config.php +tests/tmp tests/utf/data/*.txt diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php index 2f11267cba..61908dbe31 100644 --- a/tests/cache/cache_test.php +++ b/tests/cache/cache_test.php @@ -11,21 +11,53 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; class phpbb_cache_test extends phpbb_test_case { + private $cache_dir; + + public function __construct() + { + $this->cache_dir = dirname(__FILE__) . '/../tmp/cache'; + } + + protected function setUp() + { + if (file_exists($this->cache_dir)) + { + // cache directory possibly left after aborted + // or failed run earlier + $this->remove_cache_dir(); + } + $this->create_cache_dir(); + } + protected function tearDown() { - $iterator = new DirectoryIterator(dirname(__FILE__) . '/tmp'); + if (file_exists($this->cache_dir)) + { + $this->remove_cache_dir(); + } + } + + private function create_cache_dir() + { + mkdir($this->cache_dir); + } + + private function remove_cache_dir() + { + $iterator = new DirectoryIterator($this->cache_dir); foreach ($iterator as $file) { - if (is_file(dirname(__FILE__) . '/tmp/' . $file) && $file != '.gitkeep') + if ($file != '.' && $file != '..') { - unlink(dirname(__FILE__) . '/tmp/' . $file); + unlink($this->cache_dir . '/' . $file); } } + rmdir($this->cache_dir); } public function test_cache_driver_file() { - $driver = new phpbb_cache_driver_file(dirname(__FILE__) . '/tmp/'); + $driver = new phpbb_cache_driver_file($this->cache_dir); $driver->put('test_key', 'test_value'); $driver->save(); diff --git a/tests/cache/tmp/.gitkeep b/tests/cache/tmp/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 From 4e446277a5f6e4e5772065110d06eb4a46f95b41 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 2 Feb 2011 10:16:28 -0500 Subject: [PATCH 2/3] [ticket/10013] Fixed cache test to create intermediate directories. PHPBB3-10013 --- tests/cache/cache_test.php | 4 ++-- tests/test_framework/phpbb_test_case_helpers.php | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/cache/cache_test.php b/tests/cache/cache_test.php index 61908dbe31..b127c507f0 100644 --- a/tests/cache/cache_test.php +++ b/tests/cache/cache_test.php @@ -15,7 +15,7 @@ class phpbb_cache_test extends phpbb_test_case public function __construct() { - $this->cache_dir = dirname(__FILE__) . '/../tmp/cache'; + $this->cache_dir = dirname(__FILE__) . '/../tmp/cache/'; } protected function setUp() @@ -39,7 +39,7 @@ class phpbb_cache_test extends phpbb_test_case private function create_cache_dir() { - mkdir($this->cache_dir); + $this->get_test_case_helpers()->makedirs($this->cache_dir); } private function remove_cache_dir() diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 0acdce32e0..0eec4a90ca 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -41,4 +41,13 @@ class phpbb_test_case_helpers $this->expectedTriggerError = true; $this->test_case->setExpectedException($exceptionName, (string) $message, $errno); } + + public function makedirs($path) + { + while (!file_exists($path)) + { + $this->makedirs(dirname($path)); + mkdir($path); + } + } } From 0765f9ba7fdf78515260653bad15b04a406ec2ae Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 2 Feb 2011 20:34:27 -0500 Subject: [PATCH 3/3] [ticket/10013] Use mkdir to create directory trees. PHPBB3-10013 --- tests/test_framework/phpbb_test_case_helpers.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 0eec4a90ca..697dc93501 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -44,10 +44,6 @@ class phpbb_test_case_helpers public function makedirs($path) { - while (!file_exists($path)) - { - $this->makedirs(dirname($path)); - mkdir($path); - } + mkdir($path, 0777, true); } }