Skip to content

Commit

Permalink
Fix ListDatabaseTest
Browse files Browse the repository at this point in the history
Signed-off-by: Maximilian Krög <[email protected]>
  • Loading branch information
MoonE authored and MauricioFauth committed Dec 2, 2024
1 parent 43640af commit 4fa5eb0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 53 deletions.
9 changes: 0 additions & 9 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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\:
Expand Down
6 changes: 3 additions & 3 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13465,9 +13465,9 @@
</PossiblyUnusedMethod>
</file>
<file src="tests/unit/ListDatabaseTest.php">
<DeprecatedMethod>
<code><![CDATA[Config::getInstance()]]></code>
</DeprecatedMethod>
<PossiblyUnusedMethod>
<code><![CDATA[providerForTestGetList]]></code>
</PossiblyUnusedMethod>
</file>
<file src="tests/unit/MessageTest.php">
<PossiblyUnusedMethod>
Expand Down
67 changes: 26 additions & 41 deletions tests/unit/ListDatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -41,45 +23,48 @@ 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<list{string,string}> */
public static function providerForTestGetList(): array
{
return [
['db', 'single_db'],
['single_db', 'single_db'],
];
}

/**
* Test for checkHideDatabase
*/
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);
}
}

0 comments on commit 4fa5eb0

Please sign in to comment.