From 8dd26dee8349a14abac00db6ad5039d7517bda57 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 27 Mar 2013 11:45:45 +0100 Subject: [ticket/11469] Add some basic unit tests for phpbb_db_sql_insert_buffer PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 176 ++++++++++++++++++++++++++++++++++ 1 file changed, 176 insertions(+) create mode 100644 tests/dbal/sql_insert_buffer_test.php (limited to 'tests/dbal/sql_insert_buffer_test.php') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php new file mode 100644 index 0000000000..a67ccbe89f --- /dev/null +++ b/tests/dbal/sql_insert_buffer_test.php @@ -0,0 +1,176 @@ +createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); + } + + public function insert_buffer_data() + { + $db = $this->new_dbal(); + + if ($db->multi_insert) + { + // Test with enabled and disabled multi_insert + return array( + array(true), + array(false), + ); + } + else + { + // Only test with disabled multi_insert, the DB doesn't support it + return array( + array(false), + ); + } + } + + /** + * @dataProvider insert_buffer_data + */ + public function test_insert_and_flush($force_multi_insert) + { + $db = $this->new_dbal(); + $db->multi_insert = $force_multi_insert; + + $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(2, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + + // This call can be buffered + $buffer->insert(array( + 'config_name' => 'name1', + 'config_value' => 'value1', + 'is_dynamic' => '0', + )); + + if ($db->multi_insert) + { + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(2, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + } + else + { + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(3, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + } + + // Manually flush + $buffer->flush(); + + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(3, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + } + + /** + * @dataProvider insert_buffer_data + */ + public function test_insert_with_flush($force_multi_insert) + { + $db = $this->new_dbal(); + $db->multi_insert = $force_multi_insert; + + $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(2, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + + $buffer->insert(array( + 'config_name' => 'name1', + 'config_value' => 'value1', + 'is_dynamic' => '0', + )); + + // This call flushes the values + $buffer->insert(array( + 'config_name' => 'name2', + 'config_value' => 'value2', + 'is_dynamic' => '0', + )); + + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(4, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + } + + /** + * @dataProvider insert_buffer_data + */ + public function test_insert_all_and_flush($force_multi_insert) + { + $db = $this->new_dbal(); + $db->multi_insert = $force_multi_insert; + + $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(2, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + + $buffer->insert_all(array( + array( + 'config_name' => 'name1', + 'config_value' => 'value1', + 'is_dynamic' => '0', + ), + array( + 'config_name' => 'name2', + 'config_value' => 'value2', + 'is_dynamic' => '0', + ), + array( + 'config_name' => 'name3', + 'config_value' => 'value3', + 'is_dynamic' => '0', + ), + )); + + if ($db->multi_insert) + { + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(4, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + + // Manually flush + $buffer->flush(); + } + + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query_limit($sql, 1); + $this->assertEquals(5, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + } +} -- cgit v1.2.1 From af9f30cd52fd7b53b17b946a0c646fd72c4a6f4f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 27 Mar 2013 14:09:04 +0100 Subject: [ticket/11469] Use method to check config count, instead of repeating it PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 63 ++++++++++------------------------- 1 file changed, 18 insertions(+), 45 deletions(-) (limited to 'tests/dbal/sql_insert_buffer_test.php') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index a67ccbe89f..e3ee767937 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -14,6 +14,15 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); } + protected function assert_config_count($db, $num_configs) + { + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query($sql); + $this->assertEquals($num_configs, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + } + public function insert_buffer_data() { $db = $this->new_dbal(); @@ -45,11 +54,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(2, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 2); // This call can be buffered $buffer->insert(array( @@ -60,29 +65,17 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case if ($db->multi_insert) { - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(2, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 2); } else { - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(3, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 3); } // Manually flush $buffer->flush(); - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(3, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 3); } /** @@ -95,11 +88,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(2, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 2); $buffer->insert(array( 'config_name' => 'name1', @@ -114,11 +103,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case 'is_dynamic' => '0', )); - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(4, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 4); } /** @@ -131,11 +116,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(2, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 2); $buffer->insert_all(array( array( @@ -157,20 +138,12 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case if ($db->multi_insert) { - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(4, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 4); // Manually flush $buffer->flush(); } - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query_limit($sql, 1); - $this->assertEquals(5, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $this->assert_config_count($db, 5); } } -- cgit v1.2.1 From 9606ccc2021e7e169473d92306e28680e4b9f966 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 27 Mar 2013 20:54:20 +0100 Subject: [ticket/11469] Split tests and skip multi_insert if unavailable PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 139 +++++++++++++++++++++++----------- 1 file changed, 95 insertions(+), 44 deletions(-) (limited to 'tests/dbal/sql_insert_buffer_test.php') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index e3ee767937..bdf3544bbc 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -23,34 +23,38 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $db->sql_freeresult($result); } - public function insert_buffer_data() + public function test_multi_insert_disabled_insert_and_flush() { $db = $this->new_dbal(); + $db->multi_insert = false; - if ($db->multi_insert) - { - // Test with enabled and disabled multi_insert - return array( - array(true), - array(false), - ); - } - else - { - // Only test with disabled multi_insert, the DB doesn't support it - return array( - array(false), - ); - } + $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + + $this->assert_config_count($db, 2); + + // This call can be buffered + $buffer->insert(array( + 'config_name' => 'name1', + 'config_value' => 'value1', + 'is_dynamic' => '0', + )); + + $this->assert_config_count($db, 3); + + // Manually flush + $buffer->flush(); + + $this->assert_config_count($db, 3); } - /** - * @dataProvider insert_buffer_data - */ - public function test_insert_and_flush($force_multi_insert) + public function test_multi_insert_enabled_insert_and_flush() { $db = $this->new_dbal(); - $db->multi_insert = $force_multi_insert; + + if (!$db->multi_insert) + { + $this->markTestSkipped('Database does not support multi_insert'); + } $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); @@ -63,14 +67,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case 'is_dynamic' => '0', )); - if ($db->multi_insert) - { - $this->assert_config_count($db, 2); - } - else - { - $this->assert_config_count($db, 3); - } + $this->assert_config_count($db, 2); // Manually flush $buffer->flush(); @@ -78,13 +75,10 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 3); } - /** - * @dataProvider insert_buffer_data - */ - public function test_insert_with_flush($force_multi_insert) + public function test_multi_insert_disabled_insert_with_flush() { $db = $this->new_dbal(); - $db->multi_insert = $force_multi_insert; + $db->multi_insert = false; $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); @@ -106,13 +100,39 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 4); } - /** - * @dataProvider insert_buffer_data - */ - public function test_insert_all_and_flush($force_multi_insert) + public function test_multi_insert_enabled_insert_with_flush() { $db = $this->new_dbal(); - $db->multi_insert = $force_multi_insert; + + if (!$db->multi_insert) + { + $this->markTestSkipped('Database does not support multi_insert'); + } + + $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + + $this->assert_config_count($db, 2); + + $buffer->insert(array( + 'config_name' => 'name1', + 'config_value' => 'value1', + 'is_dynamic' => '0', + )); + + // This call flushes the values + $buffer->insert(array( + 'config_name' => 'name2', + 'config_value' => 'value2', + 'is_dynamic' => '0', + )); + + $this->assert_config_count($db, 4); + } + + public function test_multi_insert_disabled_insert_all_and_flush() + { + $db = $this->new_dbal(); + $db->multi_insert = false; $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); @@ -136,14 +156,45 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case ), )); - if ($db->multi_insert) - { - $this->assert_config_count($db, 4); + $this->assert_config_count($db, 5); + } + + public function test_multi_insert_enabled_insert_all_and_flush() + { + $db = $this->new_dbal(); - // Manually flush - $buffer->flush(); + if (!$db->multi_insert) + { + $this->markTestSkipped('Database does not support multi_insert'); } + $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + + $this->assert_config_count($db, 2); + + $buffer->insert_all(array( + array( + 'config_name' => 'name1', + 'config_value' => 'value1', + 'is_dynamic' => '0', + ), + array( + 'config_name' => 'name2', + 'config_value' => 'value2', + 'is_dynamic' => '0', + ), + array( + 'config_name' => 'name3', + 'config_value' => 'value3', + 'is_dynamic' => '0', + ), + )); + + $this->assert_config_count($db, 4); + + // Manually flush + $buffer->flush(); + $this->assert_config_count($db, 5); } } -- cgit v1.2.1 From 69ad4aab787db4c80c431c412a76d731a1abdf63 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 27 Mar 2013 20:55:08 +0100 Subject: [ticket/11469] Check return values of the functions PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 38 +++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'tests/dbal/sql_insert_buffer_test.php') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index bdf3544bbc..fd92ca9bba 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -33,16 +33,16 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); // This call can be buffered - $buffer->insert(array( + $this->assertTrue($buffer->insert(array( 'config_name' => 'name1', 'config_value' => 'value1', 'is_dynamic' => '0', - )); + ))); $this->assert_config_count($db, 3); // Manually flush - $buffer->flush(); + $this->assertFalse($buffer->flush()); $this->assert_config_count($db, 3); } @@ -61,16 +61,16 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); // This call can be buffered - $buffer->insert(array( + $this->assertFalse($buffer->insert(array( 'config_name' => 'name1', 'config_value' => 'value1', 'is_dynamic' => '0', - )); + ))); $this->assert_config_count($db, 2); // Manually flush - $buffer->flush(); + $this->assertTrue($buffer->flush()); $this->assert_config_count($db, 3); } @@ -84,18 +84,18 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); - $buffer->insert(array( + $this->assertTrue($buffer->insert(array( 'config_name' => 'name1', 'config_value' => 'value1', 'is_dynamic' => '0', - )); + ))); // This call flushes the values - $buffer->insert(array( + $this->assertTrue($buffer->insert(array( 'config_name' => 'name2', 'config_value' => 'value2', 'is_dynamic' => '0', - )); + ))); $this->assert_config_count($db, 4); } @@ -113,18 +113,18 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); - $buffer->insert(array( + $this->assertFalse($buffer->insert(array( 'config_name' => 'name1', 'config_value' => 'value1', 'is_dynamic' => '0', - )); + ))); // This call flushes the values - $buffer->insert(array( + $this->assertTrue($buffer->insert(array( 'config_name' => 'name2', 'config_value' => 'value2', 'is_dynamic' => '0', - )); + ))); $this->assert_config_count($db, 4); } @@ -138,7 +138,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); - $buffer->insert_all(array( + $this->assertTrue($buffer->insert_all(array( array( 'config_name' => 'name1', 'config_value' => 'value1', @@ -154,7 +154,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case 'config_value' => 'value3', 'is_dynamic' => '0', ), - )); + ))); $this->assert_config_count($db, 5); } @@ -172,7 +172,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); - $buffer->insert_all(array( + $this->assertTrue($buffer->insert_all(array( array( 'config_name' => 'name1', 'config_value' => 'value1', @@ -188,12 +188,12 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case 'config_value' => 'value3', 'is_dynamic' => '0', ), - )); + ))); $this->assert_config_count($db, 4); // Manually flush - $buffer->flush(); + $this->assertTrue($buffer->flush()); $this->assert_config_count($db, 5); } -- cgit v1.2.1 From a534497d82cb9febaa18ee6c858ef68217bc2d14 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 27 Mar 2013 23:21:29 +0100 Subject: [ticket/11469] Move protected method to end of test file. PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'tests/dbal/sql_insert_buffer_test.php') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index fd92ca9bba..0cf476b14a 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -14,15 +14,6 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); } - protected function assert_config_count($db, $num_configs) - { - $sql = 'SELECT COUNT(*) AS num_configs - FROM phpbb_config'; - $result = $db->sql_query($sql); - $this->assertEquals($num_configs, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); - } - public function test_multi_insert_disabled_insert_and_flush() { $db = $this->new_dbal(); @@ -197,4 +188,13 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 5); } + + protected function assert_config_count($db, $num_configs) + { + $sql = 'SELECT COUNT(*) AS num_configs + FROM phpbb_config'; + $result = $db->sql_query($sql); + $this->assertEquals($num_configs, $db->sql_fetchfield('num_configs')); + $db->sql_freeresult($result); + } } -- cgit v1.2.1 From 873f098b6ccc108dc293054f2cf7cb7231684caa Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 27 Mar 2013 23:30:23 +0100 Subject: [ticket/11469] Do not repeat array with three rows. PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 57 ++++++++++++++--------------------- 1 file changed, 23 insertions(+), 34 deletions(-) (limited to 'tests/dbal/sql_insert_buffer_test.php') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index 0cf476b14a..59bfb73d0f 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -129,23 +129,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); - $this->assertTrue($buffer->insert_all(array( - array( - 'config_name' => 'name1', - 'config_value' => 'value1', - 'is_dynamic' => '0', - ), - array( - 'config_name' => 'name2', - 'config_value' => 'value2', - 'is_dynamic' => '0', - ), - array( - 'config_name' => 'name3', - 'config_value' => 'value3', - 'is_dynamic' => '0', - ), - ))); + $this->assertTrue($buffer->insert_all($this->get_three_rows())); $this->assert_config_count($db, 5); } @@ -163,23 +147,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); - $this->assertTrue($buffer->insert_all(array( - array( - 'config_name' => 'name1', - 'config_value' => 'value1', - 'is_dynamic' => '0', - ), - array( - 'config_name' => 'name2', - 'config_value' => 'value2', - 'is_dynamic' => '0', - ), - array( - 'config_name' => 'name3', - 'config_value' => 'value3', - 'is_dynamic' => '0', - ), - ))); + $this->assertTrue($buffer->insert_all($this->get_three_rows())); $this->assert_config_count($db, 4); @@ -197,4 +165,25 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assertEquals($num_configs, $db->sql_fetchfield('num_configs')); $db->sql_freeresult($result); } + + protected function get_three_rows() + { + return array( + array( + 'config_name' => 'name1', + 'config_value' => 'value1', + 'is_dynamic' => '0', + ), + array( + 'config_name' => 'name2', + 'config_value' => 'value2', + 'is_dynamic' => '0', + ), + array( + 'config_name' => 'name3', + 'config_value' => 'value3', + 'is_dynamic' => '0', + ), + ); + } } -- cgit v1.2.1 From b88eb3c8e099e1a0634ab84e9e1c215c00410264 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 27 Mar 2013 23:33:13 +0100 Subject: [ticket/11469] Do not repeat row generation. PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 63 ++++++++++------------------------- 1 file changed, 18 insertions(+), 45 deletions(-) (limited to 'tests/dbal/sql_insert_buffer_test.php') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index 59bfb73d0f..650a42c36d 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -24,11 +24,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); // This call can be buffered - $this->assertTrue($buffer->insert(array( - 'config_name' => 'name1', - 'config_value' => 'value1', - 'is_dynamic' => '0', - ))); + $this->assertTrue($buffer->insert($this->get_row(1))); $this->assert_config_count($db, 3); @@ -52,11 +48,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); // This call can be buffered - $this->assertFalse($buffer->insert(array( - 'config_name' => 'name1', - 'config_value' => 'value1', - 'is_dynamic' => '0', - ))); + $this->assertFalse($buffer->insert($this->get_row(1))); $this->assert_config_count($db, 2); @@ -75,18 +67,10 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); - $this->assertTrue($buffer->insert(array( - 'config_name' => 'name1', - 'config_value' => 'value1', - 'is_dynamic' => '0', - ))); + $this->assertTrue($buffer->insert($this->get_row(1))); // This call flushes the values - $this->assertTrue($buffer->insert(array( - 'config_name' => 'name2', - 'config_value' => 'value2', - 'is_dynamic' => '0', - ))); + $this->assertTrue($buffer->insert($this->get_row(2))); $this->assert_config_count($db, 4); } @@ -104,18 +88,10 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->assert_config_count($db, 2); - $this->assertFalse($buffer->insert(array( - 'config_name' => 'name1', - 'config_value' => 'value1', - 'is_dynamic' => '0', - ))); + $this->assertFalse($buffer->insert($this->get_row(1))); // This call flushes the values - $this->assertTrue($buffer->insert(array( - 'config_name' => 'name2', - 'config_value' => 'value2', - 'is_dynamic' => '0', - ))); + $this->assertTrue($buffer->insert($this->get_row(2))); $this->assert_config_count($db, 4); } @@ -166,24 +142,21 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $db->sql_freeresult($result); } + protected function get_row($rownum) + { + return array( + 'config_name' => "name$rownum", + 'config_value' => "value$rownum", + 'is_dynamic' => '0', + ); + } + protected function get_three_rows() { return array( - array( - 'config_name' => 'name1', - 'config_value' => 'value1', - 'is_dynamic' => '0', - ), - array( - 'config_name' => 'name2', - 'config_value' => 'value2', - 'is_dynamic' => '0', - ), - array( - 'config_name' => 'name3', - 'config_value' => 'value3', - 'is_dynamic' => '0', - ), + $this->get_row(1), + $this->get_row(2), + $this->get_row(3), ); } } -- cgit v1.2.1 From b48c4d9549acaff8bbe7846b2390267ccd36d39a Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 27 Mar 2013 23:45:10 +0100 Subject: [ticket/11469] Use setUp() to setup DB and a buffer with size 2. PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 104 +++++++++++++++------------------- 1 file changed, 47 insertions(+), 57 deletions(-) (limited to 'tests/dbal/sql_insert_buffer_test.php') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index 650a42c36d..bc6508b30a 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -9,6 +9,17 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case { + protected $db; + protected $buffer; + + public function setUp() + { + parent::setUp(); + + $this->db = $this->new_dbal(); + $this->buffer = new phpbb_db_sql_insert_buffer($this->db, 'phpbb_config', 2); + } + public function getDataSet() { return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); @@ -16,130 +27,109 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case public function test_multi_insert_disabled_insert_and_flush() { - $db = $this->new_dbal(); - $db->multi_insert = false; - - $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + $this->db->multi_insert = false; - $this->assert_config_count($db, 2); + $this->assert_config_count(2); // This call can be buffered - $this->assertTrue($buffer->insert($this->get_row(1))); + $this->assertTrue($this->buffer->insert($this->get_row(1))); - $this->assert_config_count($db, 3); + $this->assert_config_count(3); // Manually flush - $this->assertFalse($buffer->flush()); + $this->assertFalse($this->buffer->flush()); - $this->assert_config_count($db, 3); + $this->assert_config_count(3); } public function test_multi_insert_enabled_insert_and_flush() { - $db = $this->new_dbal(); - - if (!$db->multi_insert) + if (!$this->db->multi_insert) { $this->markTestSkipped('Database does not support multi_insert'); } - $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); - - $this->assert_config_count($db, 2); + $this->assert_config_count(2); // This call can be buffered - $this->assertFalse($buffer->insert($this->get_row(1))); + $this->assertFalse($this->buffer->insert($this->get_row(1))); - $this->assert_config_count($db, 2); + $this->assert_config_count(2); // Manually flush - $this->assertTrue($buffer->flush()); + $this->assertTrue($this->buffer->flush()); - $this->assert_config_count($db, 3); + $this->assert_config_count(3); } public function test_multi_insert_disabled_insert_with_flush() { - $db = $this->new_dbal(); - $db->multi_insert = false; - - $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + $this->db->multi_insert = false; - $this->assert_config_count($db, 2); + $this->assert_config_count(2); - $this->assertTrue($buffer->insert($this->get_row(1))); + $this->assertTrue($this->buffer->insert($this->get_row(1))); // This call flushes the values - $this->assertTrue($buffer->insert($this->get_row(2))); + $this->assertTrue($this->buffer->insert($this->get_row(2))); - $this->assert_config_count($db, 4); + $this->assert_config_count(4); } public function test_multi_insert_enabled_insert_with_flush() { - $db = $this->new_dbal(); - - if (!$db->multi_insert) + if (!$this->db->multi_insert) { $this->markTestSkipped('Database does not support multi_insert'); } - $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); - - $this->assert_config_count($db, 2); + $this->assert_config_count(2); - $this->assertFalse($buffer->insert($this->get_row(1))); + $this->assertFalse($this->buffer->insert($this->get_row(1))); // This call flushes the values - $this->assertTrue($buffer->insert($this->get_row(2))); + $this->assertTrue($this->buffer->insert($this->get_row(2))); - $this->assert_config_count($db, 4); + $this->assert_config_count(4); } public function test_multi_insert_disabled_insert_all_and_flush() { - $db = $this->new_dbal(); - $db->multi_insert = false; + $this->db->multi_insert = false; - $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); + $this->assert_config_count(2); - $this->assert_config_count($db, 2); + $this->assertTrue($this->buffer->insert_all($this->get_three_rows())); - $this->assertTrue($buffer->insert_all($this->get_three_rows())); - - $this->assert_config_count($db, 5); + $this->assert_config_count(5); } public function test_multi_insert_enabled_insert_all_and_flush() { - $db = $this->new_dbal(); - - if (!$db->multi_insert) + if (!$this->db->multi_insert) { $this->markTestSkipped('Database does not support multi_insert'); } - $buffer = new phpbb_db_sql_insert_buffer($db, 'phpbb_config', 2); - - $this->assert_config_count($db, 2); + $this->assert_config_count(2); - $this->assertTrue($buffer->insert_all($this->get_three_rows())); + $this->assertTrue($this->buffer->insert_all($this->get_three_rows())); - $this->assert_config_count($db, 4); + $this->assert_config_count(4); // Manually flush - $this->assertTrue($buffer->flush()); + $this->assertTrue($this->buffer->flush()); - $this->assert_config_count($db, 5); + $this->assert_config_count(5); } - protected function assert_config_count($db, $num_configs) + protected function assert_config_count($num_configs) { $sql = 'SELECT COUNT(*) AS num_configs FROM phpbb_config'; - $result = $db->sql_query($sql); - $this->assertEquals($num_configs, $db->sql_fetchfield('num_configs')); - $db->sql_freeresult($result); + $result = $this->db->sql_query($sql); + $this->assertEquals($num_configs, $this->db->sql_fetchfield('num_configs')); + $this->db->sql_freeresult($result); } protected function get_row($rownum) -- cgit v1.2.1 From c909d9602b8a8d91d9c6cd72e01c1ddf21dcf593 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 27 Mar 2013 23:46:39 +0100 Subject: [ticket/11469] Do not repeat assert_config_count(2). Also move to setUp(). PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'tests/dbal/sql_insert_buffer_test.php') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index bc6508b30a..4aad852149 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -18,6 +18,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->db = $this->new_dbal(); $this->buffer = new phpbb_db_sql_insert_buffer($this->db, 'phpbb_config', 2); + $this->assert_config_count(2); } public function getDataSet() @@ -29,8 +30,6 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case { $this->db->multi_insert = false; - $this->assert_config_count(2); - // This call can be buffered $this->assertTrue($this->buffer->insert($this->get_row(1))); @@ -49,8 +48,6 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->markTestSkipped('Database does not support multi_insert'); } - $this->assert_config_count(2); - // This call can be buffered $this->assertFalse($this->buffer->insert($this->get_row(1))); @@ -66,8 +63,6 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case { $this->db->multi_insert = false; - $this->assert_config_count(2); - $this->assertTrue($this->buffer->insert($this->get_row(1))); // This call flushes the values @@ -83,8 +78,6 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->markTestSkipped('Database does not support multi_insert'); } - $this->assert_config_count(2); - $this->assertFalse($this->buffer->insert($this->get_row(1))); // This call flushes the values @@ -97,8 +90,6 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case { $this->db->multi_insert = false; - $this->assert_config_count(2); - $this->assertTrue($this->buffer->insert_all($this->get_three_rows())); $this->assert_config_count(5); @@ -111,8 +102,6 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->markTestSkipped('Database does not support multi_insert'); } - $this->assert_config_count(2); - $this->assertTrue($this->buffer->insert_all($this->get_three_rows())); $this->assert_config_count(4); -- cgit v1.2.1 From eacd0f3e7d200924a1d98d1ce34a454eda707dd4 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 27 Mar 2013 23:48:48 +0100 Subject: [ticket/11469] Fix spacing in getDataSet(). PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/dbal/sql_insert_buffer_test.php') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index 4aad852149..bd03fb9c05 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -23,7 +23,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case public function getDataSet() { - return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml'); + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/config.xml'); } public function test_multi_insert_disabled_insert_and_flush() -- cgit v1.2.1 From 6f946e2188d08bdc939e56143bff9e663c0b6931 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 27 Mar 2013 23:53:03 +0100 Subject: [ticket/11469] Refactor get_three_rows() into get_rows($n). PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'tests/dbal/sql_insert_buffer_test.php') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index bd03fb9c05..f06df26b0c 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -90,7 +90,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case { $this->db->multi_insert = false; - $this->assertTrue($this->buffer->insert_all($this->get_three_rows())); + $this->assertTrue($this->buffer->insert_all($this->get_rows(3))); $this->assert_config_count(5); } @@ -102,7 +102,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->markTestSkipped('Database does not support multi_insert'); } - $this->assertTrue($this->buffer->insert_all($this->get_three_rows())); + $this->assertTrue($this->buffer->insert_all($this->get_rows(3))); $this->assert_config_count(4); @@ -130,12 +130,13 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case ); } - protected function get_three_rows() + protected function get_rows($n) { - return array( - $this->get_row(1), - $this->get_row(2), - $this->get_row(3), - ); + $result = array(); + for ($i = 0; $i < $n; ++$i) + { + $result[] = $this->get_row($i); + } + return $result; } } -- cgit v1.2.1 From a04fe625a86c0b1fcc037687afec39c659fbd830 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 27 Mar 2013 23:55:26 +0100 Subject: [ticket/11469] Do not repeat markTestSkipped() message. PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'tests/dbal/sql_insert_buffer_test.php') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index f06df26b0c..9357278a62 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -43,10 +43,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case public function test_multi_insert_enabled_insert_and_flush() { - if (!$this->db->multi_insert) - { - $this->markTestSkipped('Database does not support multi_insert'); - } + $this->check_multi_insert_support(); // This call can be buffered $this->assertFalse($this->buffer->insert($this->get_row(1))); @@ -73,10 +70,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case public function test_multi_insert_enabled_insert_with_flush() { - if (!$this->db->multi_insert) - { - $this->markTestSkipped('Database does not support multi_insert'); - } + $this->check_multi_insert_support(); $this->assertFalse($this->buffer->insert($this->get_row(1))); @@ -97,10 +91,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case public function test_multi_insert_enabled_insert_all_and_flush() { - if (!$this->db->multi_insert) - { - $this->markTestSkipped('Database does not support multi_insert'); - } + $this->check_multi_insert_support(); $this->assertTrue($this->buffer->insert_all($this->get_rows(3))); @@ -121,6 +112,14 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case $this->db->sql_freeresult($result); } + protected function check_multi_insert_support() + { + if (!$this->db->multi_insert) + { + $this->markTestSkipped('Database does not support multi_insert'); + } + } + protected function get_row($rownum) { return array( -- cgit v1.2.1 From e022a7e8f602de67472e4ea5b6ecb6280f4054e4 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 28 Mar 2013 00:03:48 +0100 Subject: [ticket/11469] Remove comments. Method names should be good enough now. PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 27 --------------------------- 1 file changed, 27 deletions(-) (limited to 'tests/dbal/sql_insert_buffer_test.php') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index 9357278a62..04ef6a3d52 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -29,77 +29,50 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case public function test_multi_insert_disabled_insert_and_flush() { $this->db->multi_insert = false; - - // This call can be buffered $this->assertTrue($this->buffer->insert($this->get_row(1))); - $this->assert_config_count(3); - - // Manually flush $this->assertFalse($this->buffer->flush()); - $this->assert_config_count(3); } public function test_multi_insert_enabled_insert_and_flush() { $this->check_multi_insert_support(); - - // This call can be buffered $this->assertFalse($this->buffer->insert($this->get_row(1))); - $this->assert_config_count(2); - - // Manually flush $this->assertTrue($this->buffer->flush()); - $this->assert_config_count(3); } public function test_multi_insert_disabled_insert_with_flush() { $this->db->multi_insert = false; - $this->assertTrue($this->buffer->insert($this->get_row(1))); - - // This call flushes the values $this->assertTrue($this->buffer->insert($this->get_row(2))); - $this->assert_config_count(4); } public function test_multi_insert_enabled_insert_with_flush() { $this->check_multi_insert_support(); - $this->assertFalse($this->buffer->insert($this->get_row(1))); - - // This call flushes the values $this->assertTrue($this->buffer->insert($this->get_row(2))); - $this->assert_config_count(4); } public function test_multi_insert_disabled_insert_all_and_flush() { $this->db->multi_insert = false; - $this->assertTrue($this->buffer->insert_all($this->get_rows(3))); - $this->assert_config_count(5); } public function test_multi_insert_enabled_insert_all_and_flush() { $this->check_multi_insert_support(); - $this->assertTrue($this->buffer->insert_all($this->get_rows(3))); - $this->assert_config_count(4); - - // Manually flush $this->assertTrue($this->buffer->flush()); - $this->assert_config_count(5); } -- cgit v1.2.1 From e3a6935de6185bde189e53452fca024ef9474c1b Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Thu, 28 Mar 2013 00:20:24 +0100 Subject: [ticket/11469] Add more table status assertions. PHPBB3-11469 --- tests/dbal/sql_insert_buffer_test.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/dbal/sql_insert_buffer_test.php') diff --git a/tests/dbal/sql_insert_buffer_test.php b/tests/dbal/sql_insert_buffer_test.php index 04ef6a3d52..45339a6b50 100644 --- a/tests/dbal/sql_insert_buffer_test.php +++ b/tests/dbal/sql_insert_buffer_test.php @@ -48,6 +48,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case { $this->db->multi_insert = false; $this->assertTrue($this->buffer->insert($this->get_row(1))); + $this->assert_config_count(3); $this->assertTrue($this->buffer->insert($this->get_row(2))); $this->assert_config_count(4); } @@ -56,6 +57,7 @@ class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case { $this->check_multi_insert_support(); $this->assertFalse($this->buffer->insert($this->get_row(1))); + $this->assert_config_count(2); $this->assertTrue($this->buffer->insert($this->get_row(2))); $this->assert_config_count(4); } -- cgit v1.2.1