These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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
|
|||
| 62 | $hasher->hash( null ); |
||
| 63 | } |
||
| 64 | |||
| 65 | } |
||
| 66 |
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.