Code: Select all
[2] % ./vendor/bin/phpunit tests/App/Repository/DomainRepositoryTest.php
PHPUnit 9.5.13 by Sebastian Bergmann and contributors.
F 1 / 1 (100%)
Time: 00:00.051, Memory: 6.00 MB
There was 1 failure:
1) App\Repository\DomainRepositoryTest::testInsert
Failed asserting that 'include "/etc/bind/zones/aussempott.de";\n
include "/etc/bind/zones/xxxxxxoni.de";\n
include "/etc/bind/zones/cdw.one";\n
include "/etc/bind/zones/crowddataworker.de";\n
include "/etc/bind/zones/fairdns.de";\n
include "/etc/bind/zones/test.de";\n
include "/etc/bind/zones/tzazicke.de";\n
' contains "inserttest.org".
/home/users/tfunix/www/tests/App/Repository/DomainRepositoryTest.php:93
FAILURES!
Tests: 1, Assertions: 5, Failures: 1.
Ich habe den Code noch nicht commited, muss erst den Fehler finden und den test für delete() machen.
Aber dann bin ich so langsam fertig, fehlt nur noch ne Dokumentation …
Code: Select all
<?php
namespace App\Repository;
use App\Controller\DatabaseConnection;
use App\Entity\Domain;
use DI\Container;
use DI\ContainerBuilder;
use PHPUnit\Framework\TestCase;
use function DI\autowire;
/**
*
*/
class DomainRepositoryTest extends TestCase
{
private Container $container;
private DomainRepository $domainRepository;
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);
$this->localZoneFile = '/etc/bind/local.zones';
$this->localZonesDir = '/etc/bind/zones/';
$this->namedConfLocalFile = '/etc/bind/named.conf.local';
//$this->zoneCachePath = '/var/cache/bind/';
// read config TODO use .env file instead?
$configFile = dirname(path: __DIR__, levels: 3) . "/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->domainRepository = $this->container->get(name: DomainRepository::class);
}
/**
* @throws \DI\NotFoundException
* @throws \DI\DependencyException
*/
public function testInsert()
{
$domain = new Domain(name: 'inserttest.org', a: '1.2.3.4', aaaa: '1bad::babe');
$this->domainRepository->insert(domain: $domain);
$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['name'];
$this->assertFileExists(filename: $zoneFile);
// clean up
$this->domainRepository->delete(id: $domainTest->getId());
}
}