From f6d656b6a369df9c703e1c70e496a04d494102bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Fri, 22 May 2026 19:32:03 -0300 Subject: [PATCH] Fix bookmarks not being properly saved MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- app/services.php | 2 +- phpstan-baseline.neon | 54 ----------------- psalm-baseline.xml | 21 ------- src/Bookmarks/BookmarkRepository.php | 58 ++++++++++++------- src/Controllers/Sql/SqlController.php | 55 ++++++++++++------ .../unit/Bookmarks/BookmarkRepositoryTest.php | 3 +- tests/unit/Bookmarks/BookmarkTest.php | 53 +++++++---------- tests/unit/ConsoleTest.php | 2 +- .../Console/Bookmark/AddControllerTest.php | 19 +++--- .../Bookmark/RefreshControllerTest.php | 4 +- .../MultiTableQuery/QueryControllerTest.php | 2 +- .../Database/SqlControllerTest.php | 2 +- .../Database/TrackingControllerTest.php | 2 +- .../Import/ImportControllerTest.php | 4 +- .../Sql/EnumValuesControllerTest.php | 8 +-- .../Sql/SetValuesControllerTest.php | 8 +-- .../Table/DeleteRowsControllerTest.php | 2 +- .../Table/ReplaceControllerTest.php | 4 +- .../Table/SearchControllerTest.php | 2 +- .../Controllers/Table/SqlControllerTest.php | 6 +- .../Table/TrackingControllerTest.php | 4 +- tests/unit/HeaderTest.php | 4 +- tests/unit/SqlQueryFormTest.php | 2 +- tests/unit/SqlTest.php | 4 +- tests/unit/Stubs/ResponseRenderer.php | 2 +- tests/unit/Tracking/TrackingTest.php | 4 +- 26 files changed, 139 insertions(+), 192 deletions(-) diff --git a/app/services.php b/app/services.php index 291c668d14..0b1faede29 100644 --- a/app/services.php +++ b/app/services.php @@ -385,7 +385,7 @@ return [ VersionInformation::class => ['class' => VersionInformation::class], BookmarkRepository::class => [ 'class' => BookmarkRepository::class, - 'arguments' => [DatabaseInterface::class, Relation::class], + 'arguments' => [DatabaseInterface::class, Relation::class, Config::class], ], Console::class => [ 'class' => Console::class, diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 2f5ec1b4dc..7dece79dbe 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -186,27 +186,12 @@ parameters: count: 2 path: src/Bookmarks/Bookmark.php - - - message: ''' - #^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\: - Use dependency injection instead\.$# - ''' - identifier: staticMethod.deprecated - count: 1 - path: src/Bookmarks/BookmarkRepository.php - - message: '#^Parameter \#1 \$row of method PhpMyAdmin\\Bookmarks\\BookmarkRepository\:\:createFromRow\(\) expects array\, array\ given\.$#' identifier: argument.type count: 3 path: src/Bookmarks/BookmarkRepository.php - - - message: '#^Parameter \#2 \$bookmarkFeature of class PhpMyAdmin\\Bookmarks\\Bookmark constructor expects PhpMyAdmin\\ConfigStorage\\Features\\BookmarkFeature, PhpMyAdmin\\ConfigStorage\\Features\\BookmarkFeature\|null given\.$#' - identifier: argument.type - count: 1 - path: src/Bookmarks/BookmarkRepository.php - - message: '#^Loose comparison via "\=\=" is not allowed\.$#' identifier: equal.notAllowed @@ -2505,18 +2490,6 @@ parameters: count: 1 path: src/Controllers/Sql/RelationalValuesController.php - - - message: '#^Loose comparison via "\!\=" is not allowed\.$#' - identifier: notEqual.notAllowed - count: 3 - path: src/Controllers/Sql/SqlController.php - - - - message: '#^Only booleans are allowed in an if condition, bool\|null given\.$#' - identifier: if.condNotBoolean - count: 1 - path: src/Controllers/Sql/SqlController.php - - message: '#^Parameter \#2 \$signature of static method PhpMyAdmin\\Core\:\:checkSqlQuerySignature\(\) expects string, mixed given\.$#' identifier: argument.type @@ -13770,24 +13743,6 @@ parameters: count: 1 path: tests/unit/Advisory/RulesTest.php - - - message: ''' - #^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\: - Use dependency injection instead\.$# - ''' - identifier: staticMethod.deprecated - count: 2 - path: tests/unit/Bookmarks/BookmarkTest.php - - - - message: ''' - #^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Dbal\\DatabaseInterface\: - Use dependency injection instead\.$# - ''' - identifier: staticMethod.deprecated - count: 3 - path: tests/unit/Bookmarks/BookmarkTest.php - - message: '#^Parameter \#2 \$haystack of static method PHPUnit\\Framework\\Assert\:\:assertStringContainsString\(\) expects string, mixed given\.$#' identifier: argument.type @@ -14280,15 +14235,6 @@ parameters: count: 1 path: tests/unit/Controllers/CheckRelationsControllerTest.php - - - message: ''' - #^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\: - Use dependency injection instead\.$# - ''' - identifier: staticMethod.deprecated - count: 2 - path: tests/unit/Controllers/Console/Bookmark/AddControllerTest.php - - message: ''' #^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\: diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 937f2c21c3..f7781360f6 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -30,17 +30,11 @@ - - - - - bookmarkFeature]]> - @@ -8629,15 +8623,6 @@ - - - - - - - - - @@ -9004,12 +8989,6 @@ - - - - - - diff --git a/src/Bookmarks/BookmarkRepository.php b/src/Bookmarks/BookmarkRepository.php index ed8553620f..b0ae30c877 100644 --- a/src/Bookmarks/BookmarkRepository.php +++ b/src/Bookmarks/BookmarkRepository.php @@ -10,6 +10,7 @@ namespace PhpMyAdmin\Bookmarks; use PhpMyAdmin\Config; use PhpMyAdmin\ConfigStorage\Features\BookmarkFeature; use PhpMyAdmin\ConfigStorage\Relation; +use PhpMyAdmin\ConfigStorage\RelationParameters; use PhpMyAdmin\Dbal\ConnectionType; use PhpMyAdmin\Dbal\DatabaseInterface; use PhpMyAdmin\Identifiers\DatabaseName; @@ -20,13 +21,13 @@ use PhpMyAdmin\Util; */ final class BookmarkRepository { - private BookmarkFeature|null $bookmarkFeature; - private readonly Config $config; + private RelationParameters|null $relationParameters = null; - public function __construct(private DatabaseInterface $dbi, Relation $relation) - { - $this->bookmarkFeature = $relation->getRelationParameters()->bookmarkFeature; - $this->config = Config::getInstance(); + public function __construct( + private readonly DatabaseInterface $dbi, + private readonly Relation $relation, + private readonly Config $config, + ) { } /** @@ -41,7 +42,8 @@ final class BookmarkRepository string $database, bool $shared = false, ): Bookmark|false { - if ($this->bookmarkFeature === null) { + $bookmarkFeature = $this->getBookmarkFeature(); + if ($bookmarkFeature === null) { return false; } @@ -57,7 +59,7 @@ final class BookmarkRepository return false; } - return new Bookmark($this->dbi, $this->bookmarkFeature, $database, $shared ? '' : $user, $label, $sqlQuery); + return new Bookmark($this->dbi, $bookmarkFeature, $database, $shared ? '' : $user, $label, $sqlQuery); } /** @@ -74,14 +76,15 @@ final class BookmarkRepository string $user, string|false $db = false, ): array { - if ($this->bookmarkFeature === null) { + $bookmarkFeature = $this->getBookmarkFeature(); + if ($bookmarkFeature === null) { return []; } $exactUserMatch = ! $this->config->config->AllowSharedBookmarks; - $query = 'SELECT * FROM ' . Util::backquote($this->bookmarkFeature->database) - . '.' . Util::backquote($this->bookmarkFeature->bookmark) + $query = 'SELECT * FROM ' . Util::backquote($bookmarkFeature->database) + . '.' . Util::backquote($bookmarkFeature->bookmark) . ' WHERE (`user` = ' . $this->dbi->quoteString($user); if (! $exactUserMatch) { $query .= " OR `user` = ''"; @@ -99,7 +102,7 @@ final class BookmarkRepository $bookmarks = []; foreach ($result as $row) { - $bookmarks[] = $this->createFromRow($row); + $bookmarks[] = $this->createFromRow($row, $bookmarkFeature); } return $bookmarks; @@ -112,12 +115,13 @@ final class BookmarkRepository string|null $user, int $id, ): Bookmark|null { - if ($this->bookmarkFeature === null) { + $bookmarkFeature = $this->getBookmarkFeature(); + if ($bookmarkFeature === null) { return null; } - $query = 'SELECT * FROM ' . Util::backquote($this->bookmarkFeature->database) - . '.' . Util::backquote($this->bookmarkFeature->bookmark) + $query = 'SELECT * FROM ' . Util::backquote($bookmarkFeature->database) + . '.' . Util::backquote($bookmarkFeature->bookmark) . ' WHERE `id` = ' . $id; if ($user !== null) { @@ -135,7 +139,7 @@ final class BookmarkRepository $result = $this->dbi->fetchSingleRow($query, DatabaseInterface::FETCH_ASSOC, ConnectionType::ControlUser); if ($result !== []) { - return $this->createFromRow($result); + return $this->createFromRow($result, $bookmarkFeature); } return null; @@ -149,12 +153,13 @@ final class BookmarkRepository DatabaseName $db, string $label, ): Bookmark|null { - if ($this->bookmarkFeature === null) { + $bookmarkFeature = $this->getBookmarkFeature(); + if ($bookmarkFeature === null) { return null; } - $query = 'SELECT * FROM ' . Util::backquote($this->bookmarkFeature->database) - . '.' . Util::backquote($this->bookmarkFeature->bookmark) + $query = 'SELECT * FROM ' . Util::backquote($bookmarkFeature->database) + . '.' . Util::backquote($bookmarkFeature->bookmark) . ' WHERE `label`' . ' = ' . $this->dbi->quoteString($label) . ' AND dbase = ' . $this->dbi->quoteString($db->getName()) @@ -163,18 +168,18 @@ final class BookmarkRepository $result = $this->dbi->fetchSingleRow($query, DatabaseInterface::FETCH_ASSOC, ConnectionType::ControlUser); if ($result !== []) { - return $this->createFromRow($result); + return $this->createFromRow($result, $bookmarkFeature); } return null; } /** @param string[] $row Resource used to build the bookmark */ - private function createFromRow(array $row): Bookmark + private function createFromRow(array $row, BookmarkFeature $bookmarkFeature): Bookmark { return new Bookmark( $this->dbi, - $this->bookmarkFeature, + $bookmarkFeature, $row['dbase'], $row['user'], $row['label'], @@ -182,4 +187,13 @@ final class BookmarkRepository (int) $row['id'], ); } + + private function getBookmarkFeature(): BookmarkFeature|null + { + if ($this->relationParameters === null) { + $this->relationParameters = $this->relation->getRelationParameters(); + } + + return $this->relationParameters->bookmarkFeature; + } } diff --git a/src/Controllers/Sql/SqlController.php b/src/Controllers/Sql/SqlController.php index 47904847c7..c09a6589a1 100644 --- a/src/Controllers/Sql/SqlController.php +++ b/src/Controllers/Sql/SqlController.php @@ -23,6 +23,7 @@ use PhpMyAdmin\Url; use PhpMyAdmin\UrlParams; use function __; +use function is_array; use function is_string; use function mb_strpos; use function str_contains; @@ -78,13 +79,12 @@ readonly class SqlController implements InvocableController $errorUrl .= '&table=' . urlencode(Current::$table); } - /** @var array|null $bkmFields */ - $bkmFields = $request->getParsedBodyParam('bkm_fields'); + $bookmarkFields = $this->getBookmarkFields($request->getParsedBodyParam('bkm_fields')); $sqlQuery = $request->getParsedBodyParamAsStringOrNull('sql_query'); // Coming from a bookmark dialog - if ($bkmFields !== null && $bkmFields['bkm_sql_query'] != null) { - Current::$sqlQuery = $bkmFields['bkm_sql_query']; + if (isset($bookmarkFields['bkm_sql_query'])) { + Current::$sqlQuery = $bookmarkFields['bkm_sql_query']; } elseif ($sqlQuery !== null) { Current::$sqlQuery = $sqlQuery; } elseif ($request->hasQueryParam('sql_query') && $request->hasQueryParam('sql_signature')) { @@ -98,8 +98,8 @@ readonly class SqlController implements InvocableController } // This one is just to fill $db - if ($bkmFields !== null && $bkmFields['bkm_database'] != null) { - Current::$database = $bkmFields['bkm_database']; + if (isset($bookmarkFields['bkm_database'])) { + Current::$database = $bookmarkFields['bkm_database']; } // Default to browse if no query set and we have table @@ -122,7 +122,7 @@ readonly class SqlController implements InvocableController $request->isAjax(), ); - if (Current::$table != $tableFromSql && $tableFromSql !== '') { + if (Current::$table !== $tableFromSql && $tableFromSql !== '') { Current::$table = $tableFromSql; } @@ -157,8 +157,8 @@ readonly class SqlController implements InvocableController */ $storeBkm = $request->hasBodyParam('store_bkm'); $bkmAllUsers = $request->getParsedBodyParam('bkm_all_users'); // Should this be hasBodyParam? - if ($storeBkm && $bkmFields !== null) { - return $this->addBookmark(UrlParams::$goto, $bkmFields, (bool) $bkmAllUsers); + if ($storeBkm) { + return $this->addBookmark(UrlParams::$goto, $bookmarkFields, (bool) $bkmAllUsers); } /** @@ -192,31 +192,31 @@ readonly class SqlController implements InvocableController return $this->response->response(); } - /** @param array $bkmFields */ - private function addBookmark(string $goto, array $bkmFields, bool $bkmAllUsers): Response + /** @param array $bookmarkFields */ + private function addBookmark(string $goto, array $bookmarkFields, bool $bkmAllUsers): Response { $bookmark = $this->bookmarkRepository->createBookmark( - $bkmFields['bkm_sql_query'], - $bkmFields['bkm_label'], - $bkmFields['bkm_user'], - $bkmFields['bkm_database'], + $bookmarkFields['bkm_sql_query'] ?? '', + $bookmarkFields['bkm_label'] ?? '', + $bookmarkFields['bkm_user'] ?? '', + $bookmarkFields['bkm_database'] ?? '', $bkmAllUsers, ); - $result = null; + $result = false; if ($bookmark !== false) { $result = $bookmark->save(); } if (! $this->response->isAjax()) { - $this->response->redirect('./' . $goto . '&label=' . $bkmFields['bkm_label']); + $this->response->redirect('./' . $goto . '&label=' . $bookmarkFields['bkm_label']); return $this->response->response(); } if ($result) { $msg = Message::success(__('Bookmark %s has been created.')); - $msg->addParam($bkmFields['bkm_label']); + $msg->addParam($bookmarkFields['bkm_label']); $this->response->addJSON('message', $msg); return $this->response->response(); @@ -228,4 +228,23 @@ readonly class SqlController implements InvocableController return $this->response->response(); } + + /** @return array{bkm_label?: string, bkm_database?: string, bkm_sql_query?: string, bkm_user?: string} */ + private function getBookmarkFields(mixed $param): array + { + if (! is_array($param)) { + return []; + } + + $fields = []; + foreach (['bkm_label', 'bkm_database', 'bkm_sql_query', 'bkm_user'] as $key) { + if (! isset($param[$key]) || ! is_string($param[$key])) { + continue; + } + + $fields[$key] = $param[$key]; + } + + return $fields; + } } diff --git a/tests/unit/Bookmarks/BookmarkRepositoryTest.php b/tests/unit/Bookmarks/BookmarkRepositoryTest.php index e228abcf44..e37fc5cd97 100644 --- a/tests/unit/Bookmarks/BookmarkRepositoryTest.php +++ b/tests/unit/Bookmarks/BookmarkRepositoryTest.php @@ -23,8 +23,9 @@ final class BookmarkRepositoryTest extends AbstractTestCase RelationParameters::BOOKMARK => 'pma_bookmark', ]); (new ReflectionProperty(Relation::class, 'cache'))->setValue(null, $relationParameters); + $config = new Config(); $dbi = $this->createDatabaseInterface(); - $bookmarkRepository = new BookmarkRepository($dbi, new Relation($dbi, new Config())); + $bookmarkRepository = new BookmarkRepository($dbi, new Relation($dbi, $config), $config); $bookmark = $bookmarkRepository->createBookmark('SELECT "phpmyadmin"', 'bookmark1', 'root', 'phpmyadmin'); self::assertNotFalse($bookmark); self::assertSame(0, $bookmark->getId()); diff --git a/tests/unit/Bookmarks/BookmarkTest.php b/tests/unit/Bookmarks/BookmarkTest.php index bf1cd90b3a..61fb694355 100644 --- a/tests/unit/Bookmarks/BookmarkTest.php +++ b/tests/unit/Bookmarks/BookmarkTest.php @@ -9,19 +9,13 @@ use PhpMyAdmin\Bookmarks\BookmarkRepository; use PhpMyAdmin\Config; use PhpMyAdmin\ConfigStorage\Relation; use PhpMyAdmin\ConfigStorage\RelationParameters; -use PhpMyAdmin\Dbal\DatabaseInterface; use PhpMyAdmin\Tests\AbstractTestCase; -use PhpMyAdmin\Tests\Stubs\DbiDummy; use PHPUnit\Framework\Attributes\CoversClass; use ReflectionProperty; #[CoversClass(Bookmark::class)] class BookmarkTest extends AbstractTestCase { - protected DatabaseInterface $dbi; - - protected DbiDummy $dummyDbi; - /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. @@ -30,10 +24,6 @@ class BookmarkTest extends AbstractTestCase { parent::setUp(); - $this->dummyDbi = $this->createDbiDummy(); - $this->dbi = $this->createDatabaseInterface($this->dummyDbi); - DatabaseInterface::$instance = $this->dbi; - $relationParameters = RelationParameters::fromArray([ RelationParameters::BOOKMARK_WORK => true, RelationParameters::DATABASE => 'phpmyadmin', @@ -47,19 +37,19 @@ class BookmarkTest extends AbstractTestCase */ public function testGetList(): void { - $this->dummyDbi->addResult( + $dbiDummy = $this->createDbiDummy(); + $dbiDummy->addResult( 'SELECT * FROM `phpmyadmin`.`pma_bookmark` WHERE (`user` = \'root\' OR `user` = \'\')' . ' AND dbase = \'sakila\' ORDER BY label ASC', [['1', 'sakila', 'root', 'label', 'SELECT * FROM `actor` WHERE `actor_id` < 10;']], ['id', 'dbase', 'user', 'label', 'query'], ); - $dbi = DatabaseInterface::getInstance(); - $actual = (new BookmarkRepository($dbi, new Relation($dbi)))->getList( - Config::getInstance()->selectedServer['user'], - 'sakila', - ); + $config = new Config(); + $dbi = $this->createDatabaseInterface($dbiDummy, $config); + $bookmarkRepository = new BookmarkRepository($dbi, new Relation($dbi, $config), $config); + $actual = $bookmarkRepository->getList($config->selectedServer['user'], 'sakila'); self::assertContainsOnlyInstancesOf(Bookmark::class, $actual); - $this->dummyDbi->assertAllSelectsConsumed(); + $dbiDummy->assertAllSelectsConsumed(); } /** @@ -67,18 +57,16 @@ class BookmarkTest extends AbstractTestCase */ public function testGet(): void { - $this->dummyDbi->addResult( + $dbiDummy = $this->createDbiDummy(); + $dbiDummy->addResult( "SELECT * FROM `phpmyadmin`.`pma_bookmark` WHERE `id` = 1 AND (user = 'root' OR user = '') LIMIT 1", [], ['id', 'dbase', 'user', 'label', 'query'], ); - $dbi = DatabaseInterface::getInstance(); - self::assertNull( - (new BookmarkRepository($dbi, new Relation($dbi)))->get( - Config::getInstance()->selectedServer['user'], - 1, - ), - ); + $config = new Config(); + $dbi = $this->createDatabaseInterface($dbiDummy, $config); + $bookmarkRepository = new BookmarkRepository($dbi, new Relation($dbi, $config), $config); + self::assertNull($bookmarkRepository->get($config->selectedServer['user'], 1)); } /** @@ -86,18 +74,17 @@ class BookmarkTest extends AbstractTestCase */ public function testSave(): void { - $this->dummyDbi->addResult( + $dbiDummy = $this->createDbiDummy(); + $dbiDummy->addResult( 'INSERT INTO `phpmyadmin`.`pma_bookmark` (id, dbase, user, query, label)' . " VALUES (NULL, 'phpmyadmin', 'root', 'SELECT \\\"phpmyadmin\\\"', 'bookmark1')", true, ); - $dbi = DatabaseInterface::getInstance(); - $bookmark = (new BookmarkRepository($dbi, new Relation($dbi)))->createBookmark( - 'SELECT "phpmyadmin"', - 'bookmark1', - 'root', - 'phpmyadmin', - ); + $config = new Config(); + $dbi = $this->createDatabaseInterface($dbiDummy, $config); + $relation = new Relation($dbi, $config); + $bookmarkRepository = new BookmarkRepository($dbi, $relation, $config); + $bookmark = $bookmarkRepository->createBookmark('SELECT "phpmyadmin"', 'bookmark1', 'root', 'phpmyadmin'); self::assertNotFalse($bookmark); self::assertTrue($bookmark->save()); } diff --git a/tests/unit/ConsoleTest.php b/tests/unit/ConsoleTest.php index 02647ded68..9b08452ca9 100644 --- a/tests/unit/ConsoleTest.php +++ b/tests/unit/ConsoleTest.php @@ -22,7 +22,7 @@ class ConsoleTest extends AbstractTestCase $dbi = DatabaseInterface::getInstance(); $config = Config::getInstance(); $relation = new Relation($dbi); - $bookmarkRepository = new BookmarkRepository($dbi, $relation); + $bookmarkRepository = new BookmarkRepository($dbi, $relation, $config); $history = new History($dbi, $relation, $config); $console = new Console($relation, new Template($config), $bookmarkRepository, $history); self::assertSame(['console.js'], $console->getScripts()); diff --git a/tests/unit/Controllers/Console/Bookmark/AddControllerTest.php b/tests/unit/Controllers/Console/Bookmark/AddControllerTest.php index b41a2aa908..ef193726fe 100644 --- a/tests/unit/Controllers/Console/Bookmark/AddControllerTest.php +++ b/tests/unit/Controllers/Console/Bookmark/AddControllerTest.php @@ -23,6 +23,7 @@ class AddControllerTest extends AbstractTestCase { public function testWithInvalidParams(): void { + $config = new Config(); $dbi = $this->createDatabaseInterface(); DatabaseInterface::$instance = $dbi; $response = new ResponseRenderer(); @@ -33,24 +34,24 @@ class AddControllerTest extends AbstractTestCase 'bookmark_query' => null, 'shared' => null, ]); - $relation = new Relation($dbi); - $bookmarkRepository = new BookmarkRepository($dbi, $relation); - $controller = new AddController($response, $bookmarkRepository, new Config()); + $relation = new Relation($dbi, $config); + $bookmarkRepository = new BookmarkRepository($dbi, $relation, $config); + $controller = new AddController($response, $bookmarkRepository, $config); $this->expectException(InvalidArgumentException::class); $controller($request); } public function testWithoutRelationParameters(): void { - $config = Config::getInstance(); + $config = new Config(); $config->selectedServer['user'] = 'user'; (new ReflectionProperty(Relation::class, 'cache'))->setValue(null, null); $dbi = $this->createDatabaseInterface(); DatabaseInterface::$instance = $dbi; $response = new ResponseRenderer(); $request = self::createStub(ServerRequest::class); - $relation = new Relation($dbi); - $bookmarkRepository = new BookmarkRepository($dbi, $relation); + $relation = new Relation($dbi, $config); + $bookmarkRepository = new BookmarkRepository($dbi, $relation, $config); $controller = new AddController($response, $bookmarkRepository, $config); $controller($request); self::assertSame(['message' => 'Failed'], $response->getJSONResult()); @@ -58,7 +59,7 @@ class AddControllerTest extends AbstractTestCase public function testWithValidParameters(): void { - $config = Config::getInstance(); + $config = new Config(); $config->selectedServer['user'] = 'test_user'; $relationParameters = RelationParameters::fromArray([ RelationParameters::USER => 'test_user', @@ -84,8 +85,8 @@ class AddControllerTest extends AbstractTestCase 'bookmark_query' => 'test_query', 'shared' => 'true', ]); - $relation = new Relation($dbi); - $bookmarkRepository = new BookmarkRepository($dbi, $relation); + $relation = new Relation($dbi, $config); + $bookmarkRepository = new BookmarkRepository($dbi, $relation, $config); $controller = new AddController($response, $bookmarkRepository, $config); $controller($request); self::assertSame( diff --git a/tests/unit/Controllers/Console/Bookmark/RefreshControllerTest.php b/tests/unit/Controllers/Console/Bookmark/RefreshControllerTest.php index 05ed8f9d0b..bc8f9ae1d6 100644 --- a/tests/unit/Controllers/Console/Bookmark/RefreshControllerTest.php +++ b/tests/unit/Controllers/Console/Bookmark/RefreshControllerTest.php @@ -26,8 +26,8 @@ class RefreshControllerTest extends AbstractTestCase $response = new ResponseRenderer(); $dbi = DatabaseInterface::getInstance(); $config = Config::getInstance(); - $relation = new Relation($dbi); - $bookmarkRepository = new BookmarkRepository($dbi, $relation); + $relation = new Relation($dbi, $config); + $bookmarkRepository = new BookmarkRepository($dbi, $relation, $config); $template = new Template($config); $history = new History($dbi, $relation, $config); $controller = new RefreshController( diff --git a/tests/unit/Controllers/Database/MultiTableQuery/QueryControllerTest.php b/tests/unit/Controllers/Database/MultiTableQuery/QueryControllerTest.php index 582d433701..aaae383f27 100644 --- a/tests/unit/Controllers/Database/MultiTableQuery/QueryControllerTest.php +++ b/tests/unit/Controllers/Database/MultiTableQuery/QueryControllerTest.php @@ -75,7 +75,7 @@ final class QueryControllerTest extends AbstractTestCase new RelationCleanup($dbi, $relation), new Transformations($dbi, $relation), new Template($config), - new BookmarkRepository($dbi, $relation), + new BookmarkRepository($dbi, $relation, $config), $config, $responseRenderer, ); diff --git a/tests/unit/Controllers/Database/SqlControllerTest.php b/tests/unit/Controllers/Database/SqlControllerTest.php index cd9d854feb..43694b0c3a 100644 --- a/tests/unit/Controllers/Database/SqlControllerTest.php +++ b/tests/unit/Controllers/Database/SqlControllerTest.php @@ -56,7 +56,7 @@ final class SqlControllerTest extends AbstractTestCase return new SqlController( $responseRenderer, - new SqlQueryForm($template, $dbi, new BookmarkRepository($dbi, $relation)), + new SqlQueryForm($template, $dbi, new BookmarkRepository($dbi, $relation, $config)), new PageSettings(new UserPreferences($dbi, $relation, $template, $config, new Clock()), $responseRenderer), new DbTableExists($dbi), ); diff --git a/tests/unit/Controllers/Database/TrackingControllerTest.php b/tests/unit/Controllers/Database/TrackingControllerTest.php index e052dd24c0..1ba1907951 100644 --- a/tests/unit/Controllers/Database/TrackingControllerTest.php +++ b/tests/unit/Controllers/Database/TrackingControllerTest.php @@ -71,7 +71,7 @@ final class TrackingControllerTest extends AbstractTestCase return new TrackingController( new ResponseRenderer(), new Tracking( - new SqlQueryForm($template, $dbi, new BookmarkRepository($dbi, $relation)), + new SqlQueryForm($template, $dbi, new BookmarkRepository($dbi, $relation, $config)), $template, $relation, $dbi, diff --git a/tests/unit/Controllers/Import/ImportControllerTest.php b/tests/unit/Controllers/Import/ImportControllerTest.php index 1428522c63..bb5204d03d 100644 --- a/tests/unit/Controllers/Import/ImportControllerTest.php +++ b/tests/unit/Controllers/Import/ImportControllerTest.php @@ -85,8 +85,8 @@ class ImportControllerTest extends AbstractTestCase ); $responseRenderer = new ResponseRenderer(); - $relation = new Relation($this->dbi); - $bookmarkRepository = new BookmarkRepository($this->dbi, $relation); + $relation = new Relation($this->dbi, $config); + $bookmarkRepository = new BookmarkRepository($this->dbi, $relation, $config); $template = new Template($config); $sql = new Sql( $this->dbi, diff --git a/tests/unit/Controllers/Sql/EnumValuesControllerTest.php b/tests/unit/Controllers/Sql/EnumValuesControllerTest.php index c24b36a4bd..1ef6da63d8 100644 --- a/tests/unit/Controllers/Sql/EnumValuesControllerTest.php +++ b/tests/unit/Controllers/Sql/EnumValuesControllerTest.php @@ -62,8 +62,8 @@ class EnumValuesControllerTest extends AbstractTestCase $responseRenderer = new ResponseRenderer(); $config = Config::getInstance(); $template = new Template($config); - $relation = new Relation($this->dbi); - $bookmarkRepository = new BookmarkRepository($this->dbi, $relation); + $relation = new Relation($this->dbi, $config); + $bookmarkRepository = new BookmarkRepository($this->dbi, $relation, $config); $sql = new Sql( $this->dbi, $relation, @@ -125,8 +125,8 @@ class EnumValuesControllerTest extends AbstractTestCase $responseRenderer = new ResponseRenderer(); $config = Config::getInstance(); $template = new Template($config); - $relation = new Relation($this->dbi); - $bookmarkRepository = new BookmarkRepository($this->dbi, $relation); + $relation = new Relation($this->dbi, $config); + $bookmarkRepository = new BookmarkRepository($this->dbi, $relation, $config); $sql = new Sql( $this->dbi, $relation, diff --git a/tests/unit/Controllers/Sql/SetValuesControllerTest.php b/tests/unit/Controllers/Sql/SetValuesControllerTest.php index 20bb9ef7f6..3d40d65141 100644 --- a/tests/unit/Controllers/Sql/SetValuesControllerTest.php +++ b/tests/unit/Controllers/Sql/SetValuesControllerTest.php @@ -62,8 +62,8 @@ class SetValuesControllerTest extends AbstractTestCase $responseRenderer = new ResponseRenderer(); $config = Config::getInstance(); $template = new Template($config); - $relation = new Relation($this->dbi); - $bookmarkRepository = new BookmarkRepository($this->dbi, $relation); + $relation = new Relation($this->dbi, $config); + $bookmarkRepository = new BookmarkRepository($this->dbi, $relation, $config); $sql = new Sql( $this->dbi, $relation, @@ -125,8 +125,8 @@ class SetValuesControllerTest extends AbstractTestCase $responseRenderer = new ResponseRenderer(); $config = Config::getInstance(); $template = new Template($config); - $relation = new Relation($this->dbi); - $bookmarkRepository = new BookmarkRepository($this->dbi, $relation); + $relation = new Relation($this->dbi, $config); + $bookmarkRepository = new BookmarkRepository($this->dbi, $relation, $config); $sql = new Sql( $this->dbi, $relation, diff --git a/tests/unit/Controllers/Table/DeleteRowsControllerTest.php b/tests/unit/Controllers/Table/DeleteRowsControllerTest.php index 42ab1c17eb..499495633b 100644 --- a/tests/unit/Controllers/Table/DeleteRowsControllerTest.php +++ b/tests/unit/Controllers/Table/DeleteRowsControllerTest.php @@ -69,7 +69,7 @@ class DeleteRowsControllerTest extends AbstractTestCase new RelationCleanup($dbi, $relation), new Transformations($dbi, $relation), new Template($config), - new BookmarkRepository($dbi, $relation), + new BookmarkRepository($dbi, $relation, $config), $config, $response, ); diff --git a/tests/unit/Controllers/Table/ReplaceControllerTest.php b/tests/unit/Controllers/Table/ReplaceControllerTest.php index ac1721079a..2501cb09ae 100644 --- a/tests/unit/Controllers/Table/ReplaceControllerTest.php +++ b/tests/unit/Controllers/Table/ReplaceControllerTest.php @@ -96,13 +96,13 @@ class ReplaceControllerTest extends AbstractTestCase $dummyDbi = $this->createDbiDummy(); $dbi = $this->createDatabaseInterface($dummyDbi); $config = Config::getInstance(); - $relation = new Relation($dbi); + $relation = new Relation($dbi, $config); $transformations = new Transformations($dbi, $relation); $template = new Template($config); $response = new ResponseRenderer(); $pageSettings = self::createStub(PageSettings::class); - $bookmarkRepository = new BookmarkRepository($dbi, $relation); + $bookmarkRepository = new BookmarkRepository($dbi, $relation, $config); $sqlController = new SqlController( $response, new Sql( diff --git a/tests/unit/Controllers/Table/SearchControllerTest.php b/tests/unit/Controllers/Table/SearchControllerTest.php index 8cbc5fbca7..0e3c57d021 100644 --- a/tests/unit/Controllers/Table/SearchControllerTest.php +++ b/tests/unit/Controllers/Table/SearchControllerTest.php @@ -54,7 +54,7 @@ final class SearchControllerTest extends AbstractTestCase new RelationCleanup($dbi, $relation), new Transformations($dbi, $relation), $template, - new BookmarkRepository($dbi, $relation), + new BookmarkRepository($dbi, $relation, $config), $config, $responseRenderer, ); diff --git a/tests/unit/Controllers/Table/SqlControllerTest.php b/tests/unit/Controllers/Table/SqlControllerTest.php index 4c84f1ebc7..0e69d0f471 100644 --- a/tests/unit/Controllers/Table/SqlControllerTest.php +++ b/tests/unit/Controllers/Table/SqlControllerTest.php @@ -44,9 +44,10 @@ final class SqlControllerTest extends AbstractTestCase $dbiDummy->addResult('SELECT 1 FROM `test_db`.`test_table` LIMIT 1;', [['1']]); $template = new Template($config); + $relation = new Relation($dbi, $config); $userPreferences = new UserPreferences( $dbi, - new Relation($dbi, $config), + $relation, $template, $config, new Clock(), @@ -54,8 +55,7 @@ final class SqlControllerTest extends AbstractTestCase $request = ServerRequestFactory::create()->createServerRequest('GET', 'http://example.com/') ->withQueryParams(['db' => 'test_db', 'table' => 'test_table']); - $relation = new Relation($dbi); - $bookmarkRepository = new BookmarkRepository($dbi, $relation); + $bookmarkRepository = new BookmarkRepository($dbi, $relation, $config); $responseRenderer = new ResponseRenderer(); $response = (new SqlController( $responseRenderer, diff --git a/tests/unit/Controllers/Table/TrackingControllerTest.php b/tests/unit/Controllers/Table/TrackingControllerTest.php index ee4aad3b0f..eec4704146 100644 --- a/tests/unit/Controllers/Table/TrackingControllerTest.php +++ b/tests/unit/Controllers/Table/TrackingControllerTest.php @@ -57,8 +57,8 @@ class TrackingControllerTest extends AbstractTestCase $responseRenderer = new ResponseRenderer(); $template = new Template($config); $trackingChecker = self::createStub(TrackingChecker::class); - $relation = new Relation($this->dbi); - $bookmarkRepository = new BookmarkRepository($this->dbi, $relation); + $relation = new Relation($this->dbi, $config); + $bookmarkRepository = new BookmarkRepository($this->dbi, $relation, $config); $response = (new TrackingController( $responseRenderer, new Tracking( diff --git a/tests/unit/HeaderTest.php b/tests/unit/HeaderTest.php index 98e9a5fa2d..0620a4e2ae 100644 --- a/tests/unit/HeaderTest.php +++ b/tests/unit/HeaderTest.php @@ -72,7 +72,7 @@ class HeaderTest extends AbstractTestCase return new Header( $template, - new Console($relation, $template, new BookmarkRepository($dbi, $relation), $history), + new Console($relation, $template, new BookmarkRepository($dbi, $relation, $config), $history), $config, $dbi, $relation, @@ -91,7 +91,7 @@ class HeaderTest extends AbstractTestCase $relation = new Relation($dbi, $config); $template = new Template($config); $history = new History($dbi, $relation, $config); - $console = new Console($relation, $template, new BookmarkRepository($dbi, $relation), $history); + $console = new Console($relation, $template, new BookmarkRepository($dbi, $relation, $config), $history); $userPreferences = new UserPreferences($dbi, $relation, $template, $config, new Clock()); $userPreferencesHandler = new UserPreferencesHandler( $config, diff --git a/tests/unit/SqlQueryFormTest.php b/tests/unit/SqlQueryFormTest.php index 975314765f..d87b415424 100644 --- a/tests/unit/SqlQueryFormTest.php +++ b/tests/unit/SqlQueryFormTest.php @@ -56,7 +56,7 @@ class SqlQueryFormTest extends AbstractTestCase DatabaseInterface::$instance = $this->dbi; $config = Config::getInstance(); $relation = new Relation($this->dbi); - $bookmarkRepository = new BookmarkRepository($this->dbi, $relation); + $bookmarkRepository = new BookmarkRepository($this->dbi, $relation, $config); $this->sqlQueryForm = new SqlQueryForm(new Template($config), $this->dbi, $bookmarkRepository); Current::$database = 'PMA_db'; diff --git a/tests/unit/SqlTest.php b/tests/unit/SqlTest.php index 67cf2105e0..2f1167998b 100644 --- a/tests/unit/SqlTest.php +++ b/tests/unit/SqlTest.php @@ -60,7 +60,7 @@ class SqlTest extends AbstractTestCase new RelationCleanup($this->dbi, $relation), new Transformations($this->dbi, $relation), new Template($config), - new BookmarkRepository($this->dbi, $relation), + new BookmarkRepository($this->dbi, $relation, $config), $config, new ResponseRenderer(), ); @@ -667,7 +667,7 @@ class SqlTest extends AbstractTestCase new RelationCleanup($this->dbi, $relation), new Transformations($this->dbi, $relation), new Template($config), - new BookmarkRepository($this->dbi, $relation), + new BookmarkRepository($this->dbi, $relation, $config), $config, new ResponseRenderer(), ); diff --git a/tests/unit/Stubs/ResponseRenderer.php b/tests/unit/Stubs/ResponseRenderer.php index 06b7412f51..797c10e9da 100644 --- a/tests/unit/Stubs/ResponseRenderer.php +++ b/tests/unit/Stubs/ResponseRenderer.php @@ -63,7 +63,7 @@ class ResponseRenderer extends \PhpMyAdmin\ResponseRenderer $dbi = DatabaseInterface::getInstanceForTest($dummyDbi, $config); $relation = new Relation($dbi, $config); $history = new History($dbi, $relation, $config); - $console = new Console($relation, $template, new BookmarkRepository($dbi, $relation), $history); + $console = new Console($relation, $template, new BookmarkRepository($dbi, $relation, $config), $history); $userPreferences = new UserPreferences($dbi, $relation, $template, $config, new Clock()); $userPreferencesHandler = new UserPreferencesHandler( $config, diff --git a/tests/unit/Tracking/TrackingTest.php b/tests/unit/Tracking/TrackingTest.php index 818da87645..4a34fd255f 100644 --- a/tests/unit/Tracking/TrackingTest.php +++ b/tests/unit/Tracking/TrackingTest.php @@ -65,8 +65,8 @@ final class TrackingTest extends AbstractTestCase (new ReflectionProperty(Relation::class, 'cache'))->setValue(null, $relationParameters); $template = new Template($config); - $relation = new Relation($dbi); - $bookmarkRepository = new BookmarkRepository($dbi, $relation); + $relation = new Relation($dbi, $config); + $bookmarkRepository = new BookmarkRepository($dbi, $relation, $config); $this->tracking = new Tracking( new SqlQueryForm($template, $dbi, $bookmarkRepository), $template,