diff options
author | Will Banfield <william.banfield@mongodb.com> | 2016-01-20 14:54:29 -0500 |
---|---|---|
committer | Will Banfield <william.banfield@mongodb.com> | 2016-01-21 14:19:35 -0500 |
commit | f6a9fdbb2c9ad9ef7f26269a1edb1de1c3b6d3cc (patch) | |
tree | 5cefc3f32858f4933dae99bee132615bff186a99 /tests/Monolog/Handler/MongoDBHandlerTest.php | |
parent | ad37c8e6638d6d21cf4deaca1aafb8c4a29a6d1b (diff) | |
download | monolog-f6a9fdbb2c9ad9ef7f26269a1edb1de1c3b6d3cc.zip monolog-f6a9fdbb2c9ad9ef7f26269a1edb1de1c3b6d3cc.tar.gz monolog-f6a9fdbb2c9ad9ef7f26269a1edb1de1c3b6d3cc.tar.bz2 |
Add case for if manager is passed in
Diffstat (limited to 'tests/Monolog/Handler/MongoDBHandlerTest.php')
-rw-r--r-- | tests/Monolog/Handler/MongoDBHandlerTest.php | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/tests/Monolog/Handler/MongoDBHandlerTest.php b/tests/Monolog/Handler/MongoDBHandlerTest.php index 0fdef63..5c05e90 100644 --- a/tests/Monolog/Handler/MongoDBHandlerTest.php +++ b/tests/Monolog/Handler/MongoDBHandlerTest.php @@ -27,7 +27,7 @@ class MongoDBHandlerTest extends TestCase public function testHandle() { $mongo = $this->getMock('Mongo', array('selectCollection'), array(), '', false); - $collection = $this->getMock('stdClass', array('save')); + $collection = $this->getMock('stdClass', array('insert')); $mongo->expects($this->once()) ->method('selectCollection') @@ -47,12 +47,45 @@ class MongoDBHandlerTest extends TestCase ); $collection->expects($this->once()) - ->method('save') + ->method('insert') ->with($expected); $handler = new MongoDBHandler($mongo, 'DB', 'Collection'); $handler->handle($record); } + + public function testHandleWithManager() { + if (!(class_exists('MongoDB\Driver\Manager'))) { + $this->markTestSkipped('mongo extension not installed'); + } + + $manager = $this->getMock('MongoDB\Driver\Manager', array('executeBulkWrite'), array(), '', false); + + + $record = $this->getRecord(Logger::WARNING, 'test', array('data' => new \stdClass, 'foo' => 34)); + $expected = array( + 'message' => 'test', + 'context' => array('data' => '[object] (stdClass: {})', 'foo' => 34), + 'level' => Logger::WARNING, + 'level_name' => 'WARNING', + 'channel' => 'test', + 'datetime' => $record['datetime']->format('Y-m-d H:i:s'), + 'extra' => array(), + ); + + $bulk = new \MongoDB\Driver\BulkWrite(); + $bulk->insert($expected); + + $manager->expects($this->once()) + ->method('executeBulkWrite') + ->with('DB.Collection', $bulk); + + + $handler = new MongoDBHandler($manager, 'DB', 'Collection'); + $handler->handle($record); + + } + } if (!class_exists('Mongo')) { |