<?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); } }