ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
MongoDBHandlerTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Monolog package.
5  *
6  * (c) Jordi Boggiano <j.boggiano@seld.be>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace Monolog\Handler;
13 
15 use Monolog\Logger;
16 
18 {
23  {
24  new MongoDBHandler(new \stdClass(), 'DB', 'Collection');
25  }
26 
27  public function testHandle()
28  {
29  $mongo = $this->getMock('Mongo', array('selectCollection'), array(), '', false);
30  $collection = $this->getMock('stdClass', array('save'));
31 
32  $mongo->expects($this->once())
33  ->method('selectCollection')
34  ->with('DB', 'Collection')
35  ->will($this->returnValue($collection));
36 
37  $record = $this->getRecord(Logger::WARNING, 'test', array('data' => new \stdClass, 'foo' => 34));
38 
39  $expected = array(
40  'message' => 'test',
41  'context' => array('data' => '[object] (stdClass: {})', 'foo' => 34),
42  'level' => Logger::WARNING,
43  'level_name' => 'WARNING',
44  'channel' => 'test',
45  'datetime' => $record['datetime']->format('Y-m-d H:i:s'),
46  'extra' => array(),
47  );
48 
49  $collection->expects($this->once())
50  ->method('save')
51  ->with($expected);
52 
53  $handler = new MongoDBHandler($mongo, 'DB', 'Collection');
54  $handler->handle($record);
55  }
56 }
57 
58 if (!class_exists('Mongo')) {
59  class Mongo
60  {
61  public function selectCollection()
62  {
63  }
64  }
65 }
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
Logs to a MongoDB database.
once($eventName, callable $callBack, $priority=100)
Subscribe to an event exactly once.
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:53
$handler
testConstructorShouldThrowExceptionForInvalidMongo()
InvalidArgumentException