Completed
Push — master ( f552f8...7247aa )
by
unknown
03:16
created

providePatchAliasGroupList()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 214
Code Lines 144

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 214
rs 8.2857
cc 1
eloc 144
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Wikibase\DataModel\Services\Tests\Diff\Internal;
4
5
use Diff\DiffOp\Diff\Diff;
6
use Diff\DiffOp\DiffOpAdd;
7
use Diff\DiffOp\DiffOpChange;
8
use Diff\DiffOp\DiffOpRemove;
9
use PHPUnit_Framework_TestCase;
10
use Wikibase\DataModel\Services\Diff\Internal\AliasGroupListPatcher;
11
use Wikibase\DataModel\Term\AliasGroup;
12
use Wikibase\DataModel\Term\AliasGroupList;
13
14
/**
15
 * @covers Wikibase\DataModel\Services\Diff\Internal\AliasGroupListPatcher
16
 *
17
 * @license GPL-2.0+
18
 * @author Bene* < [email protected] >
19
 */
20
class AliasGroupListPatcherTest extends PHPUnit_Framework_TestCase {
21
22
	/**
23
	 * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
24
	 */
25
	public function providePatchAliasGroupList() {
26
		return array(
27
			'add aliases (associative)' => array(
28
				new AliasGroupList(),
29
				new Diff( array(
30
					'en' => new Diff( array( new DiffOpAdd( 'foo' ), new DiffOpAdd( 'bar' ) ) )
31
				), true ),
32
				new AliasGroupList( array(
33
					new AliasGroup( 'en', array( 'foo', 'bar' ) )
34
				) )
35
			),
36
			'add aliases (non-associative)' => array(
37
				new AliasGroupList(),
38
				new Diff( array(
39
					'en' => new Diff( array( new DiffOpAdd( 'foo' ), new DiffOpAdd( 'bar' ) ) )
40
				), false ),
41
				new AliasGroupList( array(
42
					new AliasGroup( 'en', array( 'foo', 'bar' ) )
43
				) )
44
			),
45
			'add aliases (auto-detected)' => array(
46
				new AliasGroupList(),
47
				new Diff( array(
48
					'en' => new Diff( array( new DiffOpAdd( 'foo' ), new DiffOpAdd( 'bar' ) ) )
49
				) ),
50
				new AliasGroupList( array(
51
					new AliasGroup( 'en', array( 'foo', 'bar' ) )
52
				) )
53
			),
54
			'add aliases (atomic)' => array(
55
				new AliasGroupList(),
56
				new Diff( array(
57
					'en' => new DiffOpAdd( array( 'foo', 'bar' ) )
58
				) ),
59
				new AliasGroupList( array(
60
					new AliasGroup( 'en', array( 'foo', 'bar' ) )
61
				) )
62
			),
63
			'change aliase' => array(
64
				new AliasGroupList( array(
65
					new AliasGroup( 'en', array( 'foo', 'bar' ) )
66
				) ),
67
				new Diff( array(
68
					'en' => new Diff( array( new DiffOpChange( 'bar', 'baz' ) ) )
69
				) ),
70
				new AliasGroupList( array(
71
					new AliasGroup( 'en', array( 'foo', 'baz' ) )
72
				) )
73
			),
74
			'change aliases (atomic)' => array(
75
				new AliasGroupList( array(
76
					new AliasGroup( 'en', array( 'foo', 'bar' ) )
77
				) ),
78
				new Diff( array(
79
					'en' => new DiffOpChange( array( 'foo', 'bar' ), array( 'baz' ) )
80
				) ),
81
				new AliasGroupList( array(
82
					new AliasGroup( 'en', array( 'baz' ) )
83
				) )
84
			),
85
			'remove all aliases' => array(
86
				new AliasGroupList( array(
87
					new AliasGroup( 'en', array( 'foo', 'bar' ) )
88
				) ),
89
				new Diff( array(
90
					'en' => new Diff( array( new DiffOpRemove( 'foo' ), new DiffOpRemove( 'bar' ) ) )
91
				) ),
92
				new AliasGroupList()
93
			),
94
			'remove all aliases (atomic)' => array(
95
				new AliasGroupList( array(
96
					new AliasGroup( 'en', array( 'foo', 'bar' ) )
97
				) ),
98
				new Diff( array(
99
					'en' => new DiffOpRemove( array( 'foo', 'bar' ) )
100
				) ),
101
				new AliasGroupList()
102
			),
103
			'remove some aliases' => array(
104
				new AliasGroupList( array(
105
					new AliasGroup( 'en', array( 'foo', 'bar', 'baz' ) )
106
				) ),
107
				new Diff( array(
108
					'en' => new Diff( array( new DiffOpRemove( 'foo' ), new DiffOpRemove( 'bar' ) ) )
109
				) ),
110
				new AliasGroupList( array(
111
					new AliasGroup( 'en', array( 'baz' ) )
112
				) )
113
			),
114
			'remove some aliases is no-op (atomic)' => array(
115
				new AliasGroupList( array(
116
					new AliasGroup( 'en', array( 'foo', 'bar', 'baz' ) )
117
				) ),
118
				new Diff( array(
119
					'en' => new DiffOpRemove( array( 'foo', 'bar' ) )
120
				) ),
121
				new AliasGroupList( array(
122
					new AliasGroup( 'en', array( 'foo', 'bar', 'baz' ) )
123
				) )
124
			),
125
			'add alias to an existing language' => array(
126
				new AliasGroupList( array(
127
					new AliasGroup( 'en', array( 'foo', 'bar' ) )
128
				) ),
129
				new Diff( array(
130
					'en' => new Diff( array( new DiffOpAdd( 'baz' ) ) )
131
				) ),
132
				new AliasGroupList( array(
133
					new AliasGroup( 'en', array( 'foo', 'bar', 'baz' ) )
134
				) )
135
			),
136
			'add an existing language is no-op (atomic)' => array(
137
				new AliasGroupList( array(
138
					new AliasGroup( 'en', array( 'foo', 'bar' ) )
139
				) ),
140
				new Diff( array(
141
					'en' => new DiffOpAdd( array( 'baz' ) )
142
				) ),
143
				new AliasGroupList( array(
144
					new AliasGroup( 'en', array( 'foo', 'bar' ) )
145
				) )
146
			),
147
			'add two alias groups' => array(
148
				new AliasGroupList( array(
149
					new AliasGroup( 'en', array( 'foo', 'bar' ) )
150
				) ),
151
				new Diff( array(
152
					'de' => new Diff( array( new DiffOpAdd( 'foo' ), new DiffOpAdd( 'baz' ) ) ),
153
					'nl' => new Diff( array( new DiffOpAdd( 'bar' ), new DiffOpAdd( 'baz' ) ) )
154
				) ),
155
				new AliasGroupList( array(
156
					new AliasGroup( 'en', array( 'foo', 'bar' ) ),
157
					new AliasGroup( 'de', array( 'foo', 'baz' ) ),
158
					new AliasGroup( 'nl', array( 'bar', 'baz' ) )
159
				) )
160
			),
161
			'add two alias groups (atomic)' => array(
162
				new AliasGroupList( array(
163
					new AliasGroup( 'en', array( 'foo', 'bar' ) )
164
				) ),
165
				new Diff( array(
166
					'de' => new DiffOpAdd( array( 'foo', 'baz' ) ),
167
					'nl' => new DiffOpAdd( array( 'bar', 'baz' ) )
168
				) ),
169
				new AliasGroupList( array(
170
					new AliasGroup( 'en', array( 'foo', 'bar' ) ),
171
					new AliasGroup( 'de', array( 'foo', 'baz' ) ),
172
					new AliasGroup( 'nl', array( 'bar', 'baz' ) )
173
				) )
174
			),
175
			'remove a not existing language is no-op' => array(
176
				new AliasGroupList( array(
177
					new AliasGroup( 'en', array( 'foo', 'bar' ) )
178
				) ),
179
				new Diff( array(
180
					'de' => new Diff( array( new DiffOpRemove( 'bar' ) ) )
181
				) ),
182
				new AliasGroupList( array(
183
					new AliasGroup( 'en', array( 'foo', 'bar' ) )
184
				) )
185
			),
186
			'remove a not existing language is no-op (atomic)' => array(
187
				new AliasGroupList( array(
188
					new AliasGroup( 'en', array( 'foo', 'bar' ) )
189
				) ),
190
				new Diff( array(
191
					'de' => new DiffOpRemove( array( 'bar' ) )
192
				) ),
193
				new AliasGroupList( array(
194
					new AliasGroup( 'en', array( 'foo', 'bar' ) )
195
				) )
196
			),
197
			'change different aliases is no-op' => array(
198
				new AliasGroupList( array(
199
					new AliasGroup( 'en', array( 'foo' ) )
200
				) ),
201
				new Diff( array(
202
					'en' => new Diff( array( new DiffOpChange( 'bar', 'baz' ) ) )
203
				) ),
204
				new AliasGroupList( array(
205
					new AliasGroup( 'en', array( 'foo' ) )
206
				) )
207
			),
208
			'change different aliases is no-op (atomic)' => array(
209
				new AliasGroupList( array(
210
					new AliasGroup( 'en', array( 'foo', 'bar' ) )
211
				) ),
212
				new Diff( array(
213
					'en' => new DiffOpChange( array( 'foo', 'baz' ), array( 'baz' ) )
214
				) ),
215
				new AliasGroupList( array(
216
					new AliasGroup( 'en', array( 'foo', 'bar' ) )
217
				) )
218
			),
219
			'complex diff' => array(
220
				new AliasGroupList( array(
221
					new AliasGroup( 'en', array( 'foo', 'bar' ) ),
222
					new AliasGroup( 'de', array( 'foo', 'baz' ) ),
223
				    new AliasGroup( 'nl', array( 'bar', 'baz' ) )
224
				) ),
225
				new Diff( array(
226
					'en' => new Diff( array( new DiffOpRemove( 'foo' ), new DiffOpAdd( 'baz' ) ) ),
227
					'de' => new Diff( array( new DiffOpRemove( 'foo' ), new DiffOpRemove( 'baz' ) ) ),
228
					'nl' => new Diff( array( new DiffOpRemove( 'foo' ), new DiffOpRemove( 'bar' ) ) ),
229
					'it' => new Diff( array( new DiffOpAdd( 'bar' ), new DiffOpAdd( 'baz' ) ) )
230
				) ),
231
				new AliasGroupList( array(
232
					new AliasGroup( 'en', array( 'bar', 'baz' ) ),
233
					new AliasGroup( 'nl', array( 'baz' ) ),
234
					new AliasGroup( 'it', array( 'bar', 'baz' ) )
235
				) )
236
			),
237
		);
238
	}
239
240
	/**
241
	 * @dataProvider providePatchAliasGroupList
242
	 */
243
	public function testPatchAliasGroupList( AliasGroupList $aliasGroups, Diff $patch, AliasGroupList $expected ) {
244
		$patcher = new AliasGroupListPatcher();
245
		$patcher->patchAliasGroupList( $aliasGroups, $patch );
246
247
		$this->assertSame( $expected->toTextArray(), $aliasGroups->toTextArray() );
248
	}
249
250
}
251