diff --git a/tests/kb_display_order_migration_test.php b/tests/kb_display_order_migration_test.php index acda656..606fdcc 100644 --- a/tests/kb_display_order_migration_test.php +++ b/tests/kb_display_order_migration_test.php @@ -19,23 +19,33 @@ class kb_display_order_migration_test extends \PHPUnit\Framework\TestCase { private $db; private $tools; + private $sqlite_fixture; protected function tearDown(): void { + if ($this->tools instanceof \phpbb\db\tools\doctrine) $this->tools->get_connection()->close(); if ($this->db) $this->db->sql_close(); + if ($this->sqlite_fixture) unlink($this->sqlite_fixture); } private function connect(string $engine): void { if ($engine === 'sqlite') { - if (!class_exists(\phpbb\db\tools\sqlite3::class)) + $this->db = new \phpbb\db\driver\sqlite3(); + if (class_exists(\phpbb\db\tools\doctrine::class)) { - $this->markTestSkipped('phpBB 4.0 replaced these schema tools with Doctrine; these migrations were run on a real 4.0 board instead.'); + $this->sqlite_fixture = tempnam(sys_get_temp_dir(), 'kb-schema-'); + $this->assertTrue($this->db->sql_connect($this->sqlite_fixture, '', '', '')); + $connection = \phpbb\db\doctrine\connection_factory::get_connection_from_params('sqlite3', $this->sqlite_fixture); + $this->tools = new \phpbb\db\tools\doctrine($connection); + $this->tools->set_table_prefix('phpbb_'); + } + else + { + $this->assertTrue($this->db->sql_connect(':memory:', '', '', '')); + $this->tools = new \phpbb\db\tools\sqlite3($this->db); } - $this->db = new \phpbb\db\driver\sqlite3(); - $this->assertTrue($this->db->sql_connect(':memory:', '', '', '')); - $this->tools = new \phpbb\db\tools\sqlite3($this->db); return; } @@ -45,10 +55,23 @@ private function connect(string $engine): void $this->db = $engine === 'mysql' ? new \phpbb\db\driver\mysqli() : new \phpbb\db\driver\postgres(); $this->db->sql_return_on_error(true); $this->assertIsObject($this->db->sql_connect('127.0.0.1', $engine === 'mysql' ? 'root' : 'postgres', '', 'kb_fixture', (int) $port)); - $this->tools = $engine === 'mysql' ? new \phpbb\db\tools\tools($this->db) : new \phpbb\db\tools\postgres($this->db); + if (class_exists(\phpbb\db\tools\doctrine::class)) + { + $connection = \phpbb\db\doctrine\connection_factory::get_connection_from_params( + $engine === 'mysql' ? 'mysqli' : 'postgres', '127.0.0.1', + $engine === 'mysql' ? 'root' : 'postgres', '', 'kb_fixture', $port + ); + $this->tools = new \phpbb\db\tools\doctrine($connection); + $this->tools->set_table_prefix('phpbb_'); + } + else + { + $this->tools = $engine === 'mysql' ? new \phpbb\db\tools\tools($this->db) : new \phpbb\db\tools\postgres($this->db); + } foreach (['phpbb_kb_articles', 'phpbb_kb_categories'] as $table) { $this->query('DROP TABLE IF EXISTS ' . $table); + if ($engine === 'postgres') $this->query('DROP SEQUENCE IF EXISTS ' . $table . '_seq'); } } diff --git a/tests/kb_legacy_search_migration_test.php b/tests/kb_legacy_search_migration_test.php index 4998ad4..be9f6c7 100644 --- a/tests/kb_legacy_search_migration_test.php +++ b/tests/kb_legacy_search_migration_test.php @@ -22,32 +22,47 @@ class kb_legacy_search_migration_test extends \PHPUnit\Framework\TestCase { private $db; private $tools; + private $sqlite_fixture; private $config; protected function setUp(): void { - if (!class_exists(\phpbb\db\tools\sqlite3::class)) + $this->db = new \phpbb\db\driver\sqlite3(); + if (class_exists(\phpbb\db\tools\doctrine::class)) { - $this->markTestSkipped('phpBB 4.0 replaced these schema tools with Doctrine; these migrations were run on a real 4.0 board instead.'); + $this->sqlite_fixture = tempnam(sys_get_temp_dir(), 'kb-schema-'); + $this->assertTrue($this->db->sql_connect($this->sqlite_fixture, '', '', '')); + $connection = \phpbb\db\doctrine\connection_factory::get_connection_from_params('sqlite3', $this->sqlite_fixture); + $this->tools = new \phpbb\db\tools\doctrine($connection); + $this->tools->set_table_prefix('phpbb_'); + } + else + { + $this->assertTrue($this->db->sql_connect(':memory:', '', '', '')); + $this->tools = new \phpbb\db\tools\sqlite3($this->db); } - $this->db = new \phpbb\db\driver\sqlite3(); - $this->assertTrue($this->db->sql_connect(':memory:', '', '', '')); - $this->tools = new \phpbb\db\tools\sqlite3($this->db); $this->config = new \phpbb\config\config(['kb_version' => '2.0.14']); } protected function tearDown(): void { + if ($this->tools instanceof \phpbb\db\tools\doctrine) $this->tools->get_connection()->close(); $this->db->sql_close(); + if ($this->sqlite_fixture) unlink($this->sqlite_fixture); } private function migration($class, $prefix = 'phpbb_') { - return new $class($this->config, $this->db, $this->tools, '', 'php', $prefix); + if ($this->tools instanceof \phpbb\db\tools\doctrine) $this->tools->set_table_prefix($prefix); + return new $class($this->config, $this->db, $this->tools, '', 'php', $prefix, []); } private function columns($index) { + if ($this->tools instanceof \phpbb\db\tools\doctrine && $index === 'phpbb_kb_src_wrdmtch_un_mtch') + { + $index = \phpbb\db\doctrine\table_helper::generate_shortname('kb_src_wrdmtch') . '_un_mtch'; + } $result = $this->db->sql_query("PRAGMA index_info('" . $index . "')"); $columns = array_column($this->db->sql_fetchrowset($result), 'name'); $this->db->sql_freeresult($result); @@ -62,7 +77,7 @@ public function test_legacy_module_cleanup_uses_sql_string_literals() $queries[] = $sql; return true; }); - $migration = new version_1_0_0($this->config, $db, $this->tools, '', 'php', 'fixture_'); + $migration = new version_1_0_0($this->config, $db, $this->tools, '', 'php', 'fixture_', []); $migration->remove_knowlege_base_ext(); $this->assertStringContainsString('DELETE FROM fixture_modules', $queries[2]); foreach (['KNOWLEGE_BASE', 'ACP_KNOWLEGE_BASE_CONFIGURE', 'ACP_LIBRARY_MANAGE', 'ACP_LIBRARY_ARTICLES', 'ACP_LIBRARY_PERMISSIONS', 'ACP_LIBRARY_SEARCH', 'ACP_LIBRARY_LOGS'] as $name) diff --git a/tests/kb_markdown_migration_test.php b/tests/kb_markdown_migration_test.php index 5585988..c2d0117 100644 --- a/tests/kb_markdown_migration_test.php +++ b/tests/kb_markdown_migration_test.php @@ -19,16 +19,24 @@ class kb_markdown_migration_test extends \PHPUnit\Framework\TestCase private $db; private $tools; + private $sqlite_fixture; protected function setUp(): void { - if (!class_exists(\phpbb\db\tools\sqlite3::class)) + $this->db = new \phpbb\db\driver\sqlite3(); + if (class_exists(\phpbb\db\tools\doctrine::class)) { - $this->markTestSkipped('phpBB 4.0 replaced these schema tools with Doctrine; these migrations were run on a real 4.0 board instead.'); + $this->sqlite_fixture = tempnam(sys_get_temp_dir(), 'kb-schema-'); + $this->assertTrue($this->db->sql_connect($this->sqlite_fixture, '', '', '')); + $connection = \phpbb\db\doctrine\connection_factory::get_connection_from_params('sqlite3', $this->sqlite_fixture); + $this->tools = new \phpbb\db\tools\doctrine($connection); + $this->tools->set_table_prefix('phpbb_'); + } + else + { + $this->assertTrue($this->db->sql_connect(':memory:', '', '', '')); + $this->tools = new \phpbb\db\tools\sqlite3($this->db); } - $this->db = new \phpbb\db\driver\sqlite3(); - $this->assertTrue($this->db->sql_connect(':memory:', '', '', '')); - $this->tools = new \phpbb\db\tools\sqlite3($this->db); foreach (self::TABLES as $table) { $this->db->sql_query('CREATE TABLE phpbb_' . $table . ' (article_id INTEGER, article_body TEXT)'); @@ -38,7 +46,9 @@ protected function setUp(): void protected function tearDown(): void { + if ($this->tools instanceof \phpbb\db\tools\doctrine) $this->tools->get_connection()->close(); $this->db->sql_close(); + if ($this->sqlite_fixture) unlink($this->sqlite_fixture); } private function migration(): version_2_0_16 diff --git a/tests/kb_search_database_test.php b/tests/kb_search_database_test.php index ccf14b0..a96d80d 100644 --- a/tests/kb_search_database_test.php +++ b/tests/kb_search_database_test.php @@ -36,12 +36,25 @@ private function connect($engine) $this->db = $engine === 'mysql' ? new \phpbb\db\driver\mysqli() : new \phpbb\db\driver\postgres(); $this->db->sql_return_on_error(true); $this->assertIsObject($this->db->sql_connect('127.0.0.1', $engine === 'mysql' ? 'root' : 'postgres', '', 'kb_fixture', (int) $port)); - $this->tools = $engine === 'mysql' ? new \phpbb\db\tools\tools($this->db) : new \phpbb\db\tools\postgres($this->db); + if (class_exists(\phpbb\db\tools\doctrine::class)) + { + $connection = \phpbb\db\doctrine\connection_factory::get_connection_from_params( + $engine === 'mysql' ? 'mysqli' : 'postgres', '127.0.0.1', + $engine === 'mysql' ? 'root' : 'postgres', '', 'kb_fixture', $port + ); + $this->tools = new \phpbb\db\tools\doctrine($connection); + $this->tools->set_table_prefix('phpbb_'); + } + else + { + $this->tools = $engine === 'mysql' ? new \phpbb\db\tools\tools($this->db) : new \phpbb\db\tools\postgres($this->db); + } $this->class = $engine === 'mysql' ? kb_fulltext_mysql::class : kb_fulltext_postgres::class; $this->config = new \phpbb\config\config(['fulltext_postgres_ts_name' => 'english', 'search_block_size' => 100, 'num_posts' => 99, 'kb_num_articles' => 3]); foreach (['phpbb_kb_articles', 'phpbb_kb_search_results', 'phpbb_kb_src_wrdlist', 'phpbb_kb_src_wrdmtch', 'phpbb_kb_article_categories', SEARCH_RESULTS_TABLE] as $table) { $this->query('DROP TABLE IF EXISTS ' . $table); + if ($engine === 'postgres') $this->query('DROP SEQUENCE IF EXISTS ' . $table . '_seq'); } $old = new \phpbbmodders\knowledgebase\migrations\version_1_0_0($this->config, $this->db, $this->tools, '', 'php', 'phpbb_', []); $schema = $old->update_schema()['add_tables']; @@ -61,6 +74,7 @@ private function connect($engine) protected function tearDown(): void { + if ($this->tools instanceof \phpbb\db\tools\doctrine) $this->tools->get_connection()->close(); if ($this->db) $this->db->sql_close(); }