From 6cdea2e995195a2d2c2c013688c157f3dd74426c Mon Sep 17 00:00:00 2001 From: peter279k Date: Sun, 11 Mar 2018 16:39:46 +0800 Subject: [PATCH] Add tests (#71) --- test/RecordTest.php | 23 +++++++++++++++++++++++ test/SocketTest.php | 12 ++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 test/RecordTest.php diff --git a/test/RecordTest.php b/test/RecordTest.php new file mode 100644 index 0000000..479de71 --- /dev/null +++ b/test/RecordTest.php @@ -0,0 +1,23 @@ +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)); + } +} diff --git a/test/SocketTest.php b/test/SocketTest.php index 07f907a..ba0d65e 100644 --- a/test/SocketTest.php +++ b/test/SocketTest.php @@ -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); + }); + } }