Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
53 / 53 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
1 / 1 |
| phpbb_console_command_cron_list_test | |
100.00% |
53 / 53 |
|
100.00% |
8 / 8 |
11 | |
100.00% |
1 / 1 |
| setUp | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| test_no_task | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| test_only_ready | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| test_only_not_ready | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| test_both_ready | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| get_cron_manager | |
100.00% |
30 / 30 |
|
100.00% |
1 / 1 |
2 | |||
| get_command_tester | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| initiate_test | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
| 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__ . '/tasks/simple_ready.php'; |
| 15 | require_once __DIR__ . '/tasks/simple_not_ready.php'; |
| 16 | |
| 17 | use Symfony\Component\Console\Application; |
| 18 | use Symfony\Component\Console\Tester\CommandTester; |
| 19 | use phpbb\console\command\cron\cron_list; |
| 20 | |
| 21 | class phpbb_console_command_cron_list_test extends phpbb_test_case |
| 22 | { |
| 23 | /** @var \phpbb\cron\manager */ |
| 24 | protected $cron_manager; |
| 25 | |
| 26 | /** @var \phpbb\user */ |
| 27 | protected $user; |
| 28 | |
| 29 | protected $command_tester; |
| 30 | |
| 31 | protected function setUp(): void |
| 32 | { |
| 33 | global $phpbb_root_path, $phpEx; |
| 34 | |
| 35 | $this->user = $this->createMock('\phpbb\user'); |
| 36 | $this->user->method('lang')->will($this->returnArgument(0)); |
| 37 | } |
| 38 | |
| 39 | public function test_no_task() |
| 40 | { |
| 41 | $this->initiate_test(0, 0); |
| 42 | $this->assertStringContainsString('CRON_NO_TASKS', $this->command_tester->getDisplay()); |
| 43 | } |
| 44 | |
| 45 | public function test_only_ready() |
| 46 | { |
| 47 | $this->initiate_test(2, 0); |
| 48 | $this->assertStringContainsString('TASKS_READY command1 command2', preg_replace('/[\s*=]+/', ' ', trim($this->command_tester->getDisplay()))); |
| 49 | } |
| 50 | |
| 51 | public function test_only_not_ready() |
| 52 | { |
| 53 | $this->initiate_test(0, 2); |
| 54 | $this->assertStringContainsString('TASKS_NOT_READY command1 command2', preg_replace('/[\s*=]+/', ' ', trim($this->command_tester->getDisplay()))); |
| 55 | } |
| 56 | |
| 57 | public function test_both_ready() |
| 58 | { |
| 59 | $this->initiate_test(2, 2); |
| 60 | $this->assertSame('TASKS_READY command1 command2 TASKS_NOT_READY command3 command4', preg_replace('/[\s*=]+/', ' ', trim($this->command_tester->getDisplay()))); |
| 61 | } |
| 62 | |
| 63 | public function get_cron_manager(array $tasks) |
| 64 | { |
| 65 | global $pathEx, $phpbb_root_path; |
| 66 | $i = 1; |
| 67 | foreach ($tasks as $task) |
| 68 | { |
| 69 | $task->set_name('command' . $i); |
| 70 | $i++; |
| 71 | } |
| 72 | |
| 73 | $mock_config = new \phpbb\config\config(array( |
| 74 | 'force_server_vars' => false, |
| 75 | 'enable_mod_rewrite' => '', |
| 76 | )); |
| 77 | |
| 78 | $mock_router = $this->getMockBuilder('\phpbb\routing\router') |
| 79 | ->onlyMethods(array('setContext', 'generate')) |
| 80 | ->disableOriginalConstructor() |
| 81 | ->getMock(); |
| 82 | $mock_router->method('generate') |
| 83 | ->willReturn('foobar'); |
| 84 | |
| 85 | $request = new \phpbb\request\request(); |
| 86 | $request->enable_super_globals(); |
| 87 | |
| 88 | $routing_helper = new \phpbb\routing\helper( |
| 89 | $mock_config, |
| 90 | $mock_router, |
| 91 | new \phpbb\symfony_request($request), |
| 92 | $request, |
| 93 | $phpbb_root_path, |
| 94 | $pathEx |
| 95 | ); |
| 96 | |
| 97 | $mock_container = new phpbb_mock_container_builder(); |
| 98 | $task_collection = new \phpbb\di\service_collection($mock_container); |
| 99 | $mock_container->set('cron.task_collection', $task_collection); |
| 100 | |
| 101 | $this->cron_manager = new \phpbb\cron\manager($mock_container, $routing_helper, $phpbb_root_path, $pathEx, null); |
| 102 | $this->cron_manager->load_tasks($tasks); |
| 103 | } |
| 104 | |
| 105 | public function get_command_tester() |
| 106 | { |
| 107 | $application = new Application(); |
| 108 | $application->add(new cron_list($this->user, $this->cron_manager)); |
| 109 | |
| 110 | $command = $application->find('cron:list'); |
| 111 | return new CommandTester($command); |
| 112 | } |
| 113 | |
| 114 | public function initiate_test($number_ready, $number_not_ready) |
| 115 | { |
| 116 | $tasks = array(); |
| 117 | |
| 118 | for ($i = 0; $i < $number_ready; $i++) |
| 119 | { |
| 120 | $tasks[] = new phpbb_cron_task_simple_ready(); |
| 121 | } |
| 122 | |
| 123 | for ($i = 0; $i < $number_not_ready; $i++) |
| 124 | { |
| 125 | $tasks[] = new phpbb_cron_task_simple_not_ready(); |
| 126 | } |
| 127 | |
| 128 | $this->get_cron_manager($tasks); |
| 129 | $this->command_tester = $this->get_command_tester(); |
| 130 | $this->command_tester->execute([], array('decorated' => false)); |
| 131 | } |
| 132 | } |