2016-12-29 21:16:14 -06:00
|
|
|
<?php
|
2014-07-19 14:37:48 +01:00
|
|
|
|
2014-09-24 13:31:27 -04:00
|
|
|
namespace Amp\Dns\Test;
|
2014-09-23 16:47:55 -04:00
|
|
|
|
2017-06-17 12:30:38 +02:00
|
|
|
use Amp\Dns;
|
|
|
|
use Amp\Dns\Record;
|
2017-03-16 23:01:58 -05:00
|
|
|
use Amp\Loop;
|
2017-06-17 10:49:54 +02:00
|
|
|
use Amp\PHPUnit\TestCase;
|
2016-12-29 21:17:07 -06:00
|
|
|
|
2017-06-17 10:49:54 +02:00
|
|
|
class IntegrationTest extends TestCase {
|
2014-07-19 14:37:48 +01:00
|
|
|
/**
|
|
|
|
* @group internet
|
2017-01-25 16:25:41 +01:00
|
|
|
* @dataProvider provideHostnames
|
2014-07-19 14:37:48 +01:00
|
|
|
*/
|
2017-01-25 16:25:41 +01:00
|
|
|
public function testResolve($hostname) {
|
2017-03-16 23:01:58 -05:00
|
|
|
Loop::run(function () use ($hostname) {
|
2017-06-17 12:30:38 +02:00
|
|
|
$result = yield Dns\resolve($hostname);
|
|
|
|
|
2017-01-25 16:25:41 +01:00
|
|
|
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-03-16 23:01:58 -05:00
|
|
|
});
|
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) {
|
2017-03-16 23:01:58 -05:00
|
|
|
Loop::run(function () use ($server) {
|
2017-06-17 12:30:38 +02:00
|
|
|
$result = yield Dns\resolve("google.com", [
|
|
|
|
"server" => $server,
|
|
|
|
]);
|
|
|
|
|
|
|
|
list($addr) = $result[0];
|
2017-01-25 16:25:41 +01:00
|
|
|
$inAddr = @\inet_pton($addr);
|
|
|
|
$this->assertNotFalse(
|
|
|
|
$inAddr,
|
|
|
|
"Server name google.com did not resolve to a valid IP address via $server"
|
|
|
|
);
|
2017-03-16 23:01:58 -05:00
|
|
|
});
|
2014-07-21 22:56:48 +01:00
|
|
|
}
|
2017-01-25 16:25:41 +01:00
|
|
|
|
2017-06-17 12:30:38 +02:00
|
|
|
public function testPtrLookup() {
|
2017-06-13 12:28:06 -05:00
|
|
|
Loop::run(function () {
|
2017-06-17 12:30:38 +02:00
|
|
|
$result = yield Dns\query("8.8.4.4", Record::PTR);
|
|
|
|
|
2017-02-05 14:58:22 +01:00
|
|
|
list($addr, $type) = $result[0];
|
2017-06-17 12:30:38 +02:00
|
|
|
$this->assertSame("google-public-dns-b.google.com", $addr);
|
|
|
|
$this->assertSame(Record::PTR, $type);
|
2017-02-05 14:58:22 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
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"],
|
|
|
|
];
|
|
|
|
}
|
2014-07-19 14:37:48 +01:00
|
|
|
}
|