diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Monolog/Handler/MongoDBHandlerTest.php | 54 | ||||
-rw-r--r-- | tests/Monolog/TestCase.php | 4 |
2 files changed, 56 insertions, 2 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() {} + } +} diff --git a/tests/Monolog/TestCase.php b/tests/Monolog/TestCase.php index ecf655c..8624d07 100644 --- a/tests/Monolog/TestCase.php +++ b/tests/Monolog/TestCase.php @@ -16,11 +16,11 @@ class TestCase extends \PHPUnit_Framework_TestCase /** * @return array Record */ - protected function getRecord($level = Logger::WARNING, $message = 'test') + protected function getRecord($level = Logger::WARNING, $message = 'test', $context = array()) { return array( 'message' => $message, - 'context' => array(), + 'context' => $context, 'level' => $level, 'level_name' => Logger::getLevelName($level), 'channel' => 'test', |