ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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
12namespace Monolog\Handler;
13
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
58if (!class_exists('Mongo')) {
59 class Mongo
60 {
61 public function selectCollection()
62 {
63 }
64 }
65}
testConstructorShouldThrowExceptionForInvalidMongo()
@expectedException InvalidArgumentException
Logs to a MongoDB database.
Monolog log channel.
Definition: Logger.php:28
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:52
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19