From 4a76763a8a404a04f141825f572ff65620f400c4 Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Wed, 4 Jun 2014 16:24:33 +0200 Subject: [ticket/12657] Add a test file for base case PHPBB3-12657 --- tests/console/cache/fixtures/config.xml | 8 +++ tests/console/cache/purge_test.php | 103 ++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 tests/console/cache/fixtures/config.xml create mode 100644 tests/console/cache/purge_test.php (limited to 'tests') diff --git a/tests/console/cache/fixtures/config.xml b/tests/console/cache/fixtures/config.xml new file mode 100644 index 0000000000..2cb683d409 --- /dev/null +++ b/tests/console/cache/fixtures/config.xml @@ -0,0 +1,8 @@ + + + + config_name + config_value + is_dynamic +
+
diff --git a/tests/console/cache/purge_test.php b/tests/console/cache/purge_test.php new file mode 100644 index 0000000000..7fc9c97ca9 --- /dev/null +++ b/tests/console/cache/purge_test.php @@ -0,0 +1,103 @@ + +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. +* +*/ + +use Symfony\Component\Console\Application; +use Symfony\Component\Console\Tester\CommandTester; +use phpbb\console\command\cache\purge; + +require_once dirname(__FILE__) . '/../../../phpBB/includes/functions_admin.php'; + +class phpbb_console_command_cache_purge_test extends phpbb_database_test_case +{ + protected $cache_dir; + protected $cache; + protected $command_name; + protected $db; + protected $config; + + public function __construct() + { + $this->cache_dir = dirname(__FILE__) . 'tmp/cache/'; + } + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); + } + + protected function setUp() + { + parent::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(); + + $this->cache = new \phpbb\cache\driver\file($this->cache_dir); + + $this->db = $this->new_dbal(); + + $this->config = new \phpbb\config\config(array('assets_version' => 1)); + } + + public function test_purge() + { + $this->cache->put('test_key', 'test_value'); + + $this->assertEquals( + 'test_value', + $this->cache->get('test_key'), + 'File ACM put and get' + ); + + $command_tester = $this->get_command_tester(); + $exit_status = $command_tester->execute(array('command' => $this->command_name)); + + $this->assertSame(false, $this->cache->get('test_key')); + $this->assertSame(2, $this->config['assets_version']); + } + + private function create_cache_dir() + { + $this->get_test_case_helpers()->makedirs($this->cache_dir); + } + + private function remove_cache_dir() + { + $iterator = new DirectoryIterator($this->cache_dir); + foreach ($iterator as $file) + { + if ($file != '.' && $file != '..') + { + unlink($this->cache_dir . '/' . $file); + } + } + rmdir($this->cache_dir); + } + + public function get_command_tester() + { + global $phpbb_root_path, $phpEx; + + $application = new Application(); + $application->add(new purge($this->cache, $this->db, $this->getMock('\phpbb\auth\auth'), new \phpbb\log\null(), $this->getMock('\phpbb\user'), $this->config)); + + $command = $application->find('cache:purge'); + $this->command_name = $command->getName(); + return new CommandTester($command); + } +} -- cgit v1.2.1 From 6e4348b0ea5b8aa0b6311c0d4482d5452e00d2cc Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Wed, 4 Jun 2014 17:08:57 +0200 Subject: [ticket/12657] Fix name temporary directory used by test file PHPBB3-12657 --- tests/console/cache/purge_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/console/cache/purge_test.php b/tests/console/cache/purge_test.php index 7fc9c97ca9..6c1fb50b22 100644 --- a/tests/console/cache/purge_test.php +++ b/tests/console/cache/purge_test.php @@ -27,7 +27,7 @@ class phpbb_console_command_cache_purge_test extends phpbb_database_test_case public function __construct() { - $this->cache_dir = dirname(__FILE__) . 'tmp/cache/'; + $this->cache_dir = dirname(__FILE__) . '/tmp/cache/'; } public function getDataSet() -- cgit v1.2.1 From fb08d1b27e86b5413a18d7a820c31e1c8f8490db Mon Sep 17 00:00:00 2001 From: LEZY Thomas Date: Thu, 5 Jun 2014 09:29:33 +0200 Subject: [ticket/12657] Remove unused global variables PHPBB3-12657 --- tests/console/cache/purge_test.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'tests') diff --git a/tests/console/cache/purge_test.php b/tests/console/cache/purge_test.php index 6c1fb50b22..c950919cc2 100644 --- a/tests/console/cache/purge_test.php +++ b/tests/console/cache/purge_test.php @@ -91,8 +91,6 @@ class phpbb_console_command_cache_purge_test extends phpbb_database_test_case public function get_command_tester() { - global $phpbb_root_path, $phpEx; - $application = new Application(); $application->add(new purge($this->cache, $this->db, $this->getMock('\phpbb\auth\auth'), new \phpbb\log\null(), $this->getMock('\phpbb\user'), $this->config)); -- cgit v1.2.1 From 689eaab3e2139d6e485d4cd0da1248f4a8de2404 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Thu, 7 Aug 2014 16:41:16 +0200 Subject: [ticket/12657] The test does not need to depend on the database PHPBB3-12657 --- tests/console/cache/fixtures/config.xml | 8 -------- tests/console/cache/purge_test.php | 11 ++--------- 2 files changed, 2 insertions(+), 17 deletions(-) delete mode 100644 tests/console/cache/fixtures/config.xml (limited to 'tests') diff --git a/tests/console/cache/fixtures/config.xml b/tests/console/cache/fixtures/config.xml deleted file mode 100644 index 2cb683d409..0000000000 --- a/tests/console/cache/fixtures/config.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - config_name - config_value - is_dynamic -
-
diff --git a/tests/console/cache/purge_test.php b/tests/console/cache/purge_test.php index c950919cc2..ee4e8f5d50 100644 --- a/tests/console/cache/purge_test.php +++ b/tests/console/cache/purge_test.php @@ -17,7 +17,7 @@ use phpbb\console\command\cache\purge; require_once dirname(__FILE__) . '/../../../phpBB/includes/functions_admin.php'; -class phpbb_console_command_cache_purge_test extends phpbb_database_test_case +class phpbb_console_command_cache_purge_test extends phpbb_test_case { protected $cache_dir; protected $cache; @@ -30,15 +30,8 @@ class phpbb_console_command_cache_purge_test extends phpbb_database_test_case $this->cache_dir = dirname(__FILE__) . '/tmp/cache/'; } - public function getDataSet() - { - return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); - } - protected function setUp() { - parent::setUp(); - if (file_exists($this->cache_dir)) { // cache directory possibly left after aborted @@ -49,7 +42,7 @@ class phpbb_console_command_cache_purge_test extends phpbb_database_test_case $this->cache = new \phpbb\cache\driver\file($this->cache_dir); - $this->db = $this->new_dbal(); + $this->db = $this->getMock('\phpbb\db\driver\driver_interface'); $this->config = new \phpbb\config\config(array('assets_version' => 1)); } -- cgit v1.2.1 From c767712c64de93b96e718af593c6c18f4a0042b0 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Fri, 8 Aug 2014 13:29:41 +0200 Subject: [ticket/12657] Fix the order of the parameters for the constructor PHPBB3-12657 --- tests/console/cache/purge_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/console/cache/purge_test.php b/tests/console/cache/purge_test.php index ee4e8f5d50..ff76f31e69 100644 --- a/tests/console/cache/purge_test.php +++ b/tests/console/cache/purge_test.php @@ -85,7 +85,7 @@ class phpbb_console_command_cache_purge_test extends phpbb_test_case public function get_command_tester() { $application = new Application(); - $application->add(new purge($this->cache, $this->db, $this->getMock('\phpbb\auth\auth'), new \phpbb\log\null(), $this->getMock('\phpbb\user'), $this->config)); + $application->add(new purge($this->getMock('\phpbb\user'), $this->cache, $this->db, $this->getMock('\phpbb\auth\auth'), new \phpbb\log\null(), $this->config)); $command = $application->find('cache:purge'); $this->command_name = $command->getName(); -- cgit v1.2.1 From 834aea70a7d51f775b2b88e467d273233744a107 Mon Sep 17 00:00:00 2001 From: Tristan Darricau Date: Wed, 24 Sep 2014 15:24:56 +0200 Subject: [ticket/12657] Fix unit tests PHPBB3-12657 --- tests/console/cache/purge_test.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/console/cache/purge_test.php b/tests/console/cache/purge_test.php index ff76f31e69..96988c1028 100644 --- a/tests/console/cache/purge_test.php +++ b/tests/console/cache/purge_test.php @@ -45,6 +45,7 @@ class phpbb_console_command_cache_purge_test extends phpbb_test_case $this->db = $this->getMock('\phpbb\db\driver\driver_interface'); $this->config = new \phpbb\config\config(array('assets_version' => 1)); + $this->user = $this->getMock('\phpbb\user', array(), array('\phpbb\datetime')); } public function test_purge() @@ -85,7 +86,7 @@ class phpbb_console_command_cache_purge_test extends phpbb_test_case public function get_command_tester() { $application = new Application(); - $application->add(new purge($this->getMock('\phpbb\user'), $this->cache, $this->db, $this->getMock('\phpbb\auth\auth'), new \phpbb\log\null(), $this->config)); + $application->add(new purge($this->user, $this->cache, $this->db, $this->getMock('\phpbb\auth\auth'), new \phpbb\log\null(), $this->config)); $command = $application->find('cache:purge'); $this->command_name = $command->getName(); -- cgit v1.2.1