1
0
mirror of https://github.com/danog/dns.git synced 2024-12-03 09:57:56 +01:00
dns/test/ClientTest.php
2014-11-10 16:13:44 +00:00

96 lines
2.9 KiB
PHP

<?php
namespace Amp\Dns\Test;
use Amp\Dns\AddressModes;
use Amp\Dns\Client;
class ClientTest extends \PHPUnit_Framework_TestCase {
/**
* @expectedException \Amp\Dns\ResolutionException
*/
public function testFailToConnect() {
$client = new Client();
$client->setOption(Client::OP_SERVER_ADDRESS, '260.260.260.260');
$promise = $client->resolve('example.com', AddressModes::INET4_ADDR);
$promise->wait();
}
/**
* This is just for coverage - which is not worthwhile in itself,
* but it makes it easier to detect missing important coverage.
*/
public function testSetRequestTime() {
$client = new Client();
$client->setOption(Client::OP_MS_REQUEST_TIMEOUT, 1000);
$client->setOption(Client::OP_SERVER_PORT, 53);
}
/**
* @expectedException \DomainException
*/
public function testUnknownOptionThrowsException() {
$client = new Client();
$client->setOption('foo', 1000);
}
/**
* @expectedException \RuntimeException
* @group internet
*/
public function testSetAddressAfterConnectException() {
$client = new Client();
$promise = $client->resolve('google.com', AddressModes::INET4_ADDR);
$promise->wait();
$client->setOption(Client::OP_SERVER_ADDRESS, '260.260.260.260');
}
/**
* @expectedException \RuntimeException
* @group internet
*/
public function testSetPortAfterConnectException() {
$client = new Client();
$promise = $client->resolve('google.com', AddressModes::INET4_ADDR);
$promise->wait();
$client->setOption(Client::OP_SERVER_PORT, 53);
}
/**
* @expectedException \Amp\Dns\ResolutionException
*/
public function testNoAnswers() {
$client = new Client();
$promise = $client->resolve('googleaiusdisuhdihas.apsidjpasjdisjdajsoidaugiug.com', AddressModes::INET4_ADDR);
$promise->wait();
}
/**
* Test that the overflow of lookupIdCounter and requestIdCounter to
* zero occurs.
*/
public function testPendingIdOverflow() {
$class = new \ReflectionClass('Amp\Dns\Client');
$lookupIdProperty = $class->getProperty("lookupIdCounter");
$requestIdCounterProperty = $class->getProperty("requestIdCounter");
/** @var Client $client */
$client = $class->newInstance();
$lookupIdProperty->setAccessible(true);
$lookupIdProperty->setValue($client, PHP_INT_MAX);
$requestIdCounterProperty->setAccessible(true);
$requestIdCounterProperty->setValue($client, 65535);
$promise = $client->resolve('google.com', AddressModes::INET4_ADDR);
$promise->wait();
$lookupIdCounter = $lookupIdProperty->getValue($client);
$this->assertEquals(0, $lookupIdCounter);
$requestIdCounter = $lookupIdProperty->getValue($client);
$this->assertEquals(0, $requestIdCounter);
}
}