bindAPI/tests/Unit/Repository/DomainRepositoryTest.php

125 lines
3.9 KiB
PHP
Raw Normal View History

2022-10-08 10:51:54 +02:00
<?php
namespace Unit\Repository;
use App\Controller\ConfigController;
use App\Controller\DomainController;
use App\Entity\Domain;
use App\Repository\DomainRepository;
use DI\Container;
use DI\ContainerBuilder;
use Exception;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use PHPUnit\Framework\TestCase;
use Unit\Controller\BindApiControllerTest;
use function DI\autowire;
/**
*
*/
class DomainRepositoryTest extends BindApiControllerTest
{
private string $localZoneFile;
private string $localZonesDir;
private string $namedConfLocalFile;
/**
* @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);
}
public function setUp(): void
{
$this->logger->info(message: 'Started DomainRepositoryTest');
}
public function tearDown(): void
{
$this->logger->info(message: 'Finished DomainRepositoryTest');
}
/**
*/
public function testInsert()
{
self::assertEquals(expected: true, actual: true);
/*
$domain = new Domain(name: 'inserttest.org', panel: 'keyhelp.lab.24unix.net');
$this->domainRepository->insert(domain: $domain);
$this->domainController->createSlaveZoneFile(domain: $domain);
// now get the persisted domain with id
$domainTest = $this->domainRepository->findByName(name: 'inserttest.org');
$this->assertIsNotBool(actual: $domainTest);
$this->assertEquals(expected: 'inserttest.org', actual: $domainTest->getName());
if ($namedConfLocal = file_get_contents(filename: $this->namedConfLocalFile)) {
$this->assertStringContainsString(needle: $this->localZoneFile, haystack: $namedConfLocal);
} else {
$this->fail(message: 'No permissions: ' . $this->namedConfLocalFile);
}
$this->assertNotFalse(condition: fileperms(filename: $this->localZoneFile));
$localZones = file_get_contents(filename: $this->localZoneFile);
$this->assertStringContainsString(needle: $domainTest->getName(), haystack: $localZones);
$zoneFile = $this->localZonesDir . $domain->getName();
$this->assertFileExists(filename: $zoneFile);
// clean up
$this->domainRepository->delete(domain: $domainTest);
*/
}
/**
*/
public function testDelete()
{
self::assertEquals(expected: true, actual: true);
/*
$domain = new Domain(name: 'inserttest.org', panel: 'keyhelp.lab.24unix.net');
$this->domainRepository->insert(domain: $domain);
$this->domainController->createSlaveZoneFile(domain: $domain);
$domainTest = $this->domainRepository->findByName(name: 'inserttest.org');
$this->assertIsNotBool(actual: $domainTest);
$this->assertEquals(expected: 'inserttest.org', actual: $domainTest->getName());
// domain is valid and created
// now delete and check for cleanup
$this->domainRepository->delete(domain: $domainTest);
$this->domainController->deleteZone(domain: $domainTest);
// check zone is removed
$this->assertNotFalse(condition: fileperms(filename: $this->localZoneFile));
$localZones = file_get_contents(filename: $this->localZoneFile);
$this->assertStringNotContainsString(needle: $domainTest->getName(), haystack: $localZones);
$zoneFile = $this->localZonesDir . $domain->getName();
$this->assertFileDoesNotExist(filename: $zoneFile);
*/
}
}