Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
65.31% |
32 / 49 |
|
66.67% |
8 / 12 |
CRAP | |
0.00% |
0 / 1 |
| phpbb_dbal_sql_insert_buffer_test | |
65.31% |
32 / 49 |
|
66.67% |
8 / 12 |
22.18 | |
0.00% |
0 / 1 |
| setUp | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| getDataSet | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| test_multi_insert_disabled_insert_and_flush | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| test_multi_insert_enabled_insert_and_flush | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| test_multi_insert_disabled_insert_with_flush | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| test_multi_insert_enabled_insert_with_flush | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| test_multi_insert_disabled_insert_all_and_flush | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| test_multi_insert_enabled_insert_all_and_flush | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| assert_config_count | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| check_multi_insert_support | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| get_row | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| get_rows | |
100.00% |
4 / 4 |
|
100.00% |
1 / 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 | class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case |
| 15 | { |
| 16 | protected $db; |
| 17 | protected $buffer; |
| 18 | |
| 19 | protected function setUp(): void |
| 20 | { |
| 21 | parent::setUp(); |
| 22 | |
| 23 | $this->db = $this->new_dbal(); |
| 24 | $this->buffer = new \phpbb\db\sql_insert_buffer($this->db, 'phpbb_config', 2); |
| 25 | $this->assert_config_count(2); |
| 26 | } |
| 27 | |
| 28 | public function getDataSet() |
| 29 | { |
| 30 | return $this->createXMLDataSet(__DIR__ . '/fixtures/config.xml'); |
| 31 | } |
| 32 | |
| 33 | public function test_multi_insert_disabled_insert_and_flush() |
| 34 | { |
| 35 | $this->db->set_multi_insert(false); |
| 36 | $this->assertTrue($this->buffer->insert($this->get_row(1))); |
| 37 | $this->assert_config_count(3); |
| 38 | $this->assertFalse($this->buffer->flush()); |
| 39 | $this->assert_config_count(3); |
| 40 | } |
| 41 | |
| 42 | public function test_multi_insert_enabled_insert_and_flush() |
| 43 | { |
| 44 | $this->check_multi_insert_support(); |
| 45 | $this->assertFalse($this->buffer->insert($this->get_row(1))); |
| 46 | $this->assert_config_count(2); |
| 47 | $this->assertTrue($this->buffer->flush()); |
| 48 | $this->assert_config_count(3); |
| 49 | } |
| 50 | |
| 51 | public function test_multi_insert_disabled_insert_with_flush() |
| 52 | { |
| 53 | $this->db->set_multi_insert(false); |
| 54 | $this->assertTrue($this->buffer->insert($this->get_row(1))); |
| 55 | $this->assert_config_count(3); |
| 56 | $this->assertTrue($this->buffer->insert($this->get_row(2))); |
| 57 | $this->assert_config_count(4); |
| 58 | } |
| 59 | |
| 60 | public function test_multi_insert_enabled_insert_with_flush() |
| 61 | { |
| 62 | $this->check_multi_insert_support(); |
| 63 | $this->assertFalse($this->buffer->insert($this->get_row(1))); |
| 64 | $this->assert_config_count(2); |
| 65 | $this->assertTrue($this->buffer->insert($this->get_row(2))); |
| 66 | $this->assert_config_count(4); |
| 67 | } |
| 68 | |
| 69 | public function test_multi_insert_disabled_insert_all_and_flush() |
| 70 | { |
| 71 | $this->db->set_multi_insert(false); |
| 72 | $this->assertTrue($this->buffer->insert_all($this->get_rows(3))); |
| 73 | $this->assert_config_count(5); |
| 74 | } |
| 75 | |
| 76 | public function test_multi_insert_enabled_insert_all_and_flush() |
| 77 | { |
| 78 | $this->check_multi_insert_support(); |
| 79 | $this->assertTrue($this->buffer->insert_all($this->get_rows(3))); |
| 80 | $this->assert_config_count(4); |
| 81 | $this->assertTrue($this->buffer->flush()); |
| 82 | $this->assert_config_count(5); |
| 83 | } |
| 84 | |
| 85 | protected function assert_config_count($num_configs) |
| 86 | { |
| 87 | $sql = 'SELECT COUNT(*) AS num_configs |
| 88 | FROM phpbb_config'; |
| 89 | $result = $this->db->sql_query($sql); |
| 90 | $this->assertEquals($num_configs, $this->db->sql_fetchfield('num_configs')); |
| 91 | $this->db->sql_freeresult($result); |
| 92 | } |
| 93 | |
| 94 | protected function check_multi_insert_support() |
| 95 | { |
| 96 | if (!$this->db->get_multi_insert()) |
| 97 | { |
| 98 | $this->markTestSkipped('Database does not support multi_insert'); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | protected function get_row($rownum) |
| 103 | { |
| 104 | return array( |
| 105 | 'config_name' => "name$rownum", |
| 106 | 'config_value' => "value$rownum", |
| 107 | 'is_dynamic' => '0', |
| 108 | ); |
| 109 | } |
| 110 | |
| 111 | protected function get_rows($n) |
| 112 | { |
| 113 | $result = array(); |
| 114 | for ($i = 0; $i < $n; ++$i) |
| 115 | { |
| 116 | $result[] = $this->get_row($i); |
| 117 | } |
| 118 | return $result; |
| 119 | } |
| 120 | } |