Skip to content

Commit 5b9c03a

Browse files
committed
Merge branch 'master' of github.com:wmde/WikibaseDataModel
2 parents ccb1622 + 392fe98 commit 5b9c03a

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

src/ReferenceList.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,11 @@ public function unserialize( $data ) {
242242
$this->__construct( unserialize( $data ) );
243243
}
244244

245+
/**
246+
* @return bool
247+
*/
248+
public function isEmpty() {
249+
return $this->count() === 0;
250+
}
251+
245252
}

tests/unit/ReferenceListTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,26 @@ public function testSerializeRoundtrip() {
351351
$this->assertTrue( $references->equals( unserialize( $serialized ) ) );
352352
}
353353

354+
public function testGivenEmptyList_isEmpty() {
355+
$references = new ReferenceList();
356+
$this->assertTrue( $references->isEmpty() );
357+
}
358+
359+
public function testGivenNonEmptyList_isNotEmpty() {
360+
$references = new ReferenceList();
361+
$references->addNewReference( new PropertyNoValueSnak( 1 ) );
362+
363+
$this->assertFalse( $references->isEmpty() );
364+
}
365+
366+
public function testGivenNonEmptyListWithForwardedIterator_isNotEmpty() {
367+
$references = new ReferenceList();
368+
$references->addNewReference( new PropertyNoValueSnak( 1 ) );
369+
$references->next();
370+
371+
$this->assertFalse( $references->valid(), 'post condition' );
372+
$this->assertFalse( $references->isEmpty() );
373+
$this->assertFalse( $references->valid(), 'pre condition' );
374+
}
375+
354376
}

0 commit comments

Comments
 (0)