ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
BufferHandlerTest.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 {
20 
26  public function testHandleBuffers()
27  {
28  $test = new TestHandler();
29  $handler = new BufferHandler($test);
30  $handler->handle($this->getRecord(Logger::DEBUG));
31  $handler->handle($this->getRecord(Logger::INFO));
32  $this->assertFalse($test->hasDebugRecords());
33  $this->assertFalse($test->hasInfoRecords());
34  $handler->close();
35  $this->assertTrue($test->hasInfoRecords());
36  $this->assertTrue(count($test->getRecords()) === 2);
37  }
38 
44  {
45  $test = new TestHandler();
46  $handler = new BufferHandler($test);
47  $handler->handle($this->getRecord(Logger::WARNING));
48  $handler->handle($this->getRecord(Logger::DEBUG));
49  $this->shutdownCheckHandler = $test;
50  register_shutdown_function(array($this, 'checkPropagation'));
51  }
52 
53  public function checkPropagation()
54  {
55  if (!$this->shutdownCheckHandler->hasWarningRecords() || !$this->shutdownCheckHandler->hasDebugRecords()) {
56  echo '!!! BufferHandlerTest::testPropagatesRecordsAtEndOfRequest failed to verify that the messages have been propagated' . PHP_EOL;
57  exit(1);
58  }
59  }
60 
64  public function testHandleBufferLimit()
65  {
66  $test = new TestHandler();
67  $handler = new BufferHandler($test, 2);
68  $handler->handle($this->getRecord(Logger::DEBUG));
69  $handler->handle($this->getRecord(Logger::DEBUG));
70  $handler->handle($this->getRecord(Logger::INFO));
71  $handler->handle($this->getRecord(Logger::WARNING));
72  $handler->close();
73  $this->assertTrue($test->hasWarningRecords());
74  $this->assertTrue($test->hasInfoRecords());
75  $this->assertFalse($test->hasDebugRecords());
76  }
77 
82  {
83  $test = new TestHandler();
84  $handler = new BufferHandler($test, 3, Logger::DEBUG, true, true);
85 
86  // send two records
87  $handler->handle($this->getRecord(Logger::DEBUG));
88  $handler->handle($this->getRecord(Logger::DEBUG));
89  $handler->handle($this->getRecord(Logger::DEBUG));
90  $this->assertFalse($test->hasDebugRecords());
91  $this->assertCount(0, $test->getRecords());
92 
93  // overflow
94  $handler->handle($this->getRecord(Logger::INFO));
95  $this->assertTrue($test->hasDebugRecords());
96  $this->assertCount(3, $test->getRecords());
97 
98  // should buffer again
99  $handler->handle($this->getRecord(Logger::WARNING));
100  $this->assertCount(3, $test->getRecords());
101 
102  $handler->close();
103  $this->assertCount(5, $test->getRecords());
104  $this->assertTrue($test->hasWarningRecords());
105  $this->assertTrue($test->hasInfoRecords());
106  }
107 
111  public function testHandleLevel()
112  {
113  $test = new TestHandler();
114  $handler = new BufferHandler($test, 0, Logger::INFO);
115  $handler->handle($this->getRecord(Logger::DEBUG));
116  $handler->handle($this->getRecord(Logger::INFO));
117  $handler->handle($this->getRecord(Logger::WARNING));
118  $handler->handle($this->getRecord(Logger::DEBUG));
119  $handler->close();
120  $this->assertTrue($test->hasWarningRecords());
121  $this->assertTrue($test->hasInfoRecords());
122  $this->assertFalse($test->hasDebugRecords());
123  }
124 
128  public function testFlush()
129  {
130  $test = new TestHandler();
131  $handler = new BufferHandler($test, 0);
132  $handler->handle($this->getRecord(Logger::DEBUG));
133  $handler->handle($this->getRecord(Logger::INFO));
134  $handler->flush();
135  $this->assertTrue($test->hasInfoRecords());
136  $this->assertTrue($test->hasDebugRecords());
137  $this->assertFalse($test->hasWarningRecords());
138  }
139 
143  public function testHandleUsesProcessors()
144  {
145  $test = new TestHandler();
146  $handler = new BufferHandler($test);
147  $handler->pushProcessor(function ($record) {
148  $record['extra']['foo'] = true;
149 
150  return $record;
151  });
152  $handler->handle($this->getRecord(Logger::WARNING));
153  $handler->flush();
154  $this->assertTrue($test->hasWarningRecords());
155  $records = $test->getRecords();
156  $this->assertTrue($records[0]['extra']['foo']);
157  }
158 }
testHandleBuffers()
Monolog::__construct Monolog::handle Monolog::close
testPropagatesRecordsAtEndOfRequest()
Monolog::close Monolog::flush
const DEBUG
Detailed debug information.
Definition: Logger.php:32
Buffers all records until closing the handler and then pass them as batch.
$records
Definition: simple_test.php:22
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
if($is_dev) echo "Review changes write something in WHATSNEW and and then commit with log PHP_EOL
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:52
Create styles array
The data for the language used.
testHandleBufferLimitWithFlushOnOverflow()
Monolog::handle
Used for testing purposes.
Definition: TestHandler.php:66
$test
Definition: Utf8Test.php:84
const INFO
Interesting events.
Definition: Logger.php:39