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 ); |
|
|
|
|
38
|
|
|
|
39
|
|
|
$map1 = $map0; |
40
|
|
|
unset( $map1['foo'] ); |
41
|
|
|
$map1[] = $map0['foo']; |
42
|
|
|
|
43
|
|
|
$this->assertSame( $hash, $hasher->hash( $map1 ) ); |
|
|
|
|
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 ) ); |
|
|
|
|
52
|
|
|
|
53
|
|
|
$map3 = $map0; |
54
|
|
|
$map3['foo'] = new PropertyNoValueSnak( new PropertyId( 'P5' ) ); |
55
|
|
|
|
56
|
|
|
$this->assertNotEquals( $hash, $hasher->hash( $map3 ) ); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testHashThrowsExceptionOnInvalidArgument() { |
60
|
|
|
$hasher = new MapValueHasher(); |
61
|
|
|
|
62
|
|
|
$this->expectException( InvalidArgumentException::class ); |
63
|
|
|
$hasher->hash( null ); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
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: