From 54fb31bae556bcab02c4c8c6cd09779f28e4f850 Mon Sep 17 00:00:00 2001 From: William Jacoby Date: Sun, 18 Oct 2026 00:38:49 -0500 Subject: [PATCH 1/2] Fix migration test constructors for phpBB 4.0 --- tests/kb_match_key_repair_test.php | 2 +- tests/kb_search_key_migration_test.php | 2 +- tests/kb_upload_directory_test.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/kb_match_key_repair_test.php b/tests/kb_match_key_repair_test.php index 6a195ad..ea6ef76 100644 --- a/tests/kb_match_key_repair_test.php +++ b/tests/kb_match_key_repair_test.php @@ -24,7 +24,7 @@ class kb_match_key_repair_test extends \PHPUnit\Framework\TestCase private function migration($db): version_2_0_25 { - return new version_2_0_25(new \phpbb\config\config(['kb_version' => '2.0.24']), $db, $this->createMock(\phpbb\db\tools\tools_interface::class), '', 'php', 'phpbb_'); + return new version_2_0_25(new \phpbb\config\config(['kb_version' => '2.0.24']), $db, $this->createMock(\phpbb\db\tools\tools_interface::class), '', 'php', 'phpbb_', []); } /** diff --git a/tests/kb_search_key_migration_test.php b/tests/kb_search_key_migration_test.php index 19650e2..d7adaa7 100644 --- a/tests/kb_search_key_migration_test.php +++ b/tests/kb_search_key_migration_test.php @@ -41,7 +41,7 @@ private function run_add_key(array $indexes, string $layer = 'mysqli'): array return array_shift($rows) ?? false; }); - $migration = new version_1_0_3(new \phpbb\config\config([]), $db, $this->createMock(\phpbb\db\tools\tools_interface::class), '', 'php', 'phpbb_'); + $migration = new version_1_0_3(new \phpbb\config\config([]), $db, $this->createMock(\phpbb\db\tools\tools_interface::class), '', 'php', 'phpbb_', []); $migration->add_key(); return $queries; diff --git a/tests/kb_upload_directory_test.php b/tests/kb_upload_directory_test.php index bc6f974..4fa09ed 100644 --- a/tests/kb_upload_directory_test.php +++ b/tests/kb_upload_directory_test.php @@ -186,7 +186,7 @@ public function test_attachments_stay_where_they_are_when_the_new_folder_cannot_ public function test_the_migration_moves_the_attachments_and_sets_the_version() { - $migration = new \phpbbmodders\knowledgebase\migrations\version_2_0_28(new \phpbb\config\config([]), $this->createMock(\phpbb\db\driver\driver_interface::class), $this->createMock(\phpbb\db\tools\tools_interface::class), $this->root, 'php', 'phpbb_'); + $migration = new \phpbbmodders\knowledgebase\migrations\version_2_0_28(new \phpbb\config\config([]), $this->createMock(\phpbb\db\driver\driver_interface::class), $this->createMock(\phpbb\db\tools\tools_interface::class), $this->root, 'php', 'phpbb_', []); $this->legacy_file('moved.dat'); $this->assertSame(['\phpbbmodders\knowledgebase\migrations\version_2_0_27'], $migration::depends_on()); From d2c146b0cba80126ffdda4bad2ffb8b0103adc26 Mon Sep 17 00:00:00 2001 From: William Jacoby Date: Sun, 18 Oct 2026 10:44:55 -0500 Subject: [PATCH 2/2] Support Doctrine tools in database regression fixtures --- tests/kb_display_order_migration_test.php | 35 +++++++++++++++++++---- tests/kb_legacy_search_migration_test.php | 29 ++++++++++++++----- tests/kb_markdown_migration_test.php | 20 +++++++++---- tests/kb_search_database_test.php | 16 ++++++++++- 4 files changed, 81 insertions(+), 19 deletions(-) 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(); }