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