Passed
Push — entityIdInjection ( 21ce29...71be9d )
by no
05:51
created

MapValueHasherTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4
Metric Value
wmc 3
lcom 0
cbo 4
dl 0
loc 47
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testCanConstruct() 0 4 1
B testHash() 0 31 1
A testHashThrowsExceptionOnInvalidArgument() 0 6 1
1
<?php
2
3
namespace Wikibase\DataModel\Tests\Internal;
4
5
use ArrayObject;
6
use Wikibase\DataModel\Entity\PropertyId;
7
use Wikibase\DataModel\Internal\MapValueHasher;
8
use Wikibase\DataModel\Snak\PropertyNoValueSnak;
9
10
/**
11
 * @covers Wikibase\DataModel\Internal\MapValueHasher
12
 *
13
 * @group Wikibase
14
 * @group WikibaseDataModel
15
 *
16
 * @licence GNU GPL v2+
17
 * @author Jeroen De Dauw < [email protected] >
18
 */
19
class MapValueHasherTest extends \PHPUnit_Framework_TestCase {
20
21
	public function testCanConstruct() {
22
		new MapValueHasher( true );
23
		$this->assertTrue( true );
24
	}
25
26
	public function testHash() {
27
		$hasher = new MapValueHasher();
28
29
		$map0 = array(
30
			'foo' => new PropertyNoValueSnak( new PropertyId( 'P1' ) ),
31
			'bar' => new PropertyNoValueSnak( new PropertyId( 'P2' ) ),
32
			42 => new PropertyNoValueSnak( new PropertyId( 'P42' ) ),
33
			new PropertyNoValueSnak( new PropertyId( 'P9001' ) ),
34
		);
35
36
		$hash = $hasher->hash( $map0 );
37
38
		$map1 = $map0;
39
		unset( $map1['foo'] );
40
		$map1[] = $map0['foo'];
41
42
		$this->assertEquals( $hash, $hasher->hash( $map1 ) );
43
44
		$map4 = new ArrayObject( $map0 );
45
		$this->assertEquals( $hash, $hasher->hash( $map4 ) );
46
47
		$map2 = $map0;
48
		unset( $map2['foo'] );
49
50
		$this->assertNotEquals( $hash, $hasher->hash( $map2 ) );
51
52
		$map3 = $map0;
53
		$map3['foo'] = new PropertyNoValueSnak( new PropertyId( 'P5' ) );
54
55
		$this->assertNotEquals( $hash, $hasher->hash( $map3 ) );
56
	}
57
58
	public function testHashThrowsExceptionOnInvalidArgument() {
59
		$hasher = new MapValueHasher();
60
61
		$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

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...
62
		$hasher->hash( null );
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Traversable>|arra...teger,object<Hashable>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
63
	}
64
65
}
66