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 committed Nov 24, 2024
1 parent edb53ee commit cd013ce
Showing 1 changed file with 24 additions and 41 deletions.
65 changes: 24 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,46 @@ 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(),
);
public static function providerForTestGetList(): array {

Check failure on line 47 in tests/unit/ListDatabaseTest.php

View workflow job for this annotation

GitHub Actions / analyse-php (8.2)

PossiblyUnusedMethod

tests/unit/ListDatabaseTest.php:47:28: PossiblyUnusedMethod: Cannot find any calls to method PhpMyAdmin\Tests\ListDatabaseTest::providerForTestGetList (see https://psalm.dev/087)

Check failure on line 47 in tests/unit/ListDatabaseTest.php

View workflow job for this annotation

GitHub Actions / analyse-php (8.2)

Method PhpMyAdmin\Tests\ListDatabaseTest::providerForTestGetList() return type has no value type specified in iterable type 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 cd013ce

Please sign in to comment.