ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
TestHandlerTest.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
21{
25 public function testHandler($method, $level)
26 {
28 $record = $this->getRecord($level, 'test'.$method);
29 $this->assertFalse($handler->hasRecords($level));
30 $this->assertFalse($handler->hasRecord($record, $level));
31 $this->assertFalse($handler->{'has'.$method}($record), 'has'.$method);
32 $this->assertFalse($handler->{'has'.$method.'ThatContains'}('test'), 'has'.$method.'ThatContains');
33 $this->assertFalse($handler->{'has'.$method.'ThatPasses'}(function ($rec) {
34 return true;
35 }), 'has'.$method.'ThatPasses');
36 $this->assertFalse($handler->{'has'.$method.'ThatMatches'}('/test\w+/'));
37 $this->assertFalse($handler->{'has'.$method.'Records'}(), 'has'.$method.'Records');
38 $handler->handle($record);
39
40 $this->assertFalse($handler->{'has'.$method}('bar'), 'has'.$method);
41 $this->assertTrue($handler->hasRecords($level));
42 $this->assertTrue($handler->hasRecord($record, $level));
43 $this->assertTrue($handler->{'has'.$method}($record), 'has'.$method);
44 $this->assertTrue($handler->{'has'.$method}('test'.$method), 'has'.$method);
45 $this->assertTrue($handler->{'has'.$method.'ThatContains'}('test'), 'has'.$method.'ThatContains');
46 $this->assertTrue($handler->{'has'.$method.'ThatPasses'}(function ($rec) {
47 return true;
48 }), 'has'.$method.'ThatPasses');
49 $this->assertTrue($handler->{'has'.$method.'ThatMatches'}('/test\w+/'));
50 $this->assertTrue($handler->{'has'.$method.'Records'}(), 'has'.$method.'Records');
51
52 $records = $handler->getRecords();
53 unset($records[0]['formatted']);
54 $this->assertEquals(array($record), $records);
55 }
56
59 $record = $this->getRecord(Logger::WARNING, 'test', array());
60 $this->assertFalse($handler->hasWarning(array(
61 'message' => 'test',
62 'context' => array(),
63 )));
64
65 $handler->handle($record);
66
67 $this->assertTrue($handler->hasWarning(array(
68 'message' => 'test',
69 'context' => array(),
70 )));
71 $this->assertFalse($handler->hasWarning(array(
72 'message' => 'test',
73 'context' => array(
74 'foo' => 'bar'
75 ),
76 )));
77 }
78
81 $record = $this->getRecord(Logger::WARNING, 'test', array('foo' => 'bar'));
82 $this->assertFalse($handler->hasWarning(array(
83 'message' => 'test',
84 'context' => array(
85 'foo' => 'bar'
86 ),
87 )));
88
89 $handler->handle($record);
90
91 $this->assertTrue($handler->hasWarning(array(
92 'message' => 'test',
93 'context' => array(
94 'foo' => 'bar'
95 ),
96 )));
97 $this->assertFalse($handler->hasWarning(array(
98 'message' => 'test',
99 'context' => array(),
100 )));
101 }
102
103 public function methodProvider()
104 {
105 return array(
106 array('Emergency', Logger::EMERGENCY),
107 array('Alert' , Logger::ALERT),
108 array('Critical' , Logger::CRITICAL),
109 array('Error' , Logger::ERROR),
110 array('Warning' , Logger::WARNING),
111 array('Info' , Logger::INFO),
112 array('Notice' , Logger::NOTICE),
113 array('Debug' , Logger::DEBUG),
114 );
115 }
116}
An exception for terminatinating execution or to throw for unit testing.
@covers Monolog\Handler\TestHandler
testHandler($method, $level)
@dataProvider methodProvider
Used for testing purposes.
Definition: TestHandler.php:67
Monolog log channel.
Definition: Logger.php:29
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
const DEBUG
$handler
$records
Definition: simple_test.php:22