Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
81.25% |
26 / 32 |
|
60.00% |
3 / 5 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_console_command_cache_purge_test | |
81.25% |
26 / 32 |
|
60.00% |
3 / 5 |
9.53 | |
0.00% |
0 / 1 |
| setUp | |
91.67% |
11 / 12 |
|
0.00% |
0 / 1 |
2.00 | |||
| test_purge | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
| create_cache_dir | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| remove_cache_dir | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
20 | |||
| get_command_tester | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | use Symfony\Component\Console\Application; |
| 15 | use Symfony\Component\Console\Tester\CommandTester; |
| 16 | use phpbb\console\command\cache\purge; |
| 17 | |
| 18 | require_once __DIR__ . '/../../../phpBB/includes/functions_admin.php'; |
| 19 | |
| 20 | class phpbb_console_command_cache_purge_test extends phpbb_test_case |
| 21 | { |
| 22 | protected $cache_dir; |
| 23 | protected $cache; |
| 24 | protected $config; |
| 25 | protected $db; |
| 26 | protected $db_tools; |
| 27 | protected $language; |
| 28 | protected $user; |
| 29 | |
| 30 | protected function setUp(): void |
| 31 | { |
| 32 | global $phpbb_root_path, $phpEx; |
| 33 | |
| 34 | $this->cache_dir = __DIR__ . '/tmp/cache/'; |
| 35 | |
| 36 | if (file_exists($this->cache_dir)) |
| 37 | { |
| 38 | // cache directory possibly left after aborted |
| 39 | // or failed run earlier |
| 40 | $this->remove_cache_dir(); |
| 41 | } |
| 42 | $this->create_cache_dir(); |
| 43 | |
| 44 | $this->cache = new \phpbb\cache\driver\file($this->cache_dir); |
| 45 | |
| 46 | $this->db = $this->createMock('\phpbb\db\driver\driver_interface'); |
| 47 | $tools_factory = new \phpbb\db\tools\factory(); |
| 48 | $this->db_tools = $this->createMock('\phpbb\db\tools\doctrine'); |
| 49 | |
| 50 | $this->config = new \phpbb\config\config(array('assets_version' => 1)); |
| 51 | $this->language = new \phpbb\language\language(new \phpbb\language\language_file_loader($phpbb_root_path, $phpEx)); |
| 52 | $this->user = new \phpbb\user($this->language, '\phpbb\datetime'); |
| 53 | } |
| 54 | |
| 55 | public function test_purge() |
| 56 | { |
| 57 | $this->cache->put('test_key', 'test_value'); |
| 58 | |
| 59 | $this->assertEquals( |
| 60 | 'test_value', |
| 61 | $this->cache->get('test_key'), |
| 62 | 'File ACM put and get' |
| 63 | ); |
| 64 | |
| 65 | $command_tester = $this->get_command_tester(); |
| 66 | $exit_status = $command_tester->execute([]); |
| 67 | |
| 68 | $this->assertSame(false, $this->cache->get('test_key')); |
| 69 | $this->assertSame(2, $this->config['assets_version']); |
| 70 | } |
| 71 | |
| 72 | private function create_cache_dir() |
| 73 | { |
| 74 | $this->get_test_case_helpers()->makedirs($this->cache_dir); |
| 75 | } |
| 76 | |
| 77 | private function remove_cache_dir() |
| 78 | { |
| 79 | $iterator = new DirectoryIterator($this->cache_dir); |
| 80 | foreach ($iterator as $file) |
| 81 | { |
| 82 | if ($file != '.' && $file != '..') |
| 83 | { |
| 84 | unlink($this->cache_dir . '/' . $file); |
| 85 | } |
| 86 | } |
| 87 | rmdir($this->cache_dir); |
| 88 | } |
| 89 | |
| 90 | public function get_command_tester() |
| 91 | { |
| 92 | $application = new Application(); |
| 93 | $application->add(new purge($this->user, $this->cache, $this->db, $this->db_tools, $this->createMock('\phpbb\auth\auth'), new \phpbb\log\dummy(), $this->config)); |
| 94 | |
| 95 | $command = $application->find('cache:purge'); |
| 96 | return new CommandTester($command); |
| 97 | } |
| 98 | } |