public function testHandle()
 {
     $mongo = $this->getMock('Mongo', array('selectCollection'), array(), '', false);
     $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);
 }
Beispiel #2
0
 public function testHandleWithDriverManager()
 {
     if (!class_exists('MongoDB\\Driver\\Manager')) {
         $this->markTestSkipped('ext-mongodb not installed');
     }
     /* This can become a unit test once ManagerInterface can be mocked.
      * See: https://jira.mongodb.org/browse/PHPC-378
      */
     $mongodb = new Manager('mongodb://localhost:27017');
     $handler = new MongoDBHandler($mongodb, 'test', 'monolog');
     $record = $this->getRecord();
     try {
         $handler->handle($record);
     } catch (\RuntimeException $e) {
         $this->markTestSkipped('Could not connect to MongoDB server on mongodb://localhost:27017');
     }
 }