@@ -296,6 +296,20 @@ public function testFindOneAndDeleteWithCodec(): void
296
296
self ::assertEquals (TestObject::createDecodedForFixture (1 ), $ result );
297
297
}
298
298
299
+ public function testFindOneAndDeleteNothingWithCodec (): void
300
+ {
301
+ // When the query does not match any documents, the operation returns null
302
+ $ operation = new FindAndModify (
303
+ $ this ->getDatabaseName (),
304
+ $ this ->getCollectionName (),
305
+ ['remove ' => true , 'codec ' => new TestDocumentCodec ()],
306
+ );
307
+
308
+ $ result = $ operation ->execute ($ this ->getPrimaryServer ());
309
+
310
+ self ::assertNull ($ result );
311
+ }
312
+
299
313
public function testFindOneAndUpdateWithCodec (): void
300
314
{
301
315
$ this ->createFixtures (1 );
@@ -311,6 +325,20 @@ public function testFindOneAndUpdateWithCodec(): void
311
325
self ::assertEquals (TestObject::createDecodedForFixture (1 ), $ result );
312
326
}
313
327
328
+ public function testFindOneAndUpdateNothingWithCodec (): void
329
+ {
330
+ // When the query does not match any documents, the operation returns null
331
+ $ operation = new FindAndModify (
332
+ $ this ->getDatabaseName (),
333
+ $ this ->getCollectionName (),
334
+ ['update ' => ['$set ' => ['x.foo ' => 'baz ' ]], 'codec ' => new TestDocumentCodec ()],
335
+ );
336
+
337
+ $ result = $ operation ->execute ($ this ->getPrimaryServer ());
338
+
339
+ self ::assertNull ($ result );
340
+ }
341
+
314
342
public function testFindOneAndReplaceWithCodec (): void
315
343
{
316
344
$ this ->createFixtures (1 );
@@ -326,6 +354,20 @@ public function testFindOneAndReplaceWithCodec(): void
326
354
self ::assertEquals (TestObject::createDecodedForFixture (1 ), $ result );
327
355
}
328
356
357
+ public function testFindOneAndReplaceNothingWithCodec (): void
358
+ {
359
+ // When the query does not match any documents, the operation returns null
360
+ $ operation = new FindAndModify (
361
+ $ this ->getDatabaseName (),
362
+ $ this ->getCollectionName (),
363
+ ['update ' => ['_id ' => 1 ], 'codec ' => new TestDocumentCodec ()],
364
+ );
365
+
366
+ $ result = $ operation ->execute ($ this ->getPrimaryServer ());
367
+
368
+ self ::assertNull ($ result );
369
+ }
370
+
329
371
/**
330
372
* Create data fixtures.
331
373
*/
0 commit comments