From 280227036c7a2bf3340998358ea4392b91307bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Wed, 4 Feb 2026 23:30:20 -0300 Subject: [PATCH] Fix SyncFavoriteTablesControllerTest failing test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- phpstan-baseline.neon | 6 ----- .../SyncFavoriteTablesControllerTest.php | 26 ++++++++++--------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 77ab117faf..c178b7636f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -15057,12 +15057,6 @@ parameters: count: 2 path: tests/unit/Controllers/Sql/SetValuesControllerTest.php - - - message: '#^Parameter \#1 \$str of method PhpMyAdmin\\Dbal\\DatabaseInterface\:\:quoteString\(\) expects string, string\|false given\.$#' - identifier: argument.type - count: 1 - path: tests/unit/Controllers/SyncFavoriteTablesControllerTest.php - - message: ''' #^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\: diff --git a/tests/unit/Controllers/SyncFavoriteTablesControllerTest.php b/tests/unit/Controllers/SyncFavoriteTablesControllerTest.php index 9269dbbf3b..414c607139 100644 --- a/tests/unit/Controllers/SyncFavoriteTablesControllerTest.php +++ b/tests/unit/Controllers/SyncFavoriteTablesControllerTest.php @@ -16,7 +16,7 @@ use PhpMyAdmin\Http\Factory\ServerRequestFactory; use PhpMyAdmin\Identifiers\DatabaseName; use PhpMyAdmin\Identifiers\TableName; use PhpMyAdmin\Tests\AbstractTestCase; -use PhpMyAdmin\Tests\Stubs\ResponseRenderer as ResponseStub; +use PhpMyAdmin\Tests\Stubs\ResponseRenderer; use PHPUnit\Framework\Attributes\CoversClass; use ReflectionProperty; @@ -34,15 +34,14 @@ final class SyncFavoriteTablesControllerTest extends AbstractTestCase (new ReflectionProperty(RecentFavoriteTables::class, 'instances'))->setValue(null, []); - $recentFavoriteTable = new RecentFavoriteTable( - DatabaseName::from('test_db'), - TableName::from('test_table'), - ); + $recentFavoriteTable = new RecentFavoriteTable(DatabaseName::from('test_db'), TableName::from('test_table')); $dbiDummy->addResult('SELECT 1 FROM `test_db`.`test_table` LIMIT 1;', [['1']], ['1']); $dbiDummy->addResult('SELECT `tables` FROM `pmadb`.`favorite` WHERE `username` = \'root\'', []); - $dbiDummy->addResult("REPLACE INTO `pmadb`.`favorite` (`username`, `tables`) VALUES ('root', " - . $dbi->quoteString(json_encode([$recentFavoriteTable])) . - ')', true); + $dbiDummy->addResult( + "REPLACE INTO `pmadb`.`favorite` (`username`, `tables`) VALUES ('root', " + . $dbi->quoteString((string) json_encode([$recentFavoriteTable])) . ')', + true, + ); $relationParameters = RelationParameters::fromArray([ RelationParameters::DATABASE => 'pmadb', @@ -51,9 +50,11 @@ final class SyncFavoriteTablesControllerTest extends AbstractTestCase ]); (new ReflectionProperty(Relation::class, 'cache'))->setValue(null, $relationParameters); - $response = new ResponseStub(); - $response->setAjax(true); - $controller = new SyncFavoriteTablesController($response, new Relation($dbi), new Config()); + $config = Config::$instance = new Config(); + $config->selectedServer['user'] = 'root'; + $responseRenderer = new ResponseRenderer(); + $responseRenderer->setAjax(true); + $controller = new SyncFavoriteTablesController($responseRenderer, new Relation($dbi, $config), $config); // The user hash for test $user = 'dc76e9f0c0006e8f919e0c515c66dbba3982f785'; @@ -68,7 +69,8 @@ final class SyncFavoriteTablesControllerTest extends AbstractTestCase $json = json_decode((string) $response->getBody(), true); self::assertIsArray($json); - self::assertSame($favoriteTable, $json['favoriteTables'] ?? ''); + self::assertArrayHasKey('favoriteTables', $json); + self::assertSame($favoriteTable, $json['favoriteTables']); self::assertArrayHasKey('list', $json); /** * @psalm-suppress TypeDoesNotContainType