Skip to content

Commit

Permalink
Add tests for app/services* files
Browse files Browse the repository at this point in the history
Fixes error introduced by
#18625.

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Mar 9, 2024
1 parent 38bd9dd commit 55d922c
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
14 changes: 7 additions & 7 deletions app/services_controllers.php
Original file line number Diff line number Diff line change
Expand Up @@ -1252,55 +1252,55 @@
'arguments' => [
'$response' => '@response',
'$template' => '@template',
'$maintenance' => '@partitioning_maintenance',
'$model' => '@partitioning_maintenance',
],
],
Table\Partition\CheckController::class => [
'class' => Table\Partition\CheckController::class,
'arguments' => [
'$response' => '@response',
'$template' => '@template',
'$maintenance' => '@partitioning_maintenance',
'$model' => '@partitioning_maintenance',
],
],
Table\Partition\DropController::class => [
'class' => Table\Partition\DropController::class,
'arguments' => [
'$response' => '@response',
'$template' => '@template',
'$maintenance' => '@partitioning_maintenance',
'$model' => '@partitioning_maintenance',
],
],
Table\Partition\OptimizeController::class => [
'class' => Table\Partition\OptimizeController::class,
'arguments' => [
'$response' => '@response',
'$template' => '@template',
'$maintenance' => '@partitioning_maintenance',
'$model' => '@partitioning_maintenance',
],
],
Table\Partition\RebuildController::class => [
'class' => Table\Partition\RebuildController::class,
'arguments' => [
'$response' => '@response',
'$template' => '@template',
'$maintenance' => '@partitioning_maintenance',
'$model' => '@partitioning_maintenance',
],
],
Table\Partition\RepairController::class => [
'class' => Table\Partition\RepairController::class,
'arguments' => [
'$response' => '@response',
'$template' => '@template',
'$maintenance' => '@partitioning_maintenance',
'$model' => '@partitioning_maintenance',
],
],
Table\Partition\TruncateController::class => [
'class' => Table\Partition\TruncateController::class,
'arguments' => [
'$response' => '@response',
'$template' => '@template',
'$maintenance' => '@partitioning_maintenance',
'$model' => '@partitioning_maintenance',
],
],
Operations\TableController::class => [
Expand Down
5 changes: 5 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12596,6 +12596,11 @@
<code><![CDATA[DatabaseInterface::getInstance()]]></code>
</DeprecatedMethod>
</file>
<file src="tests/unit/Container/ContainerBuilderTest.php">
<PossiblyUnusedMethod>
<code><![CDATA[servicesProvider]]></code>
</PossiblyUnusedMethod>
</file>
<file src="tests/unit/Controllers/BrowseForeignersControllerTest.php">
<DeprecatedMethod>
<code><![CDATA[Config::getInstance()]]></code>
Expand Down
34 changes: 32 additions & 2 deletions tests/unit/Container/ContainerBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
namespace PhpMyAdmin\Tests\Container;

use PhpMyAdmin\Container\ContainerBuilder;
use PhpMyAdmin\DatabaseInterface;
use PhpMyAdmin\Tests\AbstractTestCase;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;

use function array_keys;
use function array_map;
use function array_merge;

#[CoversClass(ContainerBuilder::class)]
final class ContainerBuilderTest extends TestCase
final class ContainerBuilderTest extends AbstractTestCase
{
public function testGetContainer(): void
{
Expand All @@ -20,4 +26,28 @@ public function testGetContainer(): void
self::assertNotSame($container, ContainerBuilder::getContainer());
ContainerBuilder::$container = null;
}

#[DataProvider('servicesProvider')]
public function testContainerEntries(string $service): void
{
$GLOBALS['lang'] = 'en';
DatabaseInterface::$instance = $this->createDatabaseInterface();
$container = ContainerBuilder::getContainer();
self::assertNotNull($container->get($service));
ContainerBuilder::$container = null;
}

/** @return array<int, array<int, string>> */
public static function servicesProvider(): array
{
/** @psalm-var array{services: array<string, mixed>} $services */
$services = include ROOT_PATH . 'app/services.php';
/** @psalm-var array{services: array<string, mixed>} $controllerServices */
$controllerServices = include ROOT_PATH . 'app/services_controllers.php';

return array_map(
static fn ($service) => [$service],
array_merge(array_keys($services['services']), array_keys($controllerServices['services'])),
);
}
}

0 comments on commit 55d922c

Please sign in to comment.