@@ -150,6 +150,71 @@ public function it_adds_collection_with_multi_field_index_unique(): void
150150 );
151151 $ this ->assertStringStartsWith ('CREATE UNIQUE INDEX ' , $ indexes [1 ]['indexdef ' ]);
152152 }
153+
154+ /**
155+ * @test
156+ */
157+ public function it_adds_and_updates_a_doc ()
158+ {
159+ $ collectionName = 'test_adds_and_updates_a_doc ' ;
160+ $ this ->documentStore ->addCollection ($ collectionName );
161+
162+ $ doc = [
163+ 'some ' => [
164+ 'prop ' => 'foo ' ,
165+ 'other ' => [
166+ 'nested ' => 42
167+ ]
168+ ],
169+ 'baz ' => 'bat ' ,
170+ ];
171+
172+ $ docId = Uuid::uuid4 ()->toString ();
173+ $ this ->documentStore ->addDoc ($ collectionName , $ docId , $ doc );
174+
175+ $ persistedDoc = $ this ->documentStore ->getDoc ($ collectionName , $ docId );
176+
177+ $ this ->assertEquals ($ doc , $ persistedDoc );
178+
179+ $ doc ['baz ' ] = 'changed val ' ;
180+
181+ $ this ->documentStore ->updateDoc ($ collectionName , $ docId , $ doc );
182+
183+ $ filter = new EqFilter ('baz ' , 'changed val ' );
184+
185+ $ filteredDocs = $ this ->documentStore ->findDocs ($ collectionName , $ filter );
186+
187+ $ this ->assertCount (1 , $ filteredDocs );
188+ }
189+
190+ /**
191+ * @test
192+ */
193+ public function it_updates_a_subset_of_a_doc ()
194+ {
195+ $ collectionName = 'test_updates_a_subset_of_a_doc ' ;
196+ $ this ->documentStore ->addCollection ($ collectionName );
197+
198+ $ doc = [
199+ 'some ' => [
200+ 'prop ' => 'foo ' ,
201+ 'other ' => 'bar '
202+ ],
203+ 'baz ' => 'bat ' ,
204+ ];
205+
206+ $ docId = Uuid::uuid4 ()->toString ();
207+ $ this ->documentStore ->addDoc ($ collectionName , $ docId , $ doc );
208+
209+ $ this ->documentStore ->updateDoc ($ collectionName , $ docId , [
210+ 'some ' => [
211+ 'prop ' => 'fuzz '
212+ ]
213+ ]);
214+
215+ $ filteredDocs = array_values (iterator_to_array ($ this ->documentStore ->findDocs ($ collectionName , new EqFilter ('some.prop ' , 'fuzz ' ))));
216+ $ this ->assertArrayNotHasKey ('other ' , $ filteredDocs [0 ]['some ' ]);
217+ }
153218
154219 /**
155220 * @test
0 commit comments