aboutsummaryrefslogtreecommitdiffhomepage
path: root/assets/php/vendor/react/dns/tests/Resolver/ResolveAliasesTest.php
blob: b5175e3ed508ff723f1ddd24fe6b802c6d6370a1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php

namespace React\Tests\Dns\Resolver;

use PHPUnit\Framework\TestCase;
use React\Dns\Resolver\Resolver;
use React\Dns\Query\Query;
use React\Dns\Model\Message;
use React\Dns\Model\Record;

class ResolveAliasesTest extends TestCase
{
    /**
     * @covers React\Dns\Resolver\Resolver::resolveAliases
     * @dataProvider provideAliasedAnswers
     */
    public function testResolveAliases(array $expectedAnswers, array $answers, $name)
    {
        $executor = $this->createExecutorMock();
        $resolver = new Resolver('8.8.8.8:53', $executor);

        $answers = $resolver->resolveAliases($answers, $name);

        $this->assertEquals($expectedAnswers, $answers);
    }

    public function provideAliasedAnswers()
    {
        return array(
            array(
                array('178.79.169.131'),
                array(
                    new Record('igor.io', Message::TYPE_A, Message::CLASS_IN, 3600, '178.79.169.131'),
                ),
                'igor.io',
            ),
            array(
                array('178.79.169.131', '178.79.169.132', '178.79.169.133'),
                array(
                    new Record('igor.io', Message::TYPE_A, Message::CLASS_IN, 3600, '178.79.169.131'),
                    new Record('igor.io', Message::TYPE_A, Message::CLASS_IN, 3600, '178.79.169.132'),
                    new Record('igor.io', Message::TYPE_A, Message::CLASS_IN, 3600, '178.79.169.133'),
                ),
                'igor.io',
            ),
            array(
                array('178.79.169.131'),
                array(
                    new Record('igor.io', Message::TYPE_A, Message::CLASS_IN, 3600, '178.79.169.131'),
                    new Record('foo.igor.io', Message::TYPE_A, Message::CLASS_IN, 3600, '178.79.169.131'),
                    new Record('bar.igor.io', Message::TYPE_A, Message::CLASS_IN, 3600, '178.79.169.131'),
                ),
                'igor.io',
            ),
            array(
                array(),
                array(
                    new Record('foo.igor.io', Message::TYPE_A, Message::CLASS_IN),
                    new Record('bar.igor.io', Message::TYPE_A, Message::CLASS_IN),
                ),
                'igor.io',
            ),
            array(
                array('178.79.169.131'),
                array(
                    new Record('igor.io', Message::TYPE_CNAME, Message::CLASS_IN, 3600, 'foo.igor.io'),
                    new Record('foo.igor.io', Message::TYPE_A, Message::CLASS_IN, 3600, '178.79.169.131'),
                ),
                'igor.io',
            ),
            array(
                array('178.79.169.131'),
                array(
                    new Record('igor.io', Message::TYPE_CNAME, Message::CLASS_IN, 3600, 'foo.igor.io'),
                    new Record('foo.igor.io', Message::TYPE_CNAME, Message::CLASS_IN, 3600, 'bar.igor.io'),
                    new Record('bar.igor.io', Message::TYPE_A, Message::CLASS_IN, 3600, '178.79.169.131'),
                ),
                'igor.io',
            ),
            array(
                array('178.79.169.131', '178.79.169.132', '178.79.169.133'),
                array(
                    new Record('igor.io', Message::TYPE_CNAME, Message::CLASS_IN, 3600, 'foo.igor.io'),
                    new Record('foo.igor.io', Message::TYPE_CNAME, Message::CLASS_IN, 3600, 'bar.igor.io'),
                    new Record('bar.igor.io', Message::TYPE_CNAME, Message::CLASS_IN, 3600, 'baz.igor.io'),
                    new Record('bar.igor.io', Message::TYPE_CNAME, Message::CLASS_IN, 3600, 'qux.igor.io'),
                    new Record('baz.igor.io', Message::TYPE_A, Message::CLASS_IN, 3600, '178.79.169.131'),
                    new Record('baz.igor.io', Message::TYPE_A, Message::CLASS_IN, 3600, '178.79.169.132'),
                    new Record('qux.igor.io', Message::TYPE_A, Message::CLASS_IN, 3600, '178.79.169.133'),
                ),
                'igor.io',
            ),
        );
    }

    private function createExecutorMock()
    {
        return $this->getMockBuilder('React\Dns\Query\ExecutorInterface')->getMock();
    }
}