bindAPI/tests/Unit/Controller/BindApiTestController.php

44 lines
1.2 KiB
PHP
Raw Normal View History

2022-02-05 20:26:32 +01:00
<?php
2022-10-07 11:33:54 +02:00
namespace Unit\Controller;
2022-02-05 20:26:32 +01:00
2022-10-07 11:33:54 +02:00
use App\Controller\DatabaseConnection;
2022-02-05 20:26:32 +01:00
use App\Repository\NameserverRepository;
use DI\Container;
use DI\ContainerBuilder;
2022-10-07 11:33:54 +02:00
use Exception;
2022-02-05 20:26:32 +01:00
use PHPUnit\Framework\TestCase;
use function DI\autowire;
/**
*
*/
class BindApiTestController extends TestCase
{
protected Container $container;
protected NameserverRepository $nameserverRepository;
/**
* @param int|string $dataName
*
2022-10-07 11:33:54 +02:00
* @throws Exception
2022-02-05 20:26:32 +01:00
* @internal This method is not covered by the backward compatibility promise for PHPUnit
*/
public function __construct(?string $name = null, array $data = [], $dataName = '')
{
parent::__construct(name: $name, data: $data, dataName: $dataName);
// read config TODO use .env file instead?
$configFile = dirname(path: __DIR__) . "/config.json";
$configJSON = file_get_contents(filename: $configFile);
$config = json_decode(json: $configJSON, associative: true);
$containerBuilder = new ContainerBuilder();
$containerBuilder->addDefinitions([
DatabaseConnection::class => autowire()->constructorParameter(parameter: 'config', value: $config),
]);
$this->container = $containerBuilder->build();
$this->nameserverRepository = $this->container->get(name: NameserverRepository::class);
}
}