83 lines
2.7 KiB
PHP
83 lines
2.7 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Unit\Controller;
|
||
|
|
||
|
use App\Controller\ConfigController;
|
||
|
use App\Controller\DatabaseConnection;
|
||
|
use App\Controller\DomainController;
|
||
|
use App\Repository\DomainRepository;
|
||
|
use App\Repository\NameserverRepository;
|
||
|
use DI\Container;
|
||
|
use DI\ContainerBuilder;
|
||
|
use Exception;
|
||
|
use Monolog\Formatter\LineFormatter;
|
||
|
use Monolog\Handler\StreamHandler;
|
||
|
use Monolog\Level;
|
||
|
use Monolog\Logger;
|
||
|
use PHPUnit\Framework\TestCase;
|
||
|
use function DI\autowire;
|
||
|
|
||
|
/**
|
||
|
*
|
||
|
*/
|
||
|
class BindApiControllerTest extends TestCase
|
||
|
{
|
||
|
protected Container $container;
|
||
|
protected NameserverRepository $nameserverRepository;
|
||
|
protected DomainRepository $domainRepository;
|
||
|
protected DomainController $domainController;
|
||
|
protected Logger $logger;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* @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);
|
||
|
|
||
|
// init the logger
|
||
|
$dateFormat = "Y:m:d H:i:s";
|
||
|
$output = "%datetime% %channel%.%level_name% %message%\n"; // %context% %extra%
|
||
|
$formatter = new LineFormatter(format: $output, dateFormat: $dateFormat);
|
||
|
|
||
|
$debug = (new ConfigController)->getConfig(configKey: 'debug');
|
||
|
if ($debug) {
|
||
|
$stream = new StreamHandler(stream: dirname(path: __DIR__, levels: 3) . '/bindAPI.test.log', level: Level::Debug);
|
||
|
} else {
|
||
|
$stream = new StreamHandler(stream: dirname(path: __DIR__, levels: 3) . '/bindAPI.test.log', level: Level::Info);
|
||
|
}
|
||
|
$stream->setFormatter(formatter: $formatter);
|
||
|
|
||
|
$this->logger = new Logger(name: 'bindAPI');
|
||
|
$this->logger->pushHandler(handler: $stream);
|
||
|
$this->logger->debug(message: 'bindAPI started');
|
||
|
|
||
|
|
||
|
$containerBuilder = new ContainerBuilder();
|
||
|
$containerBuilder->addDefinitions([
|
||
|
//DatabaseConnection::class => autowire()->constructorParameter(parameter: 'config', value: $config),
|
||
|
DomainController::class => autowire()
|
||
|
->constructorParameter(parameter: 'logger', value: $this->logger),
|
||
|
DomainRepository::class => autowire()
|
||
|
->constructorParameter(parameter: 'logger', value: $this->logger),
|
||
|
|
||
|
]);
|
||
|
$this->container = $containerBuilder->build();
|
||
|
|
||
|
$this->nameserverRepository = $this->container->get(name: NameserverRepository::class);
|
||
|
$this->domainRepository = $this->container->get(name: DomainRepository::class);
|
||
|
$this->domainController = $this->container->get(name: DomainController::class);
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
public function testFoo(): void
|
||
|
{
|
||
|
self::assertEquals(expected: true, actual: true);
|
||
|
|
||
|
}
|
||
|
}
|