PluginProbe
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance / 3.2.5
WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance v3.2.5
4.7.0 4.6.1 4.6.0 4.5.5 4.5.4 4.5.3 4.5.2 3.2.20 3.2.21 3.2.22 3.2.3 3.2.5 3.2.6 3.2.7 3.2.9 3.3.0 3.3.1 3.3.2 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.7.0 3.7.1 All 111 releases
wp-optimize / vendor / monolog / monolog / tests / Monolog / Handler / BufferHandlerTest.php

BufferHandlerTest.php in WP-Optimize – Cache, Compress images, Minify & Clean database to boost page speed & performance 3.2.5, at vendor/monolog/monolog/tests/Monolog/Handler/BufferHandlerTest.php

159 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Monolog package.
5 *
6 * (c) Jordi Boggiano <[email protected]>
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
14 use Monolog\Test\TestCase;
15 use Monolog\Logger;
16
17 class BufferHandlerTest extends TestCase
18 {
19 private $shutdownCheckHandler;
20
21 /**
22 * @covers Monolog\Handler\BufferHandler::__construct
23 * @covers Monolog\Handler\BufferHandler::handle
24 * @covers Monolog\Handler\BufferHandler::close
25 */
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->assertCount(2, $test->getRecords());
37 }
38
39 /**
40 * @covers Monolog\Handler\BufferHandler::close
41 * @covers Monolog\Handler\BufferHandler::flush
42 */
43 public function testPropagatesRecordsAtEndOfRequest()
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([$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
61 /**
62 * @covers Monolog\Handler\BufferHandler::handle
63 */
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
78 /**
79 * @covers Monolog\Handler\BufferHandler::handle
80 */
81 public function testHandleBufferLimitWithFlushOnOverflow()
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
108 /**
109 * @covers Monolog\Handler\BufferHandler::handle
110 */
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
125 /**
126 * @covers Monolog\Handler\BufferHandler::flush
127 */
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
140 /**
141 * @covers Monolog\Handler\BufferHandler::handle
142 */
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 }
159