@@ -109,6 +109,36 @@ public function it_updates_a_subset_of_a_doc()
109109 $ this ->assertArrayNotHasKey ('other ' , $ filteredDocs [0 ]['some ' ]);
110110 }
111111
112+ /**
113+ * @test
114+ */
115+ public function it_replaces_a_doc ()
116+ {
117+ $ this ->store ->addCollection ('test ' );
118+
119+ $ doc = [
120+ 'some ' => [
121+ 'prop ' => 'foo ' ,
122+ 'other ' => [
123+ 'nested ' => 42
124+ ]
125+ ],
126+ 'baz ' => 'bat ' ,
127+ ];
128+
129+ $ this ->store ->addDoc ('test ' , '1 ' , $ doc );
130+
131+ $ doc = ['baz ' => 'changed val ' ];
132+
133+ $ this ->store ->replaceDoc ('test ' , '1 ' , $ doc );
134+
135+ $ filter = new EqFilter ('baz ' , 'changed val ' );
136+
137+ $ filteredDocs = $ this ->store ->findDocs ('test ' , $ filter );
138+
139+ $ this ->assertCount (1 , $ filteredDocs );
140+ }
141+
112142 /**
113143 * @test
114144 */
@@ -548,6 +578,30 @@ public function it_updates_many()
548578 $ this ->assertEquals ('fuzz ' , $ filteredDocs [1 ]['some ' ]['prop ' ]);
549579 }
550580
581+ /**
582+ * @test
583+ */
584+ public function it_replaces_many ()
585+ {
586+ $ this ->store ->addCollection ('test ' );
587+
588+ $ this ->store ->addDoc ('test ' , '1 ' , ['some ' => ['prop ' => 'foo ' , 'other ' => ['prop ' => 'bat ' ]]]);
589+ $ this ->store ->addDoc ('test ' , '2 ' , ['some ' => ['prop ' => 'bar ' , 'other ' => ['prop ' => 'bat ' ]]]);
590+ $ this ->store ->addDoc ('test ' , '3 ' , ['some ' => ['prop ' => 'bar ' ]]);
591+
592+ $ this ->store ->replaceMany (
593+ 'test ' ,
594+ new EqFilter ('some.other.prop ' , 'bat ' ),
595+ ['some ' => ['prop ' => 'fuzz ' ]]
596+ );
597+
598+ $ filteredDocs = array_values (iterator_to_array ($ this ->store ->findDocs ('test ' , new EqFilter ('some.prop ' , 'fuzz ' ))));
599+
600+ $ this ->assertCount (2 , $ filteredDocs );
601+ $ this ->assertEquals (['some ' => ['prop ' => 'fuzz ' ]], $ filteredDocs [0 ]);
602+ $ this ->assertEquals (['some ' => ['prop ' => 'fuzz ' ]], $ filteredDocs [1 ]);
603+ }
604+
551605 /**
552606 * @test
553607 */
0 commit comments