Skip to content

Commit cc1c2de

Browse files
committed
Merge pull request #466 from wmde/revert-459-toarray
Revert "Alter guarantees provided by StatementList::toArray"
2 parents e646410 + 287e36a commit cc1c2de

2 files changed

Lines changed: 7 additions & 21 deletions

File tree

src/Statement/StatementList.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ public function removeStatementsWithGuid( $guid ) {
117117
unset( $this->statements[$index] );
118118
}
119119
}
120+
121+
$this->statements = array_values( $this->statements );
120122
}
121123

122124
/**
@@ -241,10 +243,7 @@ public function getIterator() {
241243
}
242244

243245
/**
244-
* Returns the wrapped array of statements. This retrieval operation is cheap.
245-
* No guarantees are given about the keys of the returned array.
246-
*
247-
* @return Statement[]
246+
* @return Statement[] Numerically indexed (non-sparse) array.
248247
*/
249248
public function toArray() {
250249
return $this->statements;

tests/unit/Statement/StatementListTest.php

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,7 @@ public function testGivenGuidOfPresentStatement_statementIsRemoved() {
268268
$list = new StatementList( array( $statement1, $statement2, $statement3 ) );
269269
$list->removeStatementsWithGuid( 'foo' );
270270

271-
$statements = array();
272-
$statements[1] = $statement2;
273-
$statements[2] = $statement3;
274-
275-
$this->assertEquals( $statements, $list->toArray() );
271+
$this->assertEquals( new StatementList( $statement2, $statement3 ), $list );
276272
}
277273

278274
public function testGivenGuidOfMultipleStatements_multipleStatementsAreRemoved() {
@@ -283,10 +279,7 @@ public function testGivenGuidOfMultipleStatements_multipleStatementsAreRemoved()
283279
$list = new StatementList( array( $statement1, $statement2, $statement3 ) );
284280
$list->removeStatementsWithGuid( 'bar' );
285281

286-
$this->assertEquals(
287-
new StatementList( array( $statement1 ) ),
288-
$list
289-
);
282+
$this->assertEquals( new StatementList( $statement1 ), $list );
290283
}
291284

292285
public function testGivenNotPresentGuid_listIsNotModified() {
@@ -297,10 +290,7 @@ public function testGivenNotPresentGuid_listIsNotModified() {
297290
$list = new StatementList( array( $statement1, $statement2, $statement3 ) );
298291
$list->removeStatementsWithGuid( 'baz' );
299292

300-
$this->assertEquals(
301-
new StatementList( array( $statement1, $statement2, $statement3 ) ),
302-
$list
303-
);
293+
$this->assertEquals( new StatementList( $statement1, $statement2, $statement3 ), $list );
304294
}
305295

306296
public function testGivenNullGuid_allStatementsWithNoGuidAreRemoved() {
@@ -311,10 +301,7 @@ public function testGivenNullGuid_allStatementsWithNoGuidAreRemoved() {
311301
$list = new StatementList( array( $statement1, $statement2, $statement3 ) );
312302
$list->removeStatementsWithGuid( null );
313303

314-
$this->assertEquals(
315-
new StatementList( array( $statement1 ) ),
316-
$list
317-
);
304+
$this->assertEquals( new StatementList( $statement1 ), $list );
318305
}
319306

320307
public function testCanConstructWithClaimsObjectContainingOnlyStatements() {

0 commit comments

Comments
 (0)