Test Failed
Push — rankClass ( 1b9cf4 )
by no
07:58
created

StatementRankTest   A

Complexity

Total Complexity 31

Size/Duplication

Total Lines 303
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 31
lcom 2
cbo 2
dl 0
loc 303
rs 9.92
c 0
b 0
f 0

30 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstants() 0 5 1
A testGetNames() 0 7 1
A testGetAllRanks() 0 7 1
A testGivenInvalidRank_assertIsValidThrowsException() 0 4 1
A testGivenValidRank_assertIsValidSucceeds() 0 4 1
A testGivenInvalidRank_isValidFails() 0 3 1
A testGivenInvalidRank_isValidSucceeds() 0 3 1
A testGivenInvalidRank_isFalseThrowsException() 0 4 1
A testIsFalse() 0 3 1
A isFalseProvider() 0 7 1
A testGivenInvalidRank_isEqualThrowsException() 0 4 1
A testIsEqual() 0 3 1
A isEqualProvider() 0 20 1
A testGivenInvalidRank_isLowerThrowsException() 0 4 1
A testIsLower() 0 3 1
A isLowerProvider() 0 20 1
A testGivenInvalidRank_isHigherThrowsException() 0 4 1
A testIsHigher() 0 3 1
A isHigherProvider() 0 20 1
A testGivenInvalidRank_compareThrowsException() 0 4 1
A testCompare() 0 3 1
A compareProvider() 0 20 1
A testGivenInvalidRank_findBestRankThrowsException() 0 4 1
A testGivenInvalidArray_findBestRankThrowsException() 0 4 1
A testFindBestRank() 0 3 1
A findBestRankProvider() 0 16 1
A integerRangeProvider() 0 7 1
A neitherIntegerRangeNorNullProvider() 0 14 1
A notInIntegerRangeProvider() 0 5 1
A invalidComparisonPairProvider() 0 11 2
1
<?php
2
3
namespace Wikibase\DataModel\Tests\Statement;
4
5
use PHPUnit_Framework_TestCase;
6
use Wikibase\DataModel\Statement\StatementRank;
7
8
/**
9
 * @covers Wikibase\DataModel\Statement\StatementRank
10
 *
11
 * @group Wikibase
12
 * @group WikibaseDataModel
13
 * @group WikibaseStatement
14
 *
15
 * @licence GNU GPL v2+
16
 * @author Thiemo Mättig
17
 */
