|
2 | 2 |
|
3 | 3 | namespace Wikibase\DataModel\Tests\HashArray; |
4 | 4 |
|
| 5 | +use Hashable; |
5 | 6 | use Wikibase\DataModel\Fixtures\HashArrayElement; |
6 | 7 | use Wikibase\DataModel\HashArray; |
| 8 | +use Wikibase\DataModel\Snak\PropertyNoValueSnak; |
7 | 9 |
|
8 | 10 | /** |
9 | 11 | * @covers Wikibase\DataModel\HashArray |
@@ -80,15 +82,51 @@ public function testAddElement( HashArray $array ) { |
80 | 82 | * @dataProvider instanceProvider |
81 | 83 | * @param HashArray $array |
82 | 84 | */ |
83 | | - public function testRemoveDuplicates( HashArray $array ) { |
84 | | - $count = count( $array ); |
85 | | - $array->removeDuplicates(); |
86 | | - |
87 | | - $this->assertCount( |
88 | | - $count, |
89 | | - $array, |
90 | | - 'Count should be the same after removeDuplicates since there can be none' |
91 | | - ); |
| 85 | + public function testHasElement( HashArray $array ) { |
| 86 | + /** |
| 87 | + * @var Hashable $hashable |
| 88 | + */ |
| 89 | + foreach ( iterator_to_array( $array ) as $hashable ) { |
| 90 | + $this->assertTrue( $array->hasElement( $hashable ) ); |
| 91 | + $this->assertTrue( $array->hasElementHash( $hashable->getHash() ) ); |
| 92 | + $array->removeElement( $hashable ); |
| 93 | + $this->assertFalse( $array->hasElement( $hashable ) ); |
| 94 | + $this->assertFalse( $array->hasElementHash( $hashable->getHash() ) ); |
| 95 | + } |
| 96 | + |
| 97 | + $this->assertTrue( true ); |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * @dataProvider instanceProvider |
| 102 | + * @param HashArray $array |
| 103 | + */ |
| 104 | + public function testRemoveElement( HashArray $array ) { |
| 105 | + $elementCount = $array->count(); |
| 106 | + |
| 107 | + /** |
| 108 | + * @var Hashable $element |
| 109 | + */ |
| 110 | + foreach ( iterator_to_array( $array ) as $element ) { |
| 111 | + $this->assertTrue( $array->hasElement( $element ) ); |
| 112 | + |
| 113 | + if ( $elementCount % 2 === 0 ) { |
| 114 | + $array->removeElement( $element ); |
| 115 | + } |
| 116 | + else { |
| 117 | + $array->removeByElementHash( $element->getHash() ); |
| 118 | + } |
| 119 | + |
| 120 | + $this->assertFalse( $array->hasElement( $element ) ); |
| 121 | + $this->assertEquals( --$elementCount, $array->count() ); |
| 122 | + } |
| 123 | + |
| 124 | + $element = new PropertyNoValueSnak( 42 ); |
| 125 | + |
| 126 | + $array->removeElement( $element ); |
| 127 | + $array->removeByElementHash( $element->getHash() ); |
| 128 | + |
| 129 | + $this->assertTrue( true ); |
92 | 130 | } |
93 | 131 |
|
94 | 132 | /** |
|
0 commit comments