1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-12 16:14:08 +02:00

Support MongoClient in MongoDBHandler

This commit is contained in:
Jeremy Mikola
2012-12-13 14:59:04 -05:00
parent 546225bed2
commit 6d3bca8543
2 changed files with 13 additions and 1 deletions

View File

@@ -29,8 +29,12 @@ class MongoDBHandler extends AbstractProcessingHandler
{ {
private $mongoCollection; private $mongoCollection;
public function __construct(\Mongo $mongo, $database, $collection, $level = Logger::DEBUG, $bubble = true) public function __construct($mongo, $database, $collection, $level = Logger::DEBUG, $bubble = true)
{ {
if (!($mongo instanceof \MongoClient || $mongo instanceof \Mongo)) {
throw new \InvalidArgumentException('MongoClient or Mongo instance required');
}
$this->mongoCollection = $mongo->selectCollection($database, $collection); $this->mongoCollection = $mongo->selectCollection($database, $collection);
parent::__construct($level, $bubble); parent::__construct($level, $bubble);

View File

@@ -16,6 +16,14 @@ use Monolog\Logger;
class MongoDBHandlerTest extends TestCase class MongoDBHandlerTest extends TestCase
{ {
/**
* @expectedException InvalidArgumentException
*/
public function testConstructorShouldThrowExceptionForInvalidMongo()
{
new MongoDBHandler(new \stdClass(), 'DB', 'Collection');
}
public function testHandle() public function testHandle()
{ {
$mongo = $this->getMock('Mongo', array('selectCollection')); $mongo = $this->getMock('Mongo', array('selectCollection'));