2017-06-23 18:07:57 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Amp\Dns\Test;
|
|
|
|
|
|
|
|
use Amp\Dns\HostLoader;
|
|
|
|
use Amp\Dns\Record;
|
|
|
|
use Amp\Loop;
|
|
|
|
use Amp\PHPUnit\TestCase;
|
|
|
|
|
2019-01-25 02:27:47 +01:00
|
|
|
class HostLoaderTest extends TestCase
|
|
|
|
{
|
|
|
|
public function testIgnoresCommentsAndParsesBasicEntry()
|
|
|
|
{
|
2017-06-23 18:07:57 +02:00
|
|
|
Loop::run(function () {
|
|
|
|
$loader = new HostLoader(__DIR__ . "/data/hosts");
|
|
|
|
$this->assertSame([
|
|
|
|
Record::A => [
|
|
|
|
"localhost" => "127.0.0.1",
|
|
|
|
],
|
|
|
|
], yield $loader->loadHosts());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-25 02:27:47 +01:00
|
|
|
public function testReturnsEmptyErrorOnFileNotFound()
|
|
|
|
{
|
2017-06-23 18:07:57 +02:00
|
|
|
Loop::run(function () {
|
|
|
|
$loader = new HostLoader(__DIR__ . "/data/hosts.not.found");
|
|
|
|
$this->assertSame([], yield $loader->loadHosts());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-25 02:27:47 +01:00
|
|
|
public function testIgnoresInvalidNames()
|
|
|
|
{
|
2017-06-23 18:07:57 +02:00
|
|
|
Loop::run(function () {
|
|
|
|
$loader = new HostLoader(__DIR__ . "/data/hosts.invalid.name");
|
|
|
|
$this->assertSame([
|
|
|
|
Record::A => [
|
|
|
|
"localhost" => "127.0.0.1",
|
|
|
|
],
|
|
|
|
], yield $loader->loadHosts());
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|