ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
Monolog\Formatter\MongoDBFormatterTest Class Reference
+ Inheritance diagram for Monolog\Formatter\MongoDBFormatterTest:
+ Collaboration diagram for Monolog\Formatter\MongoDBFormatterTest:

Public Member Functions

 setUp ()
 
 constructArgumentProvider ()
 
 testConstruct ($traceDepth, $traceAsString, $expectedTraceDepth, $expectedTraceAsString)
 
 testSimpleFormat ()
 
 testRecursiveFormat ()
 
 testFormatDepthArray ()
 
 testFormatDepthArrayInfiniteNesting ()
 
 testFormatDepthObjects ()
 
 testFormatDepthException ()
 

Detailed Description

Author
Florian Plattner me@fl.nosp@m.oria.nosp@m.nplat.nosp@m.tner.nosp@m..de

Definition at line 10 of file MongoDBFormatterTest.php.

Member Function Documentation

◆ constructArgumentProvider()

Monolog\Formatter\MongoDBFormatterTest::constructArgumentProvider ( )

Definition at line 19 of file MongoDBFormatterTest.php.

20  {
21  return array(
22  array(1, true, 1, true),
23  array(0, false, 0, false),
24  );
25  }

◆ setUp()

Monolog\Formatter\MongoDBFormatterTest::setUp ( )

Definition at line 12 of file MongoDBFormatterTest.php.

13  {
14  if (!class_exists('MongoDate')) {
15  $this->markTestSkipped('mongo extension not installed');
16  }
17  }

◆ testConstruct()

Monolog\Formatter\MongoDBFormatterTest::testConstruct (   $traceDepth,
  $traceAsString,
  $expectedTraceDepth,
  $expectedTraceAsString 
)
Parameters
$traceDepth
$traceAsString
$expectedTraceDepth
$expectedTraceAsStringconstructArgumentProvider

Definition at line 35 of file MongoDBFormatterTest.php.

36  {
37  $formatter = new MongoDBFormatter($traceDepth, $traceAsString);
38 
39  $reflTrace = new \ReflectionProperty($formatter, 'exceptionTraceAsString');
40  $reflTrace->setAccessible(true);
41  $this->assertEquals($expectedTraceAsString, $reflTrace->getValue($formatter));
42 
43  $reflDepth = new\ReflectionProperty($formatter, 'maxNestingLevel');
44  $reflDepth->setAccessible(true);
45  $this->assertEquals($expectedTraceDepth, $reflDepth->getValue($formatter));
46  }

◆ testFormatDepthArray()

Monolog\Formatter\MongoDBFormatterTest::testFormatDepthArray ( )

Definition at line 122 of file MongoDBFormatterTest.php.

References Monolog\Logger\getLevelName(), and Monolog\Logger\WARNING.

123  {
124  $record = array(
125  'message' => 'some log message',
126  'context' => array(
127  'nest2' => array(
128  'property' => 'anything',
129  'nest3' => array(
130  'nest4' => 'value',
131  'property' => 'nothing'
132  )
133  )
134  ),
135  'level' => Logger::WARNING,
136  'level_name' => Logger::getLevelName(Logger::WARNING),
137  'channel' => 'test',
138  'datetime' => new \DateTime('2014-02-01 00:00:00'),
139  'extra' => array(),
140  );
141 
142  $formatter = new MongoDBFormatter(2);
143  $formattedResult = $formatter->format($record);
144 
145  $this->assertEquals(
146  array(
147  'nest2' => array(
148  'property' => 'anything',
149  'nest3' => '[...]',
150  )
151  ),
152  $formattedResult['context']
153  );
154  }
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:52
static getLevelName($level)
Gets the name of the logging level.
Definition: Logger.php:388
+ Here is the call graph for this function:

◆ testFormatDepthArrayInfiniteNesting()

Monolog\Formatter\MongoDBFormatterTest::testFormatDepthArrayInfiniteNesting ( )

