Skip to content

Commit 74ffe31

Browse files
committed
Cleanup ReferenceList changes
1 parent 0f3a39f commit 74ffe31

3 files changed

Lines changed: 15 additions & 12 deletions

File tree

RELEASE-NOTES.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
* Removed `Claims` class (deprecated since 1.0)
66
* Removed `getClaims` and `setClaims` from `Entity`, `Item` and `Property` (deprecated since 1.0)
77
* Removed `ReferenceList::removeDuplicates`
8-
* `ReferenceList` no longer derives from `SplObjectStorage`, though still implements `Countable`
9-
* `ReferenceList` now implements `IteratorAggregate` and has a `toArray` method
8+
* `ReferenceList` no longer derives from `SplObjectStorage`, though still implements `Countable` and `Traversable`
9+
* `ReferenceList` now implements `IteratorAggregate`
10+
* `ReferenceList::addReference` now throws an `InvalidArgumentException` for negative indices
1011
* Removed `HashableObjectStorage`
1112
* `Entity` no longer implements `Comparable`
1213
* Added `EntityDocument::equals`

src/ReferenceList.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function hasReference( Reference $reference ) {
126126
*/
127127
public function indexOf( Reference $reference ) {
128128
foreach ( $this->references as $index => $ref ) {
129-
if ( $ref->equals( $reference ) ) {
129+
if ( $ref === $reference ) {
130130
return $index;
131131
}
132132
}
@@ -283,13 +283,4 @@ public function getIterator() {
283283
return new ArrayIterator( $this->references );
284284
}
285285

286-
/**
287-
* @since 5.0
288-
*
289-
* @return Reference[]
290-
*/
291-
public function toArray() {
292-
return $this->references;
293-
}
294-
295286
}

tests/unit/ReferenceListTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,17 @@ public function testAddReferenceAtIndexZero() {
191191
$this->assertSameReferenceOrder( $expectedList, $references );
192192
}
193193

194+
public function testAddReferenceAtNegativeIndex() {
195+
$reference1 = new Reference( array( new PropertyNoValueSnak( 1 ) ) );
196+
$reference2 = new Reference( array( new PropertyNoValueSnak( 2 ) ) );
197+
$reference3 = new Reference( array( new PropertyNoValueSnak( 3 ) ) );
198+
199+
$references = new ReferenceList( array( $reference1, $reference2 ) );
200+
201+
$this->setExpectedException( 'InvalidArgumentException' );
202+
$references->addReference( $reference3, -1 );
203+
}
204+
194205
public function testGivenEmptyReference_addReferenceDoesNotAdd() {
195206
$reference1 = new Reference( array( new PropertyNoValueSnak( 1 ) ) );
196207
$reference2 = new Reference( array( new PropertyNoValueSnak( 2 ) ) );

0 commit comments

Comments
 (0)