diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 5a0fd25b84d..324e99b53fe 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -22215,15 +22215,6 @@ parameters: count: 2 path: tests/unit/IpAllowDenyTest.php - - - message: ''' - #^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\: - Use dependency injection instead\.$# - ''' - identifier: staticMethod.deprecated - count: 1 - path: tests/unit/ListDatabaseTest.php - - message: ''' #^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Config\: diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 6c0eeffd62c..0bc3e6961ab 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -13465,9 +13465,9 @@ - - - + + + diff --git a/tests/unit/ListDatabaseTest.php b/tests/unit/ListDatabaseTest.php index b7a0b366d48..cf01f7b333a 100644 --- a/tests/unit/ListDatabaseTest.php +++ b/tests/unit/ListDatabaseTest.php @@ -9,29 +9,11 @@ use PhpMyAdmin\ListDatabase; use PhpMyAdmin\UserPrivilegesFactory; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; #[CoversClass(ListDatabase::class)] class ListDatabaseTest extends AbstractTestCase { - /** - * ListDatabase instance - */ - private ListDatabase $object; - - /** - * SetUp for test cases - */ - protected function setUp(): void - { - parent::setUp(); - - $dbi = $this->createDatabaseInterface(); - $config = new Config(); - $config->selectedServer['DisableIS'] = false; - $config->selectedServer['only_db'] = ['single\\_db']; - $this->object = new ListDatabase($dbi, $config, new UserPrivilegesFactory($dbi)); - } - /** * Test for ListDatabase::exists */ @@ -41,29 +23,34 @@ public function testExists(): void $config = new Config(); $config->selectedServer['DisableIS'] = false; $config->selectedServer['only_db'] = ['single\\_db']; - $arr = new ListDatabase($dbi, $config, new UserPrivilegesFactory($dbi)); - self::assertTrue($arr->exists('single_db')); + $object = new ListDatabase($dbi, $config, new UserPrivilegesFactory($dbi)); + + self::assertTrue($object->exists('single_db')); } - public function testGetList(): void + #[DataProvider('providerForTestGetList')] + public function testGetList(string $currentDbName, string $dbName): void { $dbi = $this->createDatabaseInterface(); $config = new Config(); $config->selectedServer['DisableIS'] = false; $config->selectedServer['only_db'] = ['single\\_db']; - $arr = new ListDatabase($dbi, $config, new UserPrivilegesFactory($dbi)); + $object = new ListDatabase($dbi, $config, new UserPrivilegesFactory($dbi)); - Current::$database = 'db'; + Current::$database = $currentDbName; self::assertSame( - [['name' => 'single_db', 'is_selected' => false]], - $arr->getList(), + [['name' => $dbName, 'is_selected' => $currentDbName === $dbName]], + $object->getList(), ); + } - Current::$database = 'single_db'; - self::assertSame( - [['name' => 'single_db', 'is_selected' => true]], - $arr->getList(), - ); + /** @return list */ + public static function providerForTestGetList(): array + { + return [ + ['db', 'single_db'], + ['single_db', 'single_db'], + ]; } /** @@ -71,15 +58,13 @@ public function testGetList(): void */ public function testCheckHideDatabase(): void { - Config::getInstance()->selectedServer['hide_db'] = 'single\\_db'; - self::assertEquals( - $this->callFunction( - $this->object, - ListDatabase::class, - 'checkHideDatabase', - [], - ), - '', - ); + $dbi = $this->createDatabaseInterface(); + $config = new Config(); + $config->selectedServer['DisableIS'] = false; + $config->selectedServer['only_db'] = ['single\\_db']; + $config->selectedServer['hide_db'] = 'single\\_db'; + $object = new ListDatabase($dbi, $config, new UserPrivilegesFactory($dbi)); + + self::assertEquals([], (array) $object); } }