MapValueHasherTest::testHash()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 9.424
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Wikibase\DataModel\Tests\Internal;
4
5
use ArrayObject;
6
use InvalidArgumentException;
7
use Wikibase\DataModel\Entity\PropertyId;
8
use Wikibase\DataModel\Internal\MapValueHasher;
9
use Wikibase\DataModel\Snak\PropertyNoValueSnak;
10
11
/**
12
 * @covers \Wikibase\DataModel\Internal\MapValueHasher
13
 *
14
 * @group Wikibase
15
 * @group WikibaseDataModel
16
 *
17
 * @license GPL-2.0-or-later
18
 * @author Jeroen De Dauw < [email protected] >
19
 */
20
class MapValueHasherTest extends \PHPUnit\Framework\TestCase {
21
22
	public function testCanConstruct() {
23
		new MapValueHasher( true );
24
		$this->assertTrue( true );
25
	}
26
27
	public function testHash() {
28
		$hasher = new MapValueHasher();
29
30
		$map0 = [
31
			'foo' => new PropertyNoValueSnak( new PropertyId( 'P1' ) ),
32
			'bar' => new PropertyNoValueSnak( new PropertyId( 'P2' ) ),
33
			42 => new PropertyNoValueSnak( new PropertyId( 'P42' ) ),
34
			new PropertyNoValueSnak( new PropertyId( 'P9001' ) ),
35
		];
36
37
		$hash = $hasher->hash( $map0 );
0 ignored issues
show
Documentation introduced by
$map0 is of type array<string|integer,obj...PropertyNoValueSnak>"}>, but the function expects a object<Traversable>.

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...
38
39
		$map1 = $map0;
40
		unset( $map1['foo'] );
41
		$map1[] = $map0['foo'];
42
43
		$this->assertSame( $hash, $hasher->hash( $map1 ) );
0 ignored issues
show
Documentation introduced by
$map1 is of type array<string|integer,obj...k\PropertyNoValueSnak>>, but the function expects a object<Traversable>.

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...
44
45
		$map4 = new ArrayObject( $map0 );
46
		$this->assertSame( $hash, $hasher->hash( $map4 ) );
47
48
		$map2 = $map0;
49
		unset( $map2['foo'] );
50
51
		$this->assertNotEquals( $hash, $hasher->hash( $map2 ) );
0 ignored issues
show
Documentation introduced by
$map2 is of type array<string|integer,obj...PropertyNoValueSnak>"}>, but the function expects a object<Traversable>.

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...
52
53
		$map3 = $map0;
54
		$map3['foo'] = new PropertyNoValueSnak( new PropertyId( 'P5' ) );
55
56
		$this->assertNotEquals( $hash, $hasher->hash( $map3 ) );
0 ignored issues
show
Documentation introduced by
$map3 is of type array<string|integer,obj...PropertyNoValueSnak>"}>, but the function expects a object<Traversable>.

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...
57
	}
58
59
	public function testHashThrowsExceptionOnInvalidArgument() {
60
		$hasher = new MapValueHasher();
61
62
		$this->expectException( InvalidArgumentException::class );
63
		$hasher->hash( null );
0 ignored issues
show
Documentation introduced by
null is of type null, but the function expects a object<Traversable>.

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...
64
	}
65
66
}
67