File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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}
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments