diff --git a/src/Adapter.php b/src/Adapter.php deleted file mode 100644 index 521b01ca51..0000000000 --- a/src/Adapter.php +++ /dev/null @@ -1,15 +0,0 @@ - $this->toObject($where), 'u' => $this->toObject($cleanUpdates), - 'multi' => false, + 'multi' => $multi, 'upsert' => false ] ] diff --git a/tests/MongoTest.php b/tests/MongoTest.php index ab67e41a9b..e2760a5647 100644 --- a/tests/MongoTest.php +++ b/tests/MongoTest.php @@ -108,6 +108,53 @@ class MongoTest extends TestCase self::assertIsObject($doc->date_object); // Todo: This is not working can't retrieve the object back } + public function testUpdateDocument(): void + { + $this->getDatabase()->insert( + 'movies', + [ + 'name' => 'Armageddon', + 'country' => 'AUS', + 'language' => 'English' + ] + ); + + $this->getDatabase()->update( + 'movies', + ['name' => 'Armageddon'], + ['$set' => ['name' => 'Armageddon 2']] + ); + + $doc = $this->getDatabase()->find( + 'movies', + ['name' => 'Armageddon 2'] + )->cursor->firstBatch ?? []; + + self::assertCount(1, $doc); + } + + public function testUpdateMultipleDocuments(): void + { + $this->getDatabase()->update( + 'movies', + ['name' => 'Armageddon 2'], + ['$set' => ['name' => 'Armageddon']] + ); + + $this->getDatabase()->update( + 'movies', + ['name' => 'Armageddon'], + ['$rename' => ['name' => 'title']], + multi: true + ); + + $docs = $this->getDatabase()->find( + 'movies', + ['title' => 'Armageddon'] + )->cursor->firstBatch ?? []; + self::assertCount(2, $docs); + } + public function testDriverException() { self::expectException('MongoDB\Driver\Exception\InvalidArgumentException');