1
0
mirror of https://github.com/danog/dns.git synced 2024-12-02 17:38:05 +01:00
dns/test/ConfigTest.php

78 lines
1.7 KiB
PHP
Raw Normal View History

2017-06-22 23:39:13 +02:00
<?php
namespace Amp\Dns\Test;
use Amp\Dns\Config;
use Amp\Dns\ConfigException;
use Amp\PHPUnit\TestCase;
2019-01-25 02:27:47 +01:00
class ConfigTest extends TestCase
{
2017-06-22 23:39:13 +02:00
/**
* @param string[] $nameservers Valid server array.
*
* @dataProvider provideValidServers
*/
2019-01-25 02:27:47 +01:00
public function testAcceptsValidServers(array $nameservers)
{
2017-06-22 23:39:13 +02:00
$this->assertInstanceOf(Config::class, new Config($nameservers));
}
2019-01-25 02:27:47 +01:00
public function provideValidServers()
{
2017-06-22 23:39:13 +02:00
return [
[["127.1.1.1"]],
[["127.1.1.1:1"]],
[["[::1]:52"]],
[["[::1]"]],
];
}
/**
* @param string[] $nameservers Invalid server array.
*
* @dataProvider provideInvalidServers
*/
2019-01-25 02:27:47 +01:00
public function testRejectsInvalidServers(array $nameservers)
{
2017-06-22 23:39:13 +02:00
$this->expectException(ConfigException::class);
new Config($nameservers);
}
2019-01-25 02:27:47 +01:00
public function provideInvalidServers()
{
2017-06-22 23:39:13 +02:00
return [
[[]],
[[42]],
[[null]],
[[true]],
[["foobar"]],
[["foobar.com"]],
[["127.1.1"]],
[["127.1.1.1.1"]],
[["126.0.0.5", "foobar"]],
[["42"]],
[["::1"]],
[["::1:53"]],
[["[::1]:"]],
[["[::1]:76235"]],
[["[::1]:0"]],
[["[::1]:-1"]],
[["[::1:51"]],
[["[::1]:abc"]],
];
}
2019-01-25 02:27:47 +01:00
public function testInvalidTimeout()
{
2017-06-22 23:39:13 +02:00
$this->expectException(ConfigException::class);
new Config(["127.0.0.1"], [], -1);
}
2019-01-25 02:27:47 +01:00
public function testInvalidAttempts()
{
2017-06-22 23:39:13 +02:00
$this->expectException(ConfigException::class);
new Config(["127.0.0.1"], [], 500, 0);
}
}