JsonResolverTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testIsWildcardDomain() 0 13 1
A setUp() 0 7 1
A testResolveLegacyRecord() 0 14 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 yswery\DNS\RecordTypeEnum;
15
use yswery\DNS\Resolver\JsonResolver;
16
use yswery\DNS\ResourceRecord;
17
18
class JsonResolverTest extends AbstractResolverTest
19
{
20
    /**
21
     * @throws \yswery\DNS\UnsupportedTypeException
22
     */
23
    public function setUp()
24
    {
25
        $files = [
26
            __DIR__.'/../Resources/example.com.json',
27
            __DIR__.'/../Resources/test_records.json',
28
        ];
29
        $this->resolver = new JsonResolver($files, 300);
30
    }
31
32
    public function testResolveLegacyRecord()
33
    {
34
        $question[] = (new ResourceRecord())
0 ignored issues
show
Comprehensibility Best Practice introduced by
$question was never initialized. Although not strictly required by PHP, it is generally a good practice to add $question = array(); before regardless.
Loading history...
35
            ->setName('test.com.')
36
            ->setType(RecordTypeEnum::TYPE_A)
37
            ->setQuestion(true);
38
39
        $expectation[] = (new ResourceRecord())
0 ignored issues
show
Comprehensibility Best Practice introduced by
$expectation was never initialized. Although not strictly required by PHP, it is generally a good practice to add $expectation = array(); before regardless.
Loading history...
40
            ->setName('test.com.')
41
            ->setType(RecordTypeEnum::TYPE_A)
42
            ->setTtl(300)
43
            ->setRdata('111.111.111.111');
44
45
        $this->assertEquals($expectation, $this->resolver->getAnswer($question));
46
    }
47
48
    /**
49
     * @throws \yswery\DNS\UnsupportedTypeException
50
     */
51
    public function testIsWildcardDomain()
52
    {
53
        $input1 = '*.example.com.';
54
        $input2 = '*.sub.domain.com.';
55
        $input3 = '*';
56
        $input4 = 'www.test.com.au.';
57
58
        $resolver = new JsonResolver([]);
59
60
        $this->assertTrue($resolver->isWildcardDomain($input1));
61
        $this->assertTrue($resolver->isWildcardDomain($input2));
62
        $this->assertTrue($resolver->isWildcardDomain($input3));
63
        $this->assertFalse($resolver->isWildcardDomain($input4));
64
    }
65
}
66