Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
52 / 52 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
| phpbb_cron_manager_test | |
100.00% |
52 / 52 |
|
100.00% |
7 / 7 |
8 | |
100.00% |
1 / 1 |
| setUp | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| test_manager_finds_shipped_task_by_name | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| test_manager_finds_all_ready_tasks | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| test_manager_finds_one_ready_task | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| test_manager_finds_only_ready_tasks | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| tasks_to_names | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| create_cron_manager | |
100.00% |
27 / 27 |
|
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 | require_once __DIR__ . '/includes/cron/task/core/dummy_task.php'; |
| 15 | require_once __DIR__ . '/includes/cron/task/core/second_dummy_task.php'; |
| 16 | require_once __DIR__ . '/ext/testext/cron/dummy_task.php'; |
| 17 | require_once __DIR__ . '/tasks/simple_ready.php'; |
| 18 | require_once __DIR__ . '/tasks/simple_not_runnable.php'; |
| 19 | require_once __DIR__ . '/tasks/simple_should_not_run.php'; |
| 20 | |
| 21 | class phpbb_cron_manager_test extends \phpbb_test_case |
| 22 | { |
| 23 | protected $manager; |
| 24 | protected $task_name; |
| 25 | |
| 26 | protected function setUp(): void |
| 27 | { |
| 28 | $this->manager = $this->create_cron_manager(array( |
| 29 | new phpbb_cron_task_core_dummy_task(), |
| 30 | new phpbb_cron_task_core_second_dummy_task(), |
| 31 | new phpbb_ext_testext_cron_dummy_task(), |
| 32 | )); |
| 33 | $this->task_name = 'phpbb_cron_task_core_dummy_task'; |
| 34 | } |
| 35 | |
| 36 | public function test_manager_finds_shipped_task_by_name() |
| 37 | { |
| 38 | $task = $this->manager->find_task($this->task_name); |
| 39 | $this->assertInstanceOf('\phpbb\cron\task\wrapper', $task); |
| 40 | $this->assertEquals($this->task_name, $task->get_name()); |
| 41 | } |
| 42 | |
| 43 | public function test_manager_finds_all_ready_tasks() |
| 44 | { |
| 45 | $tasks = $this->manager->find_all_ready_tasks(); |
| 46 | $this->assertEquals(3, count($tasks)); |
| 47 | } |
| 48 | |
| 49 | public function test_manager_finds_one_ready_task() |
| 50 | { |
| 51 | $task = $this->manager->find_one_ready_task(); |
| 52 | $this->assertInstanceOf('\phpbb\cron\task\wrapper', $task); |
| 53 | } |
| 54 | |
| 55 | public function test_manager_finds_only_ready_tasks() |
| 56 | { |
| 57 | $manager = $this->create_cron_manager(array( |
| 58 | new phpbb_cron_task_core_simple_ready(), |
| 59 | new phpbb_cron_task_core_simple_not_runnable(), |
| 60 | new phpbb_cron_task_core_simple_should_not_run(), |
| 61 | )); |
| 62 | $tasks = $manager->find_all_ready_tasks(); |
| 63 | $task_names = $this->tasks_to_names($tasks); |
| 64 | $this->assertEquals(array('phpbb_cron_task_core_simple_ready'), $task_names); |
| 65 | } |
| 66 | |
| 67 | private function tasks_to_names($tasks) |
| 68 | { |
| 69 | $names = array(); |
| 70 | foreach ($tasks as $task) |
| 71 | { |
| 72 | $names[] = $task->get_name(); |
| 73 | } |
| 74 | return $names; |
| 75 | } |
| 76 | |
| 77 | private function create_cron_manager($tasks) |
| 78 | { |
| 79 | global $phpbb_root_path, $phpEx; |
| 80 | |
| 81 | $mock_config = new \phpbb\config\config(array( |
| 82 | 'force_server_vars' => false, |
| 83 | 'enable_mod_rewrite' => '', |
| 84 | )); |
| 85 | |
| 86 | $mock_router = $this->getMockBuilder('\phpbb\routing\router') |
| 87 | ->onlyMethods(array('setContext', 'generate')) |
| 88 | ->disableOriginalConstructor() |
| 89 | ->getMock(); |
| 90 | $mock_router->method('generate') |
| 91 | ->willReturn('foobar'); |
| 92 | |
| 93 | $request = new \phpbb\request\request(); |
| 94 | $request->enable_super_globals(); |
| 95 | |
| 96 | $routing_helper = new \phpbb\routing\helper( |
| 97 | $mock_config, |
| 98 | $mock_router, |
| 99 | new \phpbb\symfony_request($request), |
| 100 | $request, |
| 101 | $phpbb_root_path, |
| 102 | $phpEx |
| 103 | ); |
| 104 | |
| 105 | $mock_container = new phpbb_mock_container_builder(); |
| 106 | $task_collection = new \phpbb\di\service_collection($mock_container); |
| 107 | $mock_container->set('cron.task_collection', $task_collection); |
| 108 | |
| 109 | $cron_manager = new \phpbb\cron\manager($mock_container, $routing_helper, $phpbb_root_path, $phpEx, null); |
| 110 | $cron_manager->load_tasks($tasks); |
| 111 | |
| 112 | return $cron_manager; |
| 113 | } |
| 114 | } |