mirror of
https://github.com/danog/dns.git
synced 2024-11-26 20:14:51 +01:00
Add config test
This commit is contained in:
parent
74e68587f7
commit
2815d8f694
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@ composer.lock
|
|||||||
phpunit.xml
|
phpunit.xml
|
||||||
vendor
|
vendor
|
||||||
.php_cs.cache
|
.php_cs.cache
|
||||||
|
coverage
|
||||||
|
@ -31,8 +31,8 @@ class Config {
|
|||||||
$this->attempts = $attempts;
|
$this->attempts = $attempts;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function validateNameserver(string $nameserver) {
|
private function validateNameserver($nameserver) {
|
||||||
if (!$nameserver) {
|
if (!$nameserver || !\is_string($nameserver)) {
|
||||||
throw new ConfigException("Invalid nameserver: {$nameserver}");
|
throw new ConfigException("Invalid nameserver: {$nameserver}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
70
test/ConfigTest.php
Normal file
70
test/ConfigTest.php
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Amp\Dns\Test;
|
||||||
|
|
||||||
|
use Amp\Dns\Config;
|
||||||
|
use Amp\Dns\ConfigException;
|
||||||
|
use Amp\PHPUnit\TestCase;
|
||||||
|
|
||||||
|
class ConfigTest extends TestCase {
|
||||||
|
/**
|
||||||
|
* @param string[] $nameservers Valid server array.
|
||||||
|
*
|
||||||
|
* @dataProvider provideValidServers
|
||||||
|
*/
|
||||||
|
public function testAcceptsValidServers(array $nameservers) {
|
||||||
|
$this->assertInstanceOf(Config::class, new Config($nameservers));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provideValidServers() {
|
||||||
|
return [
|
||||||
|
[["127.1.1.1"]],
|
||||||
|
[["127.1.1.1:1"]],
|
||||||
|
[["[::1]:52"]],
|
||||||
|
[["[::1]"]],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string[] $nameservers Invalid server array.
|
||||||
|
*
|
||||||
|
* @dataProvider provideInvalidServers
|
||||||
|
*/
|
||||||
|
public function testRejectsInvalidServers(array $nameservers) {
|
||||||
|
$this->expectException(ConfigException::class);
|
||||||
|
new Config($nameservers);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function provideInvalidServers() {
|
||||||
|
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"]],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInvalidTimeout() {
|
||||||
|
$this->expectException(ConfigException::class);
|
||||||
|
new Config(["127.0.0.1"], [], -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInvalidAttempts() {
|
||||||
|
$this->expectException(ConfigException::class);
|
||||||
|
new Config(["127.0.0.1"], [], 500, 0);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user