bindAPI/tests/App/Controller/BindApiTestController.php

42 lines
1.2 KiB
PHP
Raw Normal View History

2022-02-05 20:26:32 +01:00
<?php
namespace App\Controller;
use App\Repository\NameserverRepository;
use DI\Container;
use DI\ContainerBuilder;
use PHPUnit\Framework\TestCase;
use function DI\autowire;
/**
*
*/
class BindApiTestController extends TestCase
{
protected Container $container;
protected NameserverRepository $nameserverRepository;
/**
* @param int|string $dataName
*
* @throws \Exception
* @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);
}
}