SystemResolverTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetAnswerWithEmptyQuestion() 0 4 1
A testGetAnswer() 0 36 1
1
<?php
2
3
/*
4
 * This file is part of PHP DNS Server.
5
 *
6
 * (c) Yif Swery <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace yswery\DNS\Tests\Resolver;
13
14
use PHPUnit\Framework\TestCase;
15
use yswery\DNS\RecordTypeEnum;
16
use yswery\DNS\Resolver\SystemResolver;
17
use yswery\DNS\ResourceRecord;
18
19
class SystemResolverTest extends TestCase
20
{
21
    /**
22
     * @throws \yswery\DNS\UnsupportedTypeException
23
     */
24
    public function testGetAnswer()
25
    {
26
        $query1 = (new ResourceRecord())
27
            ->setQuestion(true)
28
            ->setName('google-public-dns-a.google.com.')
29
            ->setType(RecordTypeEnum::TYPE_A);
30
31
        $expectation1 = '8.8.8.8';
32
33
        $query2 = (new ResourceRecord())
34
            ->setQuestion(true)
35
            ->setName('google-public-dns-a.google.com.')
36
            ->setType(RecordTypeEnum::TYPE_AAAA);
37
38
        $expectation2 = '2001:4860:4860::8888';
39
40
        $query3 = (new ResourceRecord())
41
            ->setQuestion(true)
42
            ->setName('google-public-dns-b.google.com.')
43
            ->setType(RecordTypeEnum::TYPE_A);
44
45
        $expectation3 = '8.8.4.4';
46
47
        $query4 = (new ResourceRecord())
48
            ->setQuestion(true)
49
            ->setName('google-public-dns-b.google.com.')
50
            ->setType(RecordTypeEnum::TYPE_AAAA);
51
52
        $expectation4 = '2001:4860:4860::8844';
53
54
        $resolver = new SystemResolver();
55
56
        $this->assertEquals($expectation1, $resolver->getAnswer([$query1])[0]->getRdata());
57
        $this->assertEquals($expectation2, $resolver->getAnswer([$query2])[0]->getRdata());
58
        $this->assertEquals($expectation3, $resolver->getAnswer([$query3])[0]->getRdata());
59
        $this->assertEquals($expectation4, $resolver->getAnswer([$query4])[0]->getRdata());
60
    }
61
62
    /**
63
     * @throws \yswery\DNS\UnsupportedTypeException
64
     */
65
    public function testGetAnswerWithEmptyQuestion()
66
    {
67
        $resolver = new SystemResolver();
68
        $this->assertEquals([], $resolver->getAnswer([]));
69
    }
70
}
71