mirror of
https://github.com/phpbb/phpbb.git
synced 2025-08-10 18:54:08 +02:00
[ticket/16741] Test fixes
PHPBB3-16741
This commit is contained in:
@@ -31,6 +31,11 @@ abstract class phpbb_database_test_case extends TestCase
|
||||
|
||||
protected static $phpunit_version;
|
||||
|
||||
/**
|
||||
* @var \Doctrine\DBAL\Connection[]
|
||||
*/
|
||||
private $db_connections_doctrine;
|
||||
|
||||
public function __construct($name = NULL, array $data = [], $dataName = '')
|
||||
{
|
||||
parent::__construct($name, $data, $dataName);
|
||||
@@ -58,6 +63,7 @@ abstract class phpbb_database_test_case extends TestCase
|
||||
}
|
||||
|
||||
$this->db_connections = [];
|
||||
$this->db_connections_doctrine = [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,8 +98,9 @@ abstract class phpbb_database_test_case extends TestCase
|
||||
global $table_prefix;
|
||||
|
||||
$db = new \phpbb\db\driver\sqlite3();
|
||||
$doctrine = \phpbb\db\doctrine\connection_factory::get_connection(new phpbb_mock_config_php_file());
|
||||
$factory = new \phpbb\db\tools\factory();
|
||||
$db_tools = $factory->get($db, true);
|
||||
$db_tools = $factory->get($doctrine, true);
|
||||
|
||||
$schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, $db_tools, $phpbb_root_path, $phpEx, $table_prefix, self::get_core_tables());
|
||||
file_put_contents(self::$schema_file, json_encode($schema_generator->get_schema()));
|
||||
@@ -126,6 +133,14 @@ abstract class phpbb_database_test_case extends TestCase
|
||||
$db->sql_close();
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($this->db_connections_doctrine))
|
||||
{
|
||||
foreach ($this->db_connections_doctrine as $db)
|
||||
{
|
||||
$db->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
@@ -277,7 +292,7 @@ abstract class phpbb_database_test_case extends TestCase
|
||||
|
||||
if (!self::$already_connected)
|
||||
{
|
||||
$manager->load_schema($this->new_dbal());
|
||||
$manager->load_schema($this->new_dbal(), $this->new_doctrine_dbal());
|
||||
self::$already_connected = true;
|
||||
}
|
||||
|
||||
@@ -296,6 +311,16 @@ abstract class phpbb_database_test_case extends TestCase
|
||||
return $db;
|
||||
}
|
||||
|
||||
public function new_doctrine_dbal(): \Doctrine\DBAL\Connection
|
||||
{
|
||||
$config = $this->get_database_config();
|
||||
|
||||
$db = \phpbb\db\doctrine\connection_factory::get_connection_from_params($config['dbms'], $config['dbhost'], $config['dbuser'], $config['dbpasswd'], $config['dbname'], $config['dbport']);
|
||||
$this->db_connections_doctrine[] = $db;
|
||||
|
||||
return $db;
|
||||
}
|
||||
|
||||
public function assertSqlResultEquals($expected, $sql, $message = '')
|
||||
{
|
||||
$db = $this->new_dbal();
|
||||
|
@@ -173,12 +173,12 @@ class phpbb_database_test_connection_manager
|
||||
/**
|
||||
* Load the phpBB database schema into the database
|
||||
*/
|
||||
public function load_schema($db)
|
||||
public function load_schema($db, \Doctrine\DBAL\Connection $doctrine_dbal)
|
||||
{
|
||||
$this->ensure_connected(__METHOD__);
|
||||
|
||||
$directory = __DIR__ . '/../../phpBB/install/schemas/';
|
||||
$this->load_schema_from_file($directory, $db);
|
||||
$this->load_schema_from_file($directory, $db, $doctrine_dbal);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -325,7 +325,7 @@ class phpbb_database_test_connection_manager
|
||||
* Compile the correct schema filename (as per create_schema_files) and
|
||||
* load it into the database.
|
||||
*/
|
||||
protected function load_schema_from_file($directory, \phpbb\db\driver\driver_interface $db)
|
||||
protected function load_schema_from_file($directory, \phpbb\db\driver\driver_interface $db, \Doctrine\DBAL\Connection $doctrine)
|
||||
{
|
||||
$schema = $this->dbms['SCHEMA'];
|
||||
|
||||
@@ -370,8 +370,9 @@ class phpbb_database_test_connection_manager
|
||||
->get_classes();
|
||||
|
||||
$db = new \phpbb\db\driver\sqlite3();
|
||||
$doctrine = \phpbb\db\doctrine\connection_factory::get_connection(new phpbb_mock_config_php_file());
|
||||
$factory = new \phpbb\db\tools\factory();
|
||||
$db_tools = $factory->get($db, true);
|
||||
$db_tools = $factory->get($doctrine, true);
|
||||
$tables = phpbb_database_test_case::get_core_tables();
|
||||
|
||||
$schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, $db_tools, $phpbb_root_path, $phpEx, $table_prefix, $tables);
|
||||
@@ -379,33 +380,13 @@ class phpbb_database_test_connection_manager
|
||||
}
|
||||
|
||||
$factory = new \phpbb\db\tools\factory();
|
||||
$db_tools = $factory->get($db, true);
|
||||
$db_tools = $factory->get($doctrine);
|
||||
foreach ($db_table_schema as $table_name => $table_data)
|
||||
{
|
||||
$queries = $db_tools->sql_create_table(
|
||||
$db_tools->sql_create_table(
|
||||
$table_name,
|
||||
$table_data
|
||||
);
|
||||
|
||||
foreach ($queries as $query)
|
||||
{
|
||||
if ($query === 'begin')
|
||||
{
|
||||
$this->pdo->beginTransaction();
|
||||
}
|
||||
else if ($query === 'commit' && $this->pdo->inTransaction())
|
||||
{
|
||||
$this->pdo->commit();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!$this->pdo->inTransaction())
|
||||
{
|
||||
$this->pdo->beginTransaction();
|
||||
}
|
||||
$this->pdo->exec($query);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -24,6 +24,7 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
|
||||
protected $cache = null;
|
||||
protected $db = null;
|
||||
protected $db_doctrine = null;
|
||||
protected $extension_manager = null;
|
||||
|
||||
/**
|
||||
@@ -207,6 +208,16 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
return $this->db;
|
||||
}
|
||||
|
||||
protected function get_db_doctrine()
|
||||
{
|
||||
// so we don't reopen an open connection
|
||||
if (!($this->db_doctrine instanceof \Doctrine\DBAL\Connection))
|
||||
{
|
||||
$this->db_doctrine = \phpbb\db\doctrine\connection_factory::get_connection_from_params(self::$config['dbms'], self::$config['dbhost'], self::$config['dbuser'], self::$config['dbpasswd'], self::$config['dbname'], self::$config['dbport']);
|
||||
}
|
||||
return $this->db_doctrine;
|
||||
}
|
||||
|
||||
protected function get_cache_driver()
|
||||
{
|
||||
if (!$this->cache)
|
||||
@@ -238,9 +249,10 @@ class phpbb_functional_test_case extends phpbb_test_case
|
||||
|
||||
$config = new \phpbb\config\config(array('version' => PHPBB_VERSION));
|
||||
$db = $this->get_db();
|
||||
$db_doctrine = $this->get_db_doctrine();
|
||||
$factory = new \phpbb\db\tools\factory();
|
||||
$finder_factory = new \phpbb\finder\factory(null, false, $phpbb_root_path, $phpEx);
|
||||
$db_tools = $factory->get($db);
|
||||
$db_tools = $factory->get($db_doctrine);
|
||||
|
||||
$container = new phpbb_mock_container_builder();
|
||||
$migrator = new \phpbb\db\migrator(
|
||||
|
Reference in New Issue
Block a user