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

Add case for if manager is passed in

This commit is contained in:
Will Banfield
2016-01-20 14:54:29 -05:00
parent ad37c8e663
commit f6a9fdbb2c
2 changed files with 49 additions and 6 deletions

View File

@@ -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')) {