Passed
Push — master ( d7fd0c...0cd2cd )
by Sam
04:33
created

YamlResolverTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 26
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testParseException() 0 4 1
A setUp() 0 7 1
A testResolveLegacyRecord() 0 26 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 Symfony\Component\Yaml\Exception\ParseException;
15
use yswery\DNS\Resolver\YamlResolver;
16
use yswery\DNS\ResourceRecord;
17
use yswery\DNS\RecordTypeEnum;
18
19
class YamlResolverTest extends AbstractResolverTest
20
{
21
    /**
22
     * @throws \Exception
23
     */
24
    public function setUp()
25
    {
26
        $files = [
27
            __DIR__.'/../Resources/records.yml',
28
            __DIR__.'/../Resources/example.com.yml',
29
        ];
30
        $this->resolver = new YamlResolver($files);
31
    }
32
33
    /**
34
     * @throws \Exception
35
     */
36
    public function testParseException()
37
    {
38
        $this->expectException(ParseException::class);
39
        new YamlResolver([__DIR__.'/../Resources/invalid_dns_records.json']);
40
    }
41
42
    public function testResolveLegacyRecord()
43
    {
44
        $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...
45
            ->setName('test2.com.')
46
            ->setType(RecordTypeEnum::TYPE_MX)
47
            ->setQuestion(true);
48
49
        $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...
50
            ->setName('test2.com.')
51
            ->setType(RecordTypeEnum::TYPE_MX)
52
            ->setTtl(300)
53
            ->setRdata([
54
                'preference' => 20,
55
                'exchange' => 'mail-gw1.test2.com.',
56
            ]);
57
58
        $expectation[] = (new ResourceRecord())
59
            ->setName('test2.com.')
60
            ->setType(RecordTypeEnum::TYPE_MX)
61
            ->setTtl(300)
62
            ->setRdata([
63
                'preference' => 30,
64
                'exchange' => 'mail-gw2.test2.com.',
65
            ]);
66
67
        $this->assertEquals($expectation, $this->resolver->getAnswer($question));
68
    }
69
}
70