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()) |
|
|
|
|
45
|
|
|
->setName('test2.com.') |
46
|
|
|
->setType(RecordTypeEnum::TYPE_MX) |
47
|
|
|
->setQuestion(true); |
48
|
|
|
|
49
|
|
|
$expectation[] = (new ResourceRecord()) |
|
|
|
|
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
|
|
|
|