Fake resolver
Fake resolver
Compose Cbox\LaravelDns\Testing\InteractsWithDns into your host application's
base TestCase:
use Cbox\LaravelDns\Testing\InteractsWithDns;
abstract class TestCase extends \Tests\TestCase
{
use InteractsWithDns;
}
Calling fakeDns() binds an in-memory Cbox\Dns\Testing\FakeResolver into the
container as the Resolver contract and rebuilds the Dns singleton over it —
so the facade, commands, and validation rules all resolve stubbed records.
Non-public nameserver IPs are permitted on the faked facade, so tests can use
documentation/LAN addresses for stubbed authoritative servers.
Stub records
use Cbox\LaravelDns\Facades\Dns;
use Cbox\Dns\Enums\RecordType;
$this->fakeDns()->stub('example.com', RecordType::MX, ['mail.example.com']);
Dns::lookup('example.com', RecordType::MX)->values(); // ['mail.example.com']
Stub an authoritative zone
verifyDomain, checkPropagation, and authoritative diagnostics discover a
zone's nameservers first. stubZone() wires the NS records and their addresses
so those reads have a server to target:
$this->stubZone('example.com', ['ns1.example.com' => '203.0.113.10']);
$this->fakeDns()->stub('_cbox-challenge.example.com', RecordType::TXT, ['token']);
Dns::verifyDomain('example.com', 'token'); // true
Assert what was queried
$this->fakeDns()->assertQueried('example.com', RecordType::MX);
A null-nameserver stub answers both the authoritative read and the public
resolver panel, which is the simplest way to model a fully propagated record. For
finer control (per-nameserver stubs, RCODE failures, raw DNSSEC records), reach
for the FakeResolver methods documented in
cboxdk/dns.