1
0
mirror of https://github.com/danog/dns.git synced 2024-11-30 04:29:06 +01:00
dns/test/SocketTest.php
2023-01-09 23:33:46 +01:00

39 lines
993 B
PHP

<?php declare(strict_types=1);
namespace Amp\Dns\Test;
use Amp\Dns;
use Amp\PHPUnit\AsyncTestCase;
use LibDNS\Messages\Message;
use LibDNS\Messages\MessageTypes;
use LibDNS\Records\QuestionFactory;
use function Amp\now;
abstract class SocketTest extends AsyncTestCase
{
public function testAsk(): void
{
$question = (new QuestionFactory)->create(Dns\DnsRecord::A);
$question->setName("google.com");
$socket = $this->connect();
$result = $socket->ask($question, 5000);
self::assertInstanceOf(Message::class, $result);
self::assertSame(MessageTypes::RESPONSE, $result->getType());
}
public function testGetLastActivity(): void
{
$question = (new QuestionFactory)->create(Dns\DnsRecord::A);
$question->setName("google.com");
$socket = $this->connect();
self::assertLessThan(now() + 1, $socket->getLastActivity());
}
abstract protected function connect(): Dns\Internal\Socket;
}