aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@phpbb.com>2013-03-27 23:45:10 +0100
committerAndreas Fischer <bantu@phpbb.com>2013-03-28 00:28:50 +0100
commitb48c4d9549acaff8bbe7846b2390267ccd36d39a (patch)
treee09e4af6386294e469a1ef3eb717ade588cab7b4
parent1bd13acb753553ed5b9ab54144d0ca6507b031a3 (diff)
downloadforums-b48c4d9549acaff8bbe7846b2390267ccd36d39a.tar
forums-b48c4d9549acaff8bbe7846b2390267ccd36d39a.tar.gz
forums-b48c4d9549acaff8bbe7846b2390267ccd36d39a.tar.bz2
forums-b48c4d9549acaff8bbe7846b2390267ccd36d39a.tar.xz
forums-b48c4d9549acaff8bbe7846b2390267ccd36d39a.zip
[ticket/11469] Use setUp() to setup DB and a buffer with size 2.
PHPBB3-11469
-rw-r--r--tests/dbal/sql_insert_buffer_test.php104
1 files changed, 47 insertions, 57 deletions
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)