1
0
mirror of https://github.com/danog/dns.git synced 2024-12-02 17:38:05 +01:00
dns/test/SocketTest.php

47 lines
1.2 KiB
PHP
Raw Normal View History

2017-06-29 12:36:09 +02:00
<?php
namespace Amp\Dns\Test;
use Amp\Dns;
use Amp\Loop;
use Amp\PHPUnit\TestCase;
use Amp\Promise;
use LibDNS\Messages\Message;
use LibDNS\Messages\MessageTypes;
use LibDNS\Records\QuestionFactory;
2019-01-25 02:27:47 +01:00
abstract class SocketTest extends TestCase
{
2017-06-29 12:36:09 +02:00
abstract protected function connect(): Promise;
2019-01-25 02:27:47 +01:00
public function testAsk()
{
2017-06-29 12:36:09 +02:00
Loop::run(function () {
$question = (new QuestionFactory)->create(Dns\Record::A);
$question->setName("google.com");
/** @var Dns\Internal\Socket $socket */
$socket = yield $this->connect();
/** @var Message $result */
$result = yield $socket->ask($question, 5000);
$this->assertInstanceOf(Message::class, $result);
$this->assertSame(MessageTypes::RESPONSE, $result->getType());
});
}
2018-03-11 09:39:46 +01:00
2019-01-25 02:27:47 +01:00
public function testGetLastActivity()
{
2018-03-11 09:39:46 +01:00
Loop::run(function () {
$question = (new QuestionFactory)->create(Dns\Record::A);
$question->setName("google.com");
/** @var Dns\Internal\Socket $socket */
$socket = yield $this->connect();
2019-01-25 02:27:47 +01:00
$this->assertLessThan(\time() + 1, $socket->getLastActivity());
2018-03-11 09:39:46 +01:00
});
}
2017-06-29 12:36:09 +02:00
}