30 lines
697 B
PHP
30 lines
697 B
PHP
<?php
|
|
|
|
namespace App\Services\Dns;
|
|
|
|
use RuntimeException;
|
|
|
|
class FakeHetznerDnsClient implements HetznerDnsClient
|
|
{
|
|
/** @var array<string, string> fqdn => record_id */
|
|
public array $records = [];
|
|
|
|
public bool $failUpsert = false;
|
|
|
|
private int $counter = 1;
|
|
|
|
public function upsertRecord(string $fqdn, string $type, string $value): string
|
|
{
|
|
if ($this->failUpsert) {
|
|
throw new RuntimeException('hetzner dns 5xx');
|
|
}
|
|
|
|
return $this->records[$fqdn] ??= 'rec-'.$this->counter++;
|
|
}
|
|
|
|
public function deleteRecord(string $recordId): void
|
|
{
|
|
$this->records = array_filter($this->records, fn ($id) => $id !== $recordId);
|
|
}
|
|
}
|