Definition at line 156 of file MongoDBFormatterTest.php.

References Monolog\Logger\getLevelName(), and Monolog\Logger\WARNING.

157  {
158  $record = array(
159  'message' => 'some log message',
160  'context' => array(
161  'nest2' => array(
162  'property' => 'something',
163  'nest3' => array(
164  'property' => 'anything',
165  'nest4' => array(
166  'property' => 'nothing',
167  ),
168  )
169  )
170  ),
171  'level' => Logger::WARNING,
172  'level_name' => Logger::getLevelName(Logger::WARNING),
173  'channel' => 'test',
174  'datetime' => new \DateTime('2014-02-01 00:00:00'),
175  'extra' => array(),
176  );
177 
178  $formatter = new MongoDBFormatter(0);
179  $formattedResult = $formatter->format($record);
180 
181  $this->assertEquals(
182  array(
183  'nest2' => array(
184  'property' => 'something',
185  'nest3' => array(
186  'property' => 'anything',
187  'nest4' => array(
188  'property' => 'nothing',
189  )
190  ),
191  )
192  ),
193  $formattedResult['context']
194  );
195  }
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:52
static getLevelName($level)
Gets the name of the logging level.
Definition: Logger.php:388
+ Here is the call graph for this function:

◆ testFormatDepthException()

Monolog\Formatter\MongoDBFormatterTest::testFormatDepthException ( )

Definition at line 232 of file MongoDBFormatterTest.php.

References Monolog\Logger\getLevelName(), and Monolog\Logger\WARNING.

233  {
234  $record = array(
235  'message' => 'some log message',
236  'context' => array(
237  'nest2' => new \Exception('exception message', 987),
238  ),
239  'level' => Logger::WARNING,
240  'level_name' => Logger::getLevelName(Logger::WARNING),
241  'channel' => 'test',
242  'datetime' => new \DateTime('2014-02-01 00:00:00'),
243  'extra' => array(),
244  );
245 
246  $formatter = new MongoDBFormatter(2, false);
247  $formattedRecord = $formatter->format($record);
248 
249  $this->assertEquals('exception message', $formattedRecord['context']['nest2']['message']);
250  $this->assertEquals(987, $formattedRecord['context']['nest2']['code']);
251  $this->assertEquals('[...]', $formattedRecord['context']['nest2']['trace']);
252  }
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:52
static getLevelName($level)
Gets the name of the logging level.
Definition: Logger.php:388
+ Here is the call graph for this function:

◆ testFormatDepthObjects()

Monolog\Formatter\MongoDBFormatterTest::testFormatDepthObjects ( )

Definition at line 197 of file MongoDBFormatterTest.php.

References Monolog\Logger\getLevelName(), and Monolog\Logger\WARNING.

198  {
199  $someObject = new \stdClass();
200  $someObject->property = 'anything';
201  $someObject->nest3 = new \stdClass();
202  $someObject->nest3->property = 'nothing';
203  $someObject->nest3->nest4 = 'invisible';
204 
205  $record = array(
206  'message' => 'some log message',
207  'context' => array(
208  'nest2' => $someObject
209  ),
210  'level' => Logger::WARNING,
211  'level_name' => Logger::getLevelName(Logger::WARNING),
212  'channel' => 'test',
213  'datetime' => new \DateTime('2014-02-01 00:00:00'),
214  'extra' => array(),
215  );
216 
217  $formatter = new MongoDBFormatter(2, true);
218  $formattedResult = $formatter->format($record);
219 
220  $this->assertEquals(
221  array(
222  'nest2' => array(
223  'property' => 'anything',
224  'nest3' => '[...]',
225  'class' => 'stdClass',
226  ),
227  ),
228  $formattedResult['context']
229  );
230  }
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:52
static getLevelName($level)
Gets the name of the logging level.
Definition: Logger.php:388
+ Here is the call graph for this function:

◆ testRecursiveFormat()

Monolog\Formatter\MongoDBFormatterTest::testRecursiveFormat ( )

