Skip to content

Commit bb3200d

Browse files
committed
Have StatementByGuidMap implement Countable
1 parent 994e018 commit bb3200d

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

src/Statement/StatementByGuidMap.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
1515
* @author Kai Nissen < kai.nissen@wikimedia.de >
1616
*/
17-
class StatementByGuidMap {
17+
class StatementByGuidMap implements \Countable {
1818

1919
private $statements = array();
2020

@@ -78,4 +78,12 @@ public function removeStatementWithGuid( $statementGuid ) {
7878
unset( $this->statements[$statementGuid] );
7979
}
8080

81+
/**
82+
* @see Countable::count
83+
* @return int
84+
*/
85+
public function count() {
86+
return count( $this->statements );
87+
}
88+
8189
}

tests/unit/Statement/StatementByGuidMapTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,19 @@ public function testCanConstructWithStatementIterable() {
126126
$this->assertTrue( $statementMap->hasStatementWithGuid( 'some guid' ) );
127127
}
128128

129+
public function testWhenMapIsEmpty_countReturnsZero() {
130+
$statements = new StatementByGuidMap();
131+
132+
$this->assertSame( 0, $statements->count() );
133+
}
134+
135+
public function testMapCanBePassedToCount() {
136+
$statements = new StatementByGuidMap( array(
137+
$this->newStatement( 1, 'some guid' ),
138+
$this->newStatement( 2, 'other guid' )
139+
) );
140+
141+
$this->assertSame( 2, count( $statements ) );
142+
}
143+
129144
}

0 commit comments

Comments
 (0)