18
class StatementRankTest extends PHPUnit_Framework_TestCase {
19
20
	public function testConstants() {
21
		$this->assertSame( 0, StatementRank::DEPRECATED );
22
		$this->assertSame( 1, StatementRank::NORMAL );
23
		$this->assertSame( 2, StatementRank::PREFERRED );
24
	}
25
26
	public function testGetNames() {
27
		$this->assertSame( array(
28
			'deprecated',
29
			'normal',
30
			'preferred',
31
		), StatementRank::getNames() );
32
	}
33
34
	public function testGetAllRanks() {
35
		$this->assertSame( array(
36
			'deprecated' => 0,
37
			'normal' => 1,
38
			'preferred' => 2,
39
		), StatementRank::getAllRanks() );
40
	}
41
42
	/**
43
	 * @dataProvider notInIntegerRangeProvider
44
	 */
45
	public function testGivenInvalidRank_assertIsValidThrowsException( $rank ) {
46
		$this->setExpectedException( 'InvalidArgumentException' );
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
47
		StatementRank::assertIsValid( $rank );
48
	}
49
50
	/**
51
	 * @dataProvider integerRangeProvider
52
	 */
53
	public function testGivenValidRank_assertIsValidSucceeds( $rank ) {
54
		StatementRank::assertIsValid( $rank );
55
		$this->assertTrue( true );
56
	}
57
58
	/**
59
	 * @dataProvider notInIntegerRangeProvider
60
	 */
61
	public function testGivenInvalidRank_isValidFails( $rank ) {
62
		$this->assertFalse( StatementRank::isValid( $rank ) );
63
	}
64
65
	/**
66
	 * @dataProvider integerRangeProvider
67
	 */
68
	public function testGivenInvalidRank_isValidSucceeds( $rank ) {
69
		$this->assertTrue( StatementRank::isValid( $rank ) );
70
	}
71
72
	/**
73
	 * @dataProvider notInIntegerRangeProvider
74
	 */
75
	public function testGivenInvalidRank_isFalseThrowsException( $rank ) {
76
		$this->setExpectedException( 'InvalidArgumentException' );
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
77
		StatementRank::isFalse( $rank );
78
	}
79
80
	/**
81
	 * @dataProvider isFalseProvider
82
	 */
83
	public function testIsFalse( $rank, $expected ) {
84
		$this->assertSame( $expected, StatementRank::isFalse( $rank ) );
85
	}
86
87
	public function isFalseProvider() {
88
		return array(
89
			array( 0, true ),
90
			array( 1, false ),
91
			array( 2, false ),
92
		);
93
	}
94
95
	/**
96
	 * @dataProvider invalidComparisonPairProvider
97
	 */
98
	public function testGivenInvalidRank_isEqualThrowsException( $rank1, $rank2 ) {
99
		$this->setExpectedException( 'InvalidArgumentException' );
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
100
		StatementRank::isEqual( $rank1, $rank2 );
101
	}
102
103
	/**
104
	 * @dataProvider isEqualProvider
105
	 */
106
	public function testIsEqual( $rank1, $rank2, $expected ) {
107
		$this->assertSame( $expected, StatementRank::isEqual( $rank1, $rank2 ) );
108
	}
109
110
	public function isEqualProvider() {
111
		return array(
112
			array( null, null, true ),
113
			array( null, 0, false ),
114
			array( null, 1, false ),
115
			array( null, 2, false ),
116
			array( 0, null, false ),
117
			array( 0, 0, true ),
118
			array( 0, 1, false ),
119
			array( 0, 2, false ),
120
			array( 1, null, false ),
121
			array( 1, 0, false ),
122
			array( 1, 1, true ),
123
			array( 1, 2, false ),
124
			array( 2, null, false ),
125
			array( 2, 0, false ),
126
			array( 2, 1, false ),
127
			array( 2, 2, true ),
128
		);
129
	}
130
131
	/**
132
	 * @dataProvider invalidComparisonPairProvider
133
	 */
134
	public function testGivenInvalidRank_isLowerThrowsException( $rank1, $rank2 ) {
135
		$this->setExpectedException( 'InvalidArgumentException' );
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
136
		StatementRank::isLower( $rank1, $rank2 );
137
	}
138
139
	/**
140
	 * @dataProvider isLowerProvider
141
	 */
142
	public function testIsLower( $rank1, $rank2, $expected ) {
143
		$this->assertSame( $expected, StatementRank::isLower( $rank1, $rank2 ) );
144
	}
145
146
	public function isLowerProvider() {
147
		return array(
148
			array( null, null, false ),
149
			array( null, 0, true ),
150
			array( null, 1, true ),
151
			array( null, 2, true ),
152
			array( 0, null, false ),
153
			array( 0, 0, false ),
154
			array( 0, 1, true ),
155
			array( 0, 2, true ),
156
			array( 1, null, false ),
157
			array( 1, 0, false ),
158
			array( 1, 1, false ),
159
			array( 1, 2, true ),
160
			array( 2, null, false ),
161
			array( 2, 0, false ),
162
			array( 2, 1, false ),
163
			array( 2, 2, false ),
164
		);
165
	}
166
167
	/**
168
	 * @dataProvider invalidComparisonPairProvider
169
	 */
170
	public function testGivenInvalidRank_isHigherThrowsException( $rank1, $rank2 ) {
171
		$this->setExpectedException( 'InvalidArgumentException' );
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
172
		StatementRank::isHigher( $rank1, $rank2 );
173
	}
174
175
	/**
176
	 * @dataProvider isHigherProvider
177
	 */
178
	public function testIsHigher( $rank1, $rank2, $expected ) {
179
		$this->assertSame( $expected, StatementRank::isHigher( $rank1, $rank2 ) );
180
	}
181
182
	public function isHigherProvider() {
183
		return array(
184
			array( null, null, false ),
185
			array( null, 0, false ),
186
			array( null, 1, false ),
187
			array( null, 2, false ),
188
			array( 0, null, true ),
189
			array( 0, 0, false ),
190
			array( 0, 1, false ),
191
			array( 0, 2, false ),
192
			array( 1, null, true ),
193
			array( 1, 0, true ),
194
			array( 1, 1, false ),
195
			array( 1, 2, false ),
196
			array( 2, null, true ),
197
			array( 2, 0, true ),
198
			array( 2, 1, true ),
199
			array( 2, 2, false ),
200
		);
201
	}
202
203
	/**
204
	 * @dataProvider invalidComparisonPairProvider
205
	 */
206
	public function testGivenInvalidRank_compareThrowsException( $rank1, $rank2 ) {
207
		$this->setExpectedException( 'InvalidArgumentException' );
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
208
		StatementRank::compare( $rank1, $rank2 );
209
	}
210
211
	/**
212
	 * @dataProvider compareProvider
213
	 */
214
	public function testCompare( $rank1, $rank2, $expected ) {
215
		$this->assertSame( $expected, StatementRank::compare( $rank1, $rank2 ) );
216
	}
217
218
	public function compareProvider() {
219
		return array(
220
			array( null, null, 0 ),
221
			array( null, 0, -1 ),
222
			array( null, 1, -1 ),
223
			array( null, 2, -1 ),
224
			array( 0, null, 1 ),
225
			array( 0, 0, 0 ),
226
			array( 0, 1, -1 ),
227
			array( 0, 2, -1 ),
228
			array( 1, null, 1 ),
229
			array( 1, 0, 1 ),
230
			array( 1, 1, 0 ),
231
			array( 1, 2, -1 ),
232
			array( 2, null, 1 ),
233
			array( 2, 0, 1 ),
234
			array( 2, 1, 1 ),
235
			array( 2, 2, 0 ),
236
		);
237
	}
238
239
	/**
240
	 * @dataProvider neitherIntegerRangeNorNullProvider
241
	 */
242
	public function testGivenInvalidRank_findBestRankThrowsException( $rank ) {
243
		$this->setExpectedException( 'InvalidArgumentException' );
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
244
		StatementRank::findBestRank( $rank );
245
	}
246
247
	/**
248
	 * @dataProvider invalidComparisonPairProvider
249
	 */
250
	public function testGivenInvalidArray_findBestRankThrowsException( $rank1, $rank2 ) {
251
		$this->setExpectedException( 'InvalidArgumentException' );
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
252
		StatementRank::findBestRank( array( $rank1, $rank2 ) );
253
	}
254
255
	/**
256
	 * @dataProvider findBestRankProvider
257
	 */
258
	public function testFindBestRank( $ranks, $expected ) {
259
		$this->assertSame( $expected, StatementRank::findBestRank( $ranks ) );
260
	}
261
262
	public function findBestRankProvider() {
263
		return array(
264
			array( null, null ),
265
			array( 0, 0 ),
266
			array( 1, 1 ),
267
			array( array(), null ),
268
			array( array( null ), null ),
269
			array( array( 0 ), 0 ),
270
			array( array( 1 ), 1 ),
271
			array( array( null, 0 ), 0 ),
272
			array( array( 0, null ), 0 ),
273
			array( array( 0, 1 ), 1 ),
274
			array( array( null, 0, 1, 2 ), 2 ),
275
			array( array( 2, 1, 0, null ), 2 ),
276
		);
277
	}
278
279
	public function integerRangeProvider() {
280
		return array(
281
			array( 0 ),
282
			array( 1 ),
283
			array( 2 ),
284
		);
285
	}
286
287
	public function neitherIntegerRangeNorNullProvider() {
288
		return array(
289
			array( false ),
290
			array( true ),
291
			array( NAN ),
292
			array( INF ),
293
			array( '0' ),
294
			array( '1' ),
295
			array( 0.0 ),
296
			array( 1.0 ),
297
			array( -1 ),
298
			array( 3 ),
299
		);
300
	}
301
302
	public function notInIntegerRangeProvider() {
303
		$invalid = $this->neitherIntegerRangeNorNullProvider();
304
		$invalid[] = array( null );
305
		return $invalid;
306
	}
307
308
	public function invalidComparisonPairProvider() {
309
		$invalid = $this->neitherIntegerRangeNorNullProvider();
310
		$pairs = array();
311
312
		foreach ( $invalid as $args ) {
313
			$pairs[] = array( 1, $args[0] );
314
			$pairs[] = array( $args[0], 1 );
315
		}
316
317
		return $pairs;
318
	}
319
320
}
321