diff options
author | Jordi Boggiano <j.boggiano@seld.be> | 2012-04-22 12:36:48 +0200 |
---|---|---|
committer | Jordi Boggiano <j.boggiano@seld.be> | 2012-04-22 12:38:37 +0200 |
commit | 1359f72b08f197b2f80f3d38ebe63aa5770f53a0 (patch) | |
tree | e8cfb60cb6edb6dad2dc25fa09839ec138d2d8bf /tests/Monolog/Handler/MongoDBHandlerTest.php | |
parent | 0bd4d930065107ba22ba9fa24b6607e45c9ef903 (diff) | |
download | monolog-1359f72b08f197b2f80f3d38ebe63aa5770f53a0.zip monolog-1359f72b08f197b2f80f3d38ebe63aa5770f53a0.tar.gz monolog-1359f72b08f197b2f80f3d38ebe63aa5770f53a0.tar.bz2 |
Fix up mongo db handler and add tests
Diffstat (limited to 'tests/Monolog/Handler/MongoDBHandlerTest.php')
-rw-r--r-- | tests/Monolog/Handler/MongoDBHandlerTest.php | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tests/Monolog/Handler/MongoDBHandlerTest.php b/tests/Monolog/Handler/MongoDBHandlerTest.php new file mode 100644 index 0000000..2326c98 --- /dev/null +++ b/tests/Monolog/Handler/MongoDBHandlerTest.php @@ -0,0 +1,54 @@ +<?php + +/* + * This file is part of the Monolog package. + * + * (c) Jordi Boggiano <j.boggiano@seld.be> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Monolog\Handler; + +use Monolog\TestCase; +use Monolog\Logger; + +class MongoDBHandlerTest extends TestCase +{ + public function testHandle() + { + $mongo = $this->getMock('Mongo', array('selectCollection')); + $collection = $this->getMock('stdClass', array('save')); + + $mongo->expects($this->once()) + ->method('selectCollection') + ->with('DB', 'Collection') + ->will($this->returnValue($collection)); + + $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(), + ); + + $collection->expects($this->once()) + ->method('save') + ->with($expected); + + $handler = new MongoDBHandler($mongo, 'DB', 'Collection'); + $handler->handle($record); + } +} + +if (!class_exists('Mongo')) { + class Mongo { + public function selectCollection() {} + } +} |