1
0
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:
peter279k 2018-03-11 16:39:46 +08:00 committed by Niklas Keller
parent 2c8133a7b4
commit 6cdea2e995
2 changed files with 35 additions and 0 deletions

23
test/RecordTest.php Normal file
View 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));
}
}

View File

@ -28,4 +28,16 @@ abstract class SocketTest extends TestCase {
$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);
});
}
}