From 5c0846a3591f12225615ed2f57d8b526e1701bca Mon Sep 17 00:00:00 2001 From: Alessandro Galli Date: Fri, 2 Sep 2016 12:13:24 +0200 Subject: [PATCH] [Profiling][Collection] - #10 collection updateOne method is now profiled --- src/Capsule/Collection.php | 12 ++++++++++++ tests/Functional/Capsule/CollectionTest.php | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Capsule/Collection.php b/src/Capsule/Collection.php index 42fbe58..5a30a15 100644 --- a/src/Capsule/Collection.php +++ b/src/Capsule/Collection.php @@ -142,6 +142,18 @@ public function insertOne($document, array $options = []) return $result; } + /** + * {@inheritdoc} + */ + public function updateOne($filter, $update, array $options = []) + { + $event = $this->startQueryLogging(__FUNCTION__, $filter, $update, $options); + $result = parent::updateOne($filter, $update, $options); + $this->logger->logQuery($event); + + return $result; + } + /** * @param string $method * @param array $filters diff --git a/tests/Functional/Capsule/CollectionTest.php b/tests/Functional/Capsule/CollectionTest.php index 10b88d2..8554eb9 100644 --- a/tests/Functional/Capsule/CollectionTest.php +++ b/tests/Functional/Capsule/CollectionTest.php @@ -32,6 +32,18 @@ public function test_insertOne() $coll->insertOne(['test' => 1]); } + public function test_updateOne() + { + $manager = new Manager('mongodb://localhost'); + $logger = self::prophesize(DataCollectorLoggerInterface::class); + $logger->startLogging(Argument::type(LogEvent::class))->shouldBeCalled(); + $logger->logQuery(Argument::type(LogEvent::class))->shouldBeCalled(); + + $coll = new Collection($manager, 'testdb', 'test_collection', [], $logger->reveal()); + + $coll->updateOne(['filter' => 1],['$set' => ['testField' => 1]]); + } + public function test_count() { $manager = new Manager('mongodb://localhost');