Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
125 / 125 |
|
100.00% |
15 / 15 |
CRAP | |
100.00% |
1 / 1 |
| phpbb_console_command_config_test | |
100.00% |
125 / 125 |
|
100.00% |
15 / 15 |
15 | |
100.00% |
1 / 1 |
| setUp | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| test_set_dynamic | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| test_set_no_dynamic | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| test_set_atomic_dynamic | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| test_set_atomic_no_dynamic | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| test_set_atomic_error_dynamic | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_no_new_line | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_new_line | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_error | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| test_increment_dynamic | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
| test_increment_no_dynamic | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
1 | |||
| test_increment_no_set | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| test_delete_ok | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| test_delete_error | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| get_command_tester | |
100.00% |
5 / 5 |
|
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 | |
| 17 | class phpbb_console_command_config_test extends phpbb_test_case |
| 18 | { |
| 19 | protected $config; |
| 20 | protected $command_name; |
| 21 | protected $user; |
| 22 | |
| 23 | protected function setUp(): void |
| 24 | { |
| 25 | $this->config = new \phpbb\config\config(array()); |
| 26 | |
| 27 | $this->user = $this->createMock('\phpbb\user'); |
| 28 | $this->user->method('lang')->will($this->returnArgument(0)); |
| 29 | } |
| 30 | |
| 31 | public function test_set_dynamic() |
| 32 | { |
| 33 | $this->assertEmpty($this->config); |
| 34 | |
| 35 | $command_tester = $this->get_command_tester('set', 'set'); |
| 36 | $command_tester->execute(array( |
| 37 | 'key' => 'test_key', |
| 38 | 'value' => 'test_value', |
| 39 | '--dynamic' => true, |
| 40 | )); |
| 41 | |
| 42 | $this->assertSame($this->config['test_key'], 'test_value'); |
| 43 | } |
| 44 | |
| 45 | public function test_set_no_dynamic() |
| 46 | { |
| 47 | $this->assertEmpty($this->config); |
| 48 | |
| 49 | $command_tester = $this->get_command_tester('set', 'set'); |
| 50 | $command_tester->execute(array( |
| 51 | 'key' => 'test_key', |
| 52 | 'value' => 'test_value', |
| 53 | '--dynamic' => false, |
| 54 | )); |
| 55 | |
| 56 | $this->assertSame($this->config['test_key'], 'test_value'); |
| 57 | } |
| 58 | |
| 59 | public function test_set_atomic_dynamic() |
| 60 | { |
| 61 | $this->assertEmpty($this->config); |
| 62 | |
| 63 | $this->config->set('test_key', 'old_value', true); |
| 64 | $this->assertSame($this->config['test_key'], 'old_value'); |
| 65 | |
| 66 | $command_tester = $this->get_command_tester('set_atomic', 'set-atomic'); |
| 67 | $command_tester->execute(array( |
| 68 | 'key' => 'test_key', |
| 69 | 'old' => 'old_value', |
| 70 | 'new' => 'new_value', |
| 71 | '--dynamic' => true, |
| 72 | )); |
| 73 | |
| 74 | $this->assertSame($this->config['test_key'], 'new_value'); |
| 75 | } |
| 76 | |
| 77 | public function test_set_atomic_no_dynamic() |
| 78 | { |
| 79 | $this->assertEmpty($this->config); |
| 80 | |
| 81 | $this->config->set('test_key', 'old_value', false); |
| 82 | $this->assertSame($this->config['test_key'], 'old_value'); |
| 83 | |
| 84 | $command_tester = $this->get_command_tester('set_atomic', 'set-atomic'); |
| 85 | $command_tester->execute(array( |
| 86 | 'key' => 'test_key', |
| 87 | 'old' => 'old_value', |
| 88 | 'new' => 'new_value', |
| 89 | '--dynamic' => false, |
| 90 | )); |
| 91 | |
| 92 | $this->assertSame($this->config['test_key'], 'new_value'); |
| 93 | } |
| 94 | |
| 95 | public function test_set_atomic_error_dynamic() |
| 96 | { |
| 97 | $this->assertEmpty($this->config); |
| 98 | |
| 99 | $this->config->set('test_key', 'wrong_value', true); |
| 100 | $this->assertSame($this->config['test_key'], 'wrong_value'); |
| 101 | |
| 102 | $command_tester = $this->get_command_tester('set_atomic', 'set-atomic'); |
| 103 | $command_tester->execute(array( |
| 104 | 'key' => 'test_key', |
| 105 | 'old' => 'old_value', |
| 106 | 'new' => 'new_value', |
| 107 | '--dynamic' => true, |
| 108 | )); |
| 109 | |
| 110 | $this->assertSame($this->config['test_key'], 'wrong_value'); |
| 111 | } |
| 112 | |
| 113 | public function test_get_no_new_line() |
| 114 | { |
| 115 | $this->config->set('test_key', 'test_value', false); |
| 116 | $this->assertSame($this->config['test_key'], 'test_value'); |
| 117 | |
| 118 | $command_tester = $this->get_command_tester('get', 'get'); |
| 119 | $command_tester->execute(array( |
| 120 | 'key' => 'test_key', |
| 121 | '--no-newline' => true, |
| 122 | )); |
| 123 | |
| 124 | $this->assertSame($this->config['test_key'], $command_tester->getDisplay()); |
| 125 | } |
| 126 | |
| 127 | public function test_get_new_line() |
| 128 | { |
| 129 | $this->config->set('test_key', 'test_value', false); |
| 130 | $this->assertSame($this->config['test_key'], 'test_value'); |
| 131 | |
| 132 | $command_tester = $this->get_command_tester('get', 'get'); |
| 133 | $command_tester->execute(array( |
| 134 | 'key' => 'test_key', |
| 135 | '--no-newline' => false, |
| 136 | )); |
| 137 | |
| 138 | $this->assertSame($this->config['test_key'] . PHP_EOL, $command_tester->getDisplay()); |
| 139 | } |
| 140 | |
| 141 | public function test_get_error() |
| 142 | { |
| 143 | $this->config->set('test_key', 'test_value', false); |
| 144 | $this->assertSame($this->config['test_key'], 'test_value'); |
| 145 | |
| 146 | $command_tester = $this->get_command_tester('get', 'get'); |
| 147 | $command_tester->execute(array( |
| 148 | 'key' => 'wrong_key', |
| 149 | '--no-newline' => false, |
| 150 | )); |
| 151 | |
| 152 | $this->assertStringContainsString('CLI_CONFIG_NOT_EXISTS', $command_tester->getDisplay()); |
| 153 | } |
| 154 | |
| 155 | public function test_increment_dynamic() |
| 156 | { |
| 157 | $this->config->set('test_key', 0, false); |
| 158 | $this->assertSame($this->config['test_key'], 0); |
| 159 | |
| 160 | $command_tester = $this->get_command_tester('increment', 'increment'); |
| 161 | $command_tester->execute(array( |
| 162 | 'key' => 'test_key', |
| 163 | 'increment' => 2, |
| 164 | '--dynamic' => true, |
| 165 | )); |
| 166 | |
| 167 | $this->assertStringContainsString('CLI_CONFIG_INCREMENT_SUCCESS', $command_tester->getDisplay()); |
| 168 | $this->assertSame(2, $this->config['test_key']); |
| 169 | } |
| 170 | |
| 171 | public function test_increment_no_dynamic() |
| 172 | { |
| 173 | $this->config->set('test_key', 0, false); |
| 174 | $this->assertSame($this->config['test_key'], 0); |
| 175 | |
| 176 | $command_tester = $this->get_command_tester('increment', 'increment'); |
| 177 | $command_tester->execute(array( |
| 178 | 'key' => 'test_key', |
| 179 | 'increment' => 2, |
| 180 | '--dynamic' => false, |
| 181 | )); |
| 182 | |
| 183 | $this->assertStringContainsString('CLI_CONFIG_INCREMENT_SUCCESS', $command_tester->getDisplay()); |
| 184 | $this->assertSame(2, $this->config['test_key']); |
| 185 | } |
| 186 | |
| 187 | public function test_increment_no_set() |
| 188 | { |
| 189 | $this->assertEmpty($this->config); |
| 190 | |
| 191 | $command_tester = $this->get_command_tester('increment', 'increment'); |
| 192 | $command_tester->execute(array( |
| 193 | 'key' => 'test_key', |
| 194 | 'increment' => 2, |
| 195 | '--dynamic' => true, |
| 196 | )); |
| 197 | |
| 198 | $this->assertStringContainsString('CLI_CONFIG_INCREMENT_SUCCESS', $command_tester->getDisplay()); |
| 199 | $this->assertSame(2, $this->config['test_key']); |
| 200 | } |
| 201 | |
| 202 | public function test_delete_ok() |
| 203 | { |
| 204 | $this->config->set('test_key', 'test_value', false); |
| 205 | $this->assertSame($this->config['test_key'], 'test_value'); |
| 206 | |
| 207 | $command_tester = $this->get_command_tester('delete', 'delete'); |
| 208 | $command_tester->execute(array( |
| 209 | 'key' => 'test_key', |
| 210 | )); |
| 211 | |
| 212 | $this->assertStringContainsString('CLI_CONFIG_DELETE_SUCCESS', $command_tester->getDisplay()); |
| 213 | $this->assertEmpty($this->config); |
| 214 | } |
| 215 | |
| 216 | public function test_delete_error() |
| 217 | { |
| 218 | $this->assertEmpty($this->config); |
| 219 | |
| 220 | $command_tester = $this->get_command_tester('delete', 'delete'); |
| 221 | $command_tester->execute(array( |
| 222 | 'key' => 'wrong_key', |
| 223 | )); |
| 224 | |
| 225 | $this->assertStringContainsString('CLI_CONFIG_NOT_EXISTS', $command_tester->getDisplay()); |
| 226 | $this->assertEmpty($this->config); |
| 227 | } |
| 228 | |
| 229 | public function get_command_tester($class_name, $command_name) |
| 230 | { |
| 231 | $command_complete_name = '\phpbb\console\command\config' . '\\' . $class_name; |
| 232 | $application = new Application(); |
| 233 | $application->add(new $command_complete_name($this->user, $this->config)); |
| 234 | $command = $application->find('config:' . $command_name); |
| 235 | return new CommandTester($command); |
| 236 | } |
| 237 | } |