Definition at line 74 of file MongoDBFormatterTest.php.

References Monolog\Logger\getLevelName(), and Monolog\Logger\WARNING.

75  {
76  $someObject = new \stdClass();
77  $someObject->foo = 'something';
78  $someObject->bar = 'stuff';
79 
80  $record = array(
81  'message' => 'some log message',
82  'context' => array(
83  'stuff' => new \DateTime('2014-02-01 02:31:33'),
84  'some_object' => $someObject,
85  'context_string' => 'some string',
86  'context_int' => 123456,
87  'except' => new \Exception('exception message', 987),
88  ),
89  'level' => Logger::WARNING,
90  'level_name' => Logger::getLevelName(Logger::WARNING),
91  'channel' => 'test',
92  'datetime' => new \DateTime('2014-02-01 00:00:00'),
93  'extra' => array(),
94  );
95 
96  $formatter = new MongoDBFormatter();
97  $formattedRecord = $formatter->format($record);
98 
99  $this->assertCount(5, $formattedRecord['context']);
100  $this->assertInstanceOf('\MongoDate', $formattedRecord['context']['stuff']);
101  $this->assertEquals('0.00000000 1391221893', $formattedRecord['context']['stuff']->__toString());
102  $this->assertEquals(
103  array(
104  'foo' => 'something',
105  'bar' => 'stuff',
106  'class' => 'stdClass',
107  ),
108  $formattedRecord['context']['some_object']
109  );
110  $this->assertEquals('some string', $formattedRecord['context']['context_string']);
111  $this->assertEquals(123456, $formattedRecord['context']['context_int']);
112 
113  $this->assertCount(5, $formattedRecord['context']['except']);
114  $this->assertEquals('exception message', $formattedRecord['context']['except']['message']);
115  $this->assertEquals(987, $formattedRecord['context']['except']['code']);
116  $this->assertInternalType('string', $formattedRecord['context']['except']['file']);
117  $this->assertInternalType('integer', $formattedRecord['context']['except']['code']);
118  $this->assertInternalType('string', $formattedRecord['context']['except']['trace']);
119  $this->assertEquals('Exception', $formattedRecord['context']['except']['class']);
120  }
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:52
static getLevelName($level)
Gets the name of the logging level.
Definition: Logger.php:388
+ Here is the call graph for this function:

◆ testSimpleFormat()

Monolog\Formatter\MongoDBFormatterTest::testSimpleFormat ( )

Definition at line 48 of file MongoDBFormatterTest.php.

References Monolog\Logger\getLevelName(), and Monolog\Logger\WARNING.

49  {
50  $record = array(
51  'message' => 'some log message',
52  'context' => array(),
53  'level' => Logger::WARNING,
54  'level_name' => Logger::getLevelName(Logger::WARNING),
55  'channel' => 'test',
56  'datetime' => new \DateTime('2014-02-01 00:00:00'),
57  'extra' => array(),
58  );
59 
60  $formatter = new MongoDBFormatter();
61  $formattedRecord = $formatter->format($record);
62 
63  $this->assertCount(7, $formattedRecord);
64  $this->assertEquals('some log message', $formattedRecord['message']);
65  $this->assertEquals(array(), $formattedRecord['context']);
66  $this->assertEquals(Logger::WARNING, $formattedRecord['level']);
67  $this->assertEquals(Logger::getLevelName(Logger::WARNING), $formattedRecord['level_name']);
68  $this->assertEquals('test', $formattedRecord['channel']);
69  $this->assertInstanceOf('\MongoDate', $formattedRecord['datetime']);
70  $this->assertEquals('0.00000000 1391212800', $formattedRecord['datetime']->__toString());
71  $this->assertEquals(array(), $formattedRecord['extra']);
72  }
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:52
static getLevelName($level)
Gets the name of the logging level.
Definition: Logger.php:388
+ Here is the call graph for this function:

The documentation for this class was generated from the following file: