mirror of
https://github.com/danog/dns.git
synced 2024-11-26 20:14:51 +01:00
Add tests (#71)
This commit is contained in:
parent
2c8133a7b4
commit
6cdea2e995
23
test/RecordTest.php
Normal file
23
test/RecordTest.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Amp\Dns\Test;
|
||||||
|
|
||||||
|
use Amp\Dns\Record;
|
||||||
|
use Amp\PHPUnit\TestCase;
|
||||||
|
|
||||||
|
class RecordTest extends TestCase {
|
||||||
|
public function testGetName() {
|
||||||
|
$this->assertSame("A", Record::getName(Record::A));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetNameOnInvalidRecordType() {
|
||||||
|
$this->expectException(\Error::class);
|
||||||
|
$this->expectExceptionMessage("65536 does not correspond to a valid record type (must be between 0 and 65535).");
|
||||||
|
|
||||||
|
Record::getName(65536);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGetNameOnUnknownRecordType() {
|
||||||
|
$this->assertSame("unknown (1000)", Record::getName(1000));
|
||||||
|
}
|
||||||
|
}
|
@ -28,4 +28,16 @@ abstract class SocketTest extends TestCase {
|
|||||||
$this->assertSame(MessageTypes::RESPONSE, $result->getType());
|
$this->assertSame(MessageTypes::RESPONSE, $result->getType());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetLastActivity() {
|
||||||
|
Loop::run(function () {
|
||||||
|
$question = (new QuestionFactory)->create(Dns\Record::A);
|
||||||
|
$question->setName("google.com");
|
||||||
|
|
||||||
|
/** @var Dns\Internal\Socket $socket */
|
||||||
|
$socket = yield $this->connect();
|
||||||
|
|
||||||
|
$this->assertTrue($socket->getLastActivity() < time() + 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user