mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-11 05:48:51 +00:00
[ticket/11459] Correctly set up the database from schema in unit tests
PHPBB3-11459
This commit is contained in:
parent
67737345f6
commit
ba139297b5
2 changed files with 21 additions and 4 deletions
|
@ -138,7 +138,7 @@ abstract class phpbb_database_test_case extends PHPUnit_Extensions_Database_Test
|
||||||
|
|
||||||
if (!self::$already_connected)
|
if (!self::$already_connected)
|
||||||
{
|
{
|
||||||
$manager->load_schema();
|
$manager->load_schema($this->new_dbal());
|
||||||
self::$already_connected = true;
|
self::$already_connected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -169,12 +169,12 @@ class phpbb_database_test_connection_manager
|
||||||
/**
|
/**
|
||||||
* Load the phpBB database schema into the database
|
* Load the phpBB database schema into the database
|
||||||
*/
|
*/
|
||||||
public function load_schema()
|
public function load_schema($db)
|
||||||
{
|
{
|
||||||
$this->ensure_connected(__METHOD__);
|
$this->ensure_connected(__METHOD__);
|
||||||
|
|
||||||
$directory = dirname(__FILE__) . '/../../phpBB/install/schemas/';
|
$directory = dirname(__FILE__) . '/../../phpBB/install/schemas/';
|
||||||
$this->load_schema_from_file($directory);
|
$this->load_schema_from_file($directory, $db);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -321,7 +321,7 @@ class phpbb_database_test_connection_manager
|
||||||
* Compile the correct schema filename (as per create_schema_files) and
|
* Compile the correct schema filename (as per create_schema_files) and
|
||||||
* load it into the database.
|
* load it into the database.
|
||||||
*/
|
*/
|
||||||
protected function load_schema_from_file($directory)
|
protected function load_schema_from_file($directory, \phpbb\db\driver\driver $db)
|
||||||
{
|
{
|
||||||
$schema = $this->dbms['SCHEMA'];
|
$schema = $this->dbms['SCHEMA'];
|
||||||
|
|
||||||
|
@ -351,6 +351,23 @@ class phpbb_database_test_connection_manager
|
||||||
{
|
{
|
||||||
$this->pdo->exec($query);
|
$this->pdo->exec($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ok we have the db info go ahead and work on building the table
|
||||||
|
$db_table_schema = file_get_contents($directory . 'schema.json');
|
||||||
|
$db_table_schema = json_decode($db_table_schema, true);
|
||||||
|
|
||||||
|
$db_tools = new \phpbb\db\tools($db, true);
|
||||||
|
foreach ($db_table_schema as $table_name => $table_data)
|
||||||
|
{
|
||||||
|
$queries = $db_tools->sql_create_table(
|
||||||
|
$table_name,
|
||||||
|
$table_data
|
||||||
|
);
|
||||||
|
foreach ($queries as $query)
|
||||||
|
{
|
||||||
|
$this->pdo->exec($query);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue