File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010
1111/**
1212 * Ordered and unique collection of Statement objects.
13- * Provides indexed access by Statement GUID. Can only contain Statements that have a non-null GUID.
13+ * Can only contain Statements that have a non-null GUID.
14+ *
15+ * Provides indexed access by Statement GUID.
16+ * Does not provide complex modification functionality.
1417 *
1518 * @since 3.0
1619 *
@@ -31,7 +34,13 @@ public function __construct( $statements = array() ) {
3134 }
3235 }
3336
34- private function addStatement ( Statement $ statement ) {
37+ /**
38+ * If the provided statement has a GUID not yet in the map, it will be appended to the map.
39+ * If the GUID is already in the map, the statement with this guid will be replaced.
40+ *
41+ * @param Statement $statement
42+ */
43+ public function addStatement ( Statement $ statement ) {
3544 if ( $ statement ->getGuid () === null ) {
3645 throw new InvalidArgumentException ( 'Can only add statements that have a non-null GUID ' );
3746 }
@@ -91,6 +100,8 @@ public function count() {
91100 }
92101
93102 /**
103+ * The iterator has the GUIDs of the statements as keys.
104+ *
94105 * @see IteratorAggregate::getIterator
95106 * @return Traversable
96107 */
Original file line number Diff line number Diff line change @@ -161,4 +161,23 @@ public function testMapCanBeIteratedOver() {
161161 $ this ->assertEquals ( $ expectedStatements , $ iteratedStatements );
162162 }
163163
164+ public function testGivenNotPresentStatement_addStatementAddsIt () {
165+ $ statements = new StatementByGuidMap ();
166+
167+ $ statements ->addStatement ( $ this ->newStatement ( 1 , 'some guid ' ) );
168+
169+ $ this ->assertTrue ( $ statements ->hasStatementWithGuid ( 'some guid ' ) );
170+ }
171+
172+ public function testGivenStatementWithPresentGuid_addStatementReplacesThePresentStatement () {
173+ $ statement1 = $ this ->newStatement ( 1 , 'some guid ' );
174+ $ statement2 = $ this ->newStatement ( 2 , 'some guid ' );
175+
176+ $ statements = new StatementByGuidMap ( array ( $ statement1 ) );
177+
178+ $ statements ->addStatement ( $ statement2 );
179+
180+ $ this ->assertEquals ( $ statement2 , $ statements ->getStatementByGuid ( 'some guid ' ) );
181+ }
182+
164183}
You can’t perform that action at this time.
0 commit comments