1
0
mirror of https://github.com/danog/dns.git synced 2025-01-23 05:51:11 +01:00
dns/test/IntegrationTest.php

70 lines
1.9 KiB
PHP
Raw Normal View History

<?php
2014-09-24 13:31:27 -04:00
namespace Amp\Dns\Test;
2014-09-23 16:47:55 -04:00
use Amp\Loop;
2017-06-17 10:49:54 +02:00
use Amp\PHPUnit\TestCase;
2017-06-17 10:49:54 +02:00
class IntegrationTest extends TestCase {
/**
* @group internet
2017-01-25 16:25:41 +01:00
* @dataProvider provideHostnames
*/
2017-01-25 16:25:41 +01:00
public function testResolve($hostname) {
Loop::run(function () use ($hostname) {
2017-01-25 16:25:41 +01:00
$result = (yield \Amp\Dns\resolve($hostname));
list($addr, $type, $ttl) = $result[0];
$inAddr = @\inet_pton($addr);
$this->assertNotFalse(
$inAddr,
"Server name $hostname did not resolve to a valid IP address"
);
});
2017-01-25 16:25:41 +01:00
}
2015-08-01 22:18:44 -04:00
2017-01-25 16:25:41 +01:00
/**
* @group internet
* @dataProvider provideServers
*/
public function testResolveWithCustomServer($server) {
Loop::run(function () use ($server) {
2017-01-25 16:25:41 +01:00
$result = (yield \Amp\Dns\resolve("google.com", [
2017-01-25 16:36:19 +01:00
"server" => $server
]));
2017-01-25 16:25:41 +01:00
list($addr, $type, $ttl) = $result[0];
$inAddr = @\inet_pton($addr);
$this->assertNotFalse(
$inAddr,
"Server name google.com did not resolve to a valid IP address via $server"
);
});
}
2017-01-25 16:25:41 +01:00
2017-02-05 14:58:22 +01:00
public function testPtrLoopup() {
2017-06-13 12:28:06 -05:00
Loop::run(function () {
2017-02-05 14:58:22 +01:00
$result = (yield \Amp\Dns\query("8.8.4.4", \Amp\Dns\Record::PTR));
list($addr, $type) = $result[0];
$this->assertSame($addr, "google-public-dns-b.google.com");
$this->assertSame($type, \Amp\Dns\Record::PTR);
});
}
2017-01-25 16:25:41 +01:00
public function provideHostnames() {
return [
["google.com"],
["github.com"],
["stackoverflow.com"],
["localhost"],
["192.168.0.1"],
["::1"],
];
}
public function provideServers() {
return [
["8.8.8.8"],
["8.8.8.8:53"],
];
}
}