Add @covers tags for more tests
[lhc/web/wiklou.git] / tests / phpunit / includes / libs / DnsSrvDiscovererTest.php
1 <?php
2
3 /**
4 * @covers DnsSrvDiscoverer
5 */
6 class DnsSrvDiscovererTest extends PHPUnit_Framework_TestCase {
7 /**
8 * @dataProvider provideRecords
9 */
10 public function testPickServer( $params, $expected ) {
11 $discoverer = new DnsSrvDiscoverer( 'etcd-tcp.example.net' );
12 $record = $discoverer->pickServer( $params );
13
14 $this->assertEquals( $expected, $record );
15 }
16
17 public static function provideRecords() {
18 return [
19 [
20 [ // record list
21 [
22 'target' => 'conf03.example.net',
23 'port' => 'SRV',
24 'pri' => 0,
25 'weight' => 1,
26 ],
27 [
28 'target' => 'conf02.example.net',
29 'port' => 'SRV',
30 'pri' => 1,
31 'weight' => 1,
32 ],
33 [
34 'target' => 'conf01.example.net',
35 'port' => 'SRV',
36 'pri' => 2,
37 'weight' => 1,
38 ],
39 ], // selected record
40 [
41 'target' => 'conf03.example.net',
42 'port' => 'SRV',
43 'pri' => 0,
44 'weight' => 1,
45 ]
46 ],
47 [
48 [ // record list
49 [
50 'target' => 'conf03or2.example.net',
51 'port' => 'SRV',
52 'pri' => 0,
53 'weight' => 1,
54 ],
55 [
56 'target' => 'conf03or2.example.net',
57 'port' => 'SRV',
58 'pri' => 0,
59 'weight' => 1,
60 ],
61 [
62 'target' => 'conf01.example.net',
63 'port' => 'SRV',
64 'pri' => 2,
65 'weight' => 1,
66 ],
67 [
68 'target' => 'conf04.example.net',
69 'port' => 'SRV',
70 'pri' => 2,
71 'weight' => 1,
72 ],
73 [
74 'target' => 'conf05.example.net',
75 'port' => 'SRV',
76 'pri' => 3,
77 'weight' => 1,
78 ],
79 ], // selected record
80 [
81 'target' => 'conf03or2.example.net',
82 'port' => 'SRV',
83 'pri' => 0,
84 'weight' => 1,
85 ]
86 ],
87 ];
88 }
89
90 public function testRemoveServer() {
91 $dsd = new DnsSrvDiscoverer( 'localhost' );
92
93 $servers = [
94 [
95 'target' => 'conf01.example.net',
96 'port' => 35,
97 'pri' => 2,
98 'weight' => 1,
99 ],
100 [
101 'target' => 'conf04.example.net',
102 'port' => 74,
103 'pri' => 2,
104 'weight' => 1,
105 ],
106 [
107 'target' => 'conf05.example.net',
108 'port' => 77,
109 'pri' => 3,
110 'weight' => 1,
111 ],
112 ];
113 $server = $servers[1];
114
115 $expected = [
116 [
117 'target' => 'conf01.example.net',
118 'port' => 35,
119 'pri' => 2,
120 'weight' => 1,
121 ],
122 [
123 'target' => 'conf05.example.net',
124 'port' => 77,
125 'pri' => 3,
126 'weight' => 1,
127 ],
128 ];
129
130 $this->assertEquals(
131 $expected,
132 $dsd->removeServer( $server, $servers ),
133 "Correct server removed"
134 );
135 $this->assertEquals(
136 $expected,
137 $dsd->removeServer( $server, $servers ),
138 "Nothing to remove"
139 );
140 }
141 }