comparison vendor/symfony/phpunit-bridge/Tests/DnsMockTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
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 Symfony\Bridge\PhpUnit\Tests;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Bridge\PhpUnit\DnsMock;
16
17 class DnsMockTest extends TestCase
18 {
19 protected function tearDown()
20 {
21 DnsMock::withMockedHosts(array());
22 }
23
24 public function testCheckdnsrr()
25 {
26 DnsMock::withMockedHosts(array('example.com' => array(array('type' => 'MX'))));
27 $this->assertTrue(DnsMock::checkdnsrr('example.com'));
28
29 DnsMock::withMockedHosts(array('example.com' => array(array('type' => 'A'))));
30 $this->assertFalse(DnsMock::checkdnsrr('example.com'));
31 $this->assertTrue(DnsMock::checkdnsrr('example.com', 'a'));
32 $this->assertTrue(DnsMock::checkdnsrr('example.com', 'any'));
33 $this->assertFalse(DnsMock::checkdnsrr('foobar.com', 'ANY'));
34 }
35
36 public function testGetmxrr()
37 {
38 DnsMock::withMockedHosts(array(
39 'example.com' => array(array(
40 'type' => 'MX',
41 'host' => 'mx.example.com',
42 'pri' => 10,
43 )),
44 ));
45
46 $this->assertFalse(DnsMock::getmxrr('foobar.com', $mxhosts, $weight));
47 $this->assertTrue(DnsMock::getmxrr('example.com', $mxhosts, $weight));
48 $this->assertSame(array('mx.example.com'), $mxhosts);
49 $this->assertSame(array(10), $weight);
50 }
51
52 public function testGethostbyaddr()
53 {
54 DnsMock::withMockedHosts(array(
55 'example.com' => array(
56 array(
57 'type' => 'A',
58 'ip' => '1.2.3.4',
59 ),
60 array(
61 'type' => 'AAAA',
62 'ipv6' => '::12',
63 ),
64 ),
65 ));
66
67 $this->assertSame('::21', DnsMock::gethostbyaddr('::21'));
68 $this->assertSame('example.com', DnsMock::gethostbyaddr('::12'));
69 $this->assertSame('example.com', DnsMock::gethostbyaddr('1.2.3.4'));
70 }
71
72 public function testGethostbyname()
73 {
74 DnsMock::withMockedHosts(array(
75 'example.com' => array(
76 array(
77 'type' => 'AAAA',
78 'ipv6' => '::12',
79 ),
80 array(
81 'type' => 'A',
82 'ip' => '1.2.3.4',
83 ),
84 ),
85 ));
86
87 $this->assertSame('foobar.com', DnsMock::gethostbyname('foobar.com'));
88 $this->assertSame('1.2.3.4', DnsMock::gethostbyname('example.com'));
89 }
90
91 public function testGethostbynamel()
92 {
93 DnsMock::withMockedHosts(array(
94 'example.com' => array(
95 array(
96 'type' => 'A',
97 'ip' => '1.2.3.4',
98 ),
99 array(
100 'type' => 'A',
101 'ip' => '2.3.4.5',
102 ),
103 ),
104 ));
105
106 $this->assertFalse(DnsMock::gethostbynamel('foobar.com'));
107 $this->assertSame(array('1.2.3.4', '2.3.4.5'), DnsMock::gethostbynamel('example.com'));
108 }
109
110 public function testDnsGetRecord()
111 {
112 DnsMock::withMockedHosts(array(
113 'example.com' => array(
114 array(
115 'type' => 'A',
116 'ip' => '1.2.3.4',
117 ),
118 array(
119 'type' => 'PTR',
120 'ip' => '2.3.4.5',
121 ),
122 ),
123 ));
124
125 $records = array(
126 array(
127 'host' => 'example.com',
128 'class' => 'IN',
129 'ttl' => 1,
130 'type' => 'A',
131 'ip' => '1.2.3.4',
132 ),
133 $ptr = array(
134 'host' => 'example.com',
135 'class' => 'IN',
136 'ttl' => 1,
137 'type' => 'PTR',
138 'ip' => '2.3.4.5',
139 ),
140 );
141
142 $this->assertFalse(DnsMock::dns_get_record('foobar.com'));
143 $this->assertSame($records, DnsMock::dns_get_record('example.com'));
144 $this->assertSame($records, DnsMock::dns_get_record('example.com', DNS_ALL));
145 $this->assertSame($records, DnsMock::dns_get_record('example.com', DNS_A | DNS_PTR));
146 $this->assertSame(array($ptr), DnsMock::dns_get_record('example.com', DNS_PTR));
147 }
148 }