Skip to content

Commit 3441060

Browse files
authored
Merge pull request #709 from wmde/refListTestMutations
Add missing ReferenceList::addReference test case
2 parents 38b0008 + 38b2f82 commit 3441060

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

src/ReferenceList.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ public function addNewReference( $snaks = [] /*...*/ ) {
100100
* @param int $index
101101
*/
102102
private function insertReferenceAtIndex( Reference $reference, $index ) {
103+
if ( !is_int( $index ) ) {
104+
throw new InvalidArgumentException( '$index must be an integer' );
105+
}
106+
103107
$this->references = array_merge(
104108
array_slice( $this->references, 0, $index ),
105109
[ spl_object_hash( $reference ) => $reference ],

tests/unit/ReferenceListTest.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public function testRemoveReference( ReferenceList $array ) {
143143
$array->removeReference( $element );
144144

145145
$this->assertFalse( $array->hasReference( $element ) );
146-
$this->assertEquals( --$elementCount, count( $array ) );
146+
$this->assertSame( --$elementCount, count( $array ) );
147147
}
148148
}
149149

@@ -180,13 +180,13 @@ public function testAddReferenceOnEmptyList() {
180180
}
181181

182182
private function assertSameReferenceOrder( ReferenceList $expectedList, ReferenceList $references ) {
183-
$this->assertEquals(
183+
$this->assertSame(
184184
iterator_to_array( $expectedList ),
185185
iterator_to_array( $references )
186186
);
187187
}
188188

189-
public function testAddReferenceOnNonEmptyList() {
189+
public function testAddReferenceAtTheEnd() {
190190
$reference1 = new Reference( [ new PropertyNoValueSnak( 1 ) ] );
191191
$reference2 = new Reference( [ new PropertyNoValueSnak( 2 ) ] );
192192
$reference3 = new Reference( [ new PropertyNoValueSnak( 3 ) ] );
@@ -200,6 +200,18 @@ public function testAddReferenceOnNonEmptyList() {
200200
$this->assertSameReferenceOrder( $expectedList, $references );
201201
}
202202

203+
public function testAddReferenceBetweenExistingReferences() {
204+
$reference1 = new Reference( [ new PropertyNoValueSnak( 1 ) ] );
205+
$reference2 = new Reference( [ new PropertyNoValueSnak( 2 ) ] );
206+
$list = new ReferenceList( [ $reference1, $reference2 ] );
207+
208+
$reference3 = new Reference( [ new PropertyNoValueSnak( 3 ) ] );
209+
$list->addReference( $reference3, 1 );
210+
211+
$this->assertCount( 3, $list );
212+
$this->assertSame( 1, $list->indexOf( $reference3 ) );
213+
}
214+
203215
public function testAddReferenceIgnoresIdenticalObjects() {
204216
$list = new ReferenceList();
205217
$reference = new Reference( [ new PropertyNoValueSnak( 1 ) ] );
@@ -294,7 +306,7 @@ public function testIndexOf( ReferenceList $array ) {
294306

295307
$i = 0;
296308
foreach ( $array as $reference ) {
297-
$this->assertEquals( $i++, $array->indexOf( $reference ) );
309+
$this->assertSame( $i++, $array->indexOf( $reference ) );
298310
}
299311
}
300312

@@ -329,7 +341,7 @@ public function testGetValueHashReturnsString( ReferenceList $array ) {
329341
*/
330342
public function testGetValueHashIsTheSameForClone( ReferenceList $array ) {
331343
$copy = unserialize( serialize( $array ) );
332-
$this->assertEquals( $array->getValueHash(), $copy->getValueHash() );
344+
$this->assertSame( $array->getValueHash(), $copy->getValueHash() );
333345
}
334346

335347
/**

0 commit comments

Comments
 (0)