Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
75.76% |
25 / 33 |
|
87.50% |
7 / 8 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_wrapper_phpbb_php_ini_test | |
75.76% |
25 / 33 |
|
87.50% |
7 / 8 |
10.15 | |
0.00% |
0 / 1 |
| setUp | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_string | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_bool | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_int | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_float | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_bytes_invalid | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| test_get_bytes | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| get_bytes_data | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| 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__ . '/phpbb_php_ini_fake.php'; |
| 15 | |
| 16 | class phpbb_wrapper_phpbb_php_ini_test extends phpbb_test_case |
| 17 | { |
| 18 | /** @var \phpbb_php_ini_fake php_ini */ |
| 19 | protected $php_ini; |
| 20 | |
| 21 | protected function setUp(): void |
| 22 | { |
| 23 | $this->php_ini = new phpbb_php_ini_fake; |
| 24 | } |
| 25 | |
| 26 | public function test_get_string() |
| 27 | { |
| 28 | $this->assertSame('', $this->php_ini->getString(false)); |
| 29 | $this->assertSame('phpbb', $this->php_ini->getString(' phpbb ')); |
| 30 | } |
| 31 | |
| 32 | public function test_get_bool() |
| 33 | { |
| 34 | $this->assertSame(true, $this->php_ini->getBool('ON')); |
| 35 | $this->assertSame(true, $this->php_ini->getBool('on')); |
| 36 | $this->assertSame(true, $this->php_ini->getBool('1')); |
| 37 | |
| 38 | $this->assertSame(false, $this->php_ini->getBool('OFF')); |
| 39 | $this->assertSame(false, $this->php_ini->getBool('off')); |
| 40 | $this->assertSame(false, $this->php_ini->getBool('0')); |
| 41 | $this->assertSame(false, $this->php_ini->getBool('')); |
| 42 | } |
| 43 | |
| 44 | public function test_get_int() |
| 45 | { |
| 46 | $this->assertSame(1234, $this->php_ini->getNumeric('1234')); |
| 47 | $this->assertSame(-12345, $this->php_ini->getNumeric('-12345')); |
| 48 | $this->assertSame(null, $this->php_ini->getNumeric('phpBB')); |
| 49 | } |
| 50 | |
| 51 | public function test_get_float() |
| 52 | { |
| 53 | $this->assertSame(1234.0, $this->php_ini->getNumeric('1234.0')); |
| 54 | $this->assertSame(-12345.0, $this->php_ini->getNumeric('-12345.0')); |
| 55 | $this->assertSame(null, $this->php_ini->getNumeric('phpBB')); |
| 56 | } |
| 57 | |
| 58 | public function test_get_bytes_invalid() |
| 59 | { |
| 60 | $this->assertSame(null, $this->php_ini->getBytes(false)); |
| 61 | $this->assertSame(null, $this->php_ini->getBytes('phpBB')); |
| 62 | $this->assertSame(null, $this->php_ini->getBytes('k')); |
| 63 | $this->assertSame(null, $this->php_ini->getBytes('-k')); |
| 64 | $this->assertSame(null, $this->php_ini->getBytes('M')); |
| 65 | $this->assertSame(null, $this->php_ini->getBytes('-M')); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @dataProvider get_bytes_data |
| 70 | */ |
| 71 | public function test_get_bytes($expected, $value) |
| 72 | { |
| 73 | $actual = $this->php_ini->getBytes($value); |
| 74 | |
| 75 | $this->assertTrue(is_float($actual) || is_int($actual)); |
| 76 | $this->assertEquals($expected, $actual); |
| 77 | } |
| 78 | |
| 79 | static public function get_bytes_data() |
| 80 | { |
| 81 | return array( |
| 82 | array(32 * pow(2, 20), '32m'), |
| 83 | array(- 32 * pow(2, 20), '-32m'), |
| 84 | array(8 * pow(2, 30), '8G'), |
| 85 | array(- 8 * pow(2, 30), '-8G'), |
| 86 | array(1234, '1234'), |
| 87 | array(-12345, '-12345'), |
| 88 | ); |
| 89 | } |
| 90 | } |