mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-08 04:18:52 +00:00
[ticket/11469] Use setUp() to setup DB and a buffer with size 2.
PHPBB3-11469
This commit is contained in:
parent
1bd13acb75
commit
b48c4d9549
1 changed files with 47 additions and 57 deletions
|
@ -9,6 +9,17 @@
|
||||||
|
|
||||||
class phpbb_dbal_sql_insert_buffer_test extends phpbb_database_test_case
|
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()
|
public function getDataSet()
|
||||||
{
|
{
|
||||||
return $this->createXMLDataSet(dirname(__FILE__).'/fixtures/config.xml');
|
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()
|
public function test_multi_insert_disabled_insert_and_flush()
|
||||||
{
|
{
|
||||||
$db = $this->new_dbal();
|
$this->db->multi_insert = false;
|
||||||
$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 call can be buffered
|
// 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
|
// 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()
|
public function test_multi_insert_enabled_insert_and_flush()
|
||||||
{
|
{
|
||||||
$db = $this->new_dbal();
|
if (!$this->db->multi_insert)
|
||||||
|
|
||||||
if (!$db->multi_insert)
|
|
||||||
{
|
{
|
||||||
$this->markTestSkipped('Database does not support 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(2);
|
||||||
|
|
||||||
$this->assert_config_count($db, 2);
|
|
||||||
|
|
||||||
// This call can be buffered
|
// 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
|
// 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()
|
public function test_multi_insert_disabled_insert_with_flush()
|
||||||
{
|
{
|
||||||
$db = $this->new_dbal();
|
$this->db->multi_insert = false;
|
||||||
$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($this->get_row(1)));
|
||||||
|
|
||||||
$this->assertTrue($buffer->insert($this->get_row(1)));
|
|
||||||
|
|
||||||
// This call flushes the values
|
// 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()
|
public function test_multi_insert_enabled_insert_with_flush()
|
||||||
{
|
{
|
||||||
$db = $this->new_dbal();
|
if (!$this->db->multi_insert)
|
||||||
|
|
||||||
if (!$db->multi_insert)
|
|
||||||
{
|
{
|
||||||
$this->markTestSkipped('Database does not support 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(2);
|
||||||
|
|
||||||
$this->assert_config_count($db, 2);
|
$this->assertFalse($this->buffer->insert($this->get_row(1)));
|
||||||
|
|
||||||
$this->assertFalse($buffer->insert($this->get_row(1)));
|
|
||||||
|
|
||||||
// This call flushes the values
|
// 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()
|
public function test_multi_insert_disabled_insert_all_and_flush()
|
||||||
{
|
{
|
||||||
$db = $this->new_dbal();
|
$this->db->multi_insert = false;
|
||||||
$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(5);
|
||||||
|
|
||||||
$this->assert_config_count($db, 5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_multi_insert_enabled_insert_all_and_flush()
|
public function test_multi_insert_enabled_insert_all_and_flush()
|
||||||
{
|
{
|
||||||
$db = $this->new_dbal();
|
if (!$this->db->multi_insert)
|
||||||
|
|
||||||
if (!$db->multi_insert)
|
|
||||||
{
|
{
|
||||||
$this->markTestSkipped('Database does not support 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(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(4);
|
||||||
|
|
||||||
$this->assert_config_count($db, 4);
|
|
||||||
|
|
||||||
// Manually flush
|
// 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
|
$sql = 'SELECT COUNT(*) AS num_configs
|
||||||
FROM phpbb_config';
|
FROM phpbb_config';
|
||||||
$result = $db->sql_query($sql);
|
$result = $this->db->sql_query($sql);
|
||||||
$this->assertEquals($num_configs, $db->sql_fetchfield('num_configs'));
|
$this->assertEquals($num_configs, $this->db->sql_fetchfield('num_configs'));
|
||||||
$db->sql_freeresult($result);
|
$this->db->sql_freeresult($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function get_row($rownum)
|
protected function get_row($rownum)
|
||||||
|
|
Loading…
Add table
Reference in a new issue