ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Monolog\Handler\DeduplicationHandlerTest Class Reference
+ Inheritance diagram for Monolog\Handler\DeduplicationHandlerTest:
+ Collaboration diagram for Monolog\Handler\DeduplicationHandlerTest:

Public Member Functions

 testFlushPassthruIfAllRecordsUnderTrigger ()
 Monolog::flush More...
 
 testFlushPassthruIfEmptyLog ()
 Monolog::flush Monolog::appendRecord More...
 
 testFlushSkipsIfLogExists ()
 Monolog::flush Monolog::appendRecord Monolog::isDuplicate testFlushPassthruIfEmptyLog More...
 
 testFlushPassthruIfLogTooOld ()
 Monolog::flush Monolog::appendRecord Monolog::isDuplicate testFlushPassthruIfEmptyLog More...
 
 testGcOldLogs ()
 Monolog::flush Monolog::appendRecord Monolog::isDuplicate Monolog::collectLogs More...
 

Static Public Member Functions

static tearDownAfterClass ()
 

Additional Inherited Members

- Protected Member Functions inherited from Monolog\TestCase
 getRecord ($level=Logger::WARNING, $message='test', $context=array())
 
 getMultipleRecords ()
 
 getIdentityFormatter ()
 

Detailed Description

Definition at line 17 of file DeduplicationHandlerTest.php.

Member Function Documentation

◆ tearDownAfterClass()

static Monolog\Handler\DeduplicationHandlerTest::tearDownAfterClass ( )
static

Definition at line 161 of file DeduplicationHandlerTest.php.

162  {
163  @unlink(sys_get_temp_dir().'/monolog_dedup.log');
164  }

◆ testFlushPassthruIfAllRecordsUnderTrigger()

Monolog\Handler\DeduplicationHandlerTest::testFlushPassthruIfAllRecordsUnderTrigger ( )

Monolog::flush

Definition at line 22 of file DeduplicationHandlerTest.php.

References $handler, $test, Monolog\Logger\DEBUG, Monolog\TestCase\getRecord(), and Monolog\Logger\INFO.

23  {
24  $test = new TestHandler();
25  @unlink(sys_get_temp_dir().'/monolog_dedup.log');
26  $handler = new DeduplicationHandler($test, sys_get_temp_dir().'/monolog_dedup.log', 0);
27 
28  $handler->handle($this->getRecord(Logger::DEBUG));
29  $handler->handle($this->getRecord(Logger::INFO));
30 
31  $handler->flush();
32 
33  $this->assertTrue($test->hasInfoRecords());
34  $this->assertTrue($test->hasDebugRecords());
35  $this->assertFalse($test->hasWarningRecords());
36  }
const DEBUG
Detailed debug information.
Definition: Logger.php:33
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
$handler
$test
Definition: Utf8Test.php:84
const INFO
Interesting events.
Definition: Logger.php:40
+ Here is the call graph for this function:

◆ testFlushPassthruIfEmptyLog()

Monolog\Handler\DeduplicationHandlerTest::testFlushPassthruIfEmptyLog ( )

Monolog::flush Monolog::appendRecord

Definition at line 42 of file DeduplicationHandlerTest.php.

References $handler, $test, Monolog\Logger\CRITICAL, Monolog\Logger\ERROR, and Monolog\TestCase\getRecord().

43  {
44  $test = new TestHandler();
45  @unlink(sys_get_temp_dir().'/monolog_dedup.log');
46  $handler = new DeduplicationHandler($test, sys_get_temp_dir().'/monolog_dedup.log', 0);
47 
48  $handler->handle($this->getRecord(Logger::ERROR, 'Foo:bar'));
49  $handler->handle($this->getRecord(Logger::CRITICAL, "Foo\nbar"));
50 
51  $handler->flush();
52 
53  $this->assertTrue($test->hasErrorRecords());
54  $this->assertTrue($test->hasCriticalRecords());
55  $this->assertFalse($test->hasWarningRecords());
56  }
const ERROR
Runtime errors.
Definition: Logger.php:58
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
const CRITICAL
Critical conditions.
Definition: Logger.php:65
$handler
$test
Definition: Utf8Test.php:84
+ Here is the call graph for this function:

◆ testFlushPassthruIfLogTooOld()

Monolog\Handler\DeduplicationHandlerTest::testFlushPassthruIfLogTooOld ( )

Monolog::flush Monolog::appendRecord Monolog::isDuplicate testFlushPassthruIfEmptyLog

Definition at line 85 of file DeduplicationHandlerTest.php.

References $handler, $test, Monolog\Logger\CRITICAL, Monolog\Logger\ERROR, and Monolog\TestCase\getRecord().

86  {
87  $test = new TestHandler();
88  $handler = new DeduplicationHandler($test, sys_get_temp_dir().'/monolog_dedup.log', 0);
89 
90  $record = $this->getRecord(Logger::ERROR);
91  $record['datetime']->modify('+62seconds');
92  $handler->handle($record);
93  $record = $this->getRecord(Logger::CRITICAL);
94  $record['datetime']->modify('+62seconds');
95  $handler->handle($record);
96 
97  $handler->flush();
98 
99  $this->assertTrue($test->hasErrorRecords());
100  $this->assertTrue($test->hasCriticalRecords());
101  $this->assertFalse($test->hasWarningRecords());
102  }
const ERROR
Runtime errors.
Definition: Logger.php:58
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
const CRITICAL
Critical conditions.
Definition: Logger.php:65
$handler
$test
Definition: Utf8Test.php:84
+ Here is the call graph for this function:

◆ testFlushSkipsIfLogExists()

Monolog\Handler\DeduplicationHandlerTest::testFlushSkipsIfLogExists ( )

Monolog::flush Monolog::appendRecord Monolog::isDuplicate testFlushPassthruIfEmptyLog

Definition at line 64 of file DeduplicationHandlerTest.php.

References $handler, $test, Monolog\Logger\CRITICAL, Monolog\Logger\ERROR, and Monolog\TestCase\getRecord().

65  {
66  $test = new TestHandler();
67  $handler = new DeduplicationHandler($test, sys_get_temp_dir().'/monolog_dedup.log', 0);
68 
69  $handler->handle($this->getRecord(Logger::ERROR, 'Foo:bar'));
70  $handler->handle($this->getRecord(Logger::CRITICAL, "Foo\nbar"));
71 
72  $handler->flush();
73 
74  $this->assertFalse($test->hasErrorRecords());
75  $this->assertFalse($test->hasCriticalRecords());
76  $this->assertFalse($test->hasWarningRecords());
77  }
const ERROR
Runtime errors.
Definition: Logger.php:58
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
const CRITICAL
Critical conditions.
Definition: Logger.php:65
$handler
$test
Definition: Utf8Test.php:84
+ Here is the call graph for this function:

◆ testGcOldLogs()

Monolog\Handler\DeduplicationHandlerTest::testGcOldLogs ( )

Monolog::flush Monolog::appendRecord Monolog::isDuplicate Monolog::collectLogs

Definition at line 110 of file DeduplicationHandlerTest.php.

References $handler, $test, Monolog\Logger\CRITICAL, Monolog\Logger\ERROR, and Monolog\TestCase\getRecord().

111  {
112  $test = new TestHandler();
113  @unlink(sys_get_temp_dir().'/monolog_dedup.log');
114  $handler = new DeduplicationHandler($test, sys_get_temp_dir().'/monolog_dedup.log', 0);
115 
116  // handle two records from yesterday, and one recent
117  $record = $this->getRecord(Logger::ERROR);
118  $record['datetime']->modify('-1day -10seconds');
119  $handler->handle($record);
120  $record2 = $this->getRecord(Logger::CRITICAL);
121  $record2['datetime']->modify('-1day -10seconds');
122  $handler->handle($record2);
123  $record3 = $this->getRecord(Logger::CRITICAL);
124  $record3['datetime']->modify('-30seconds');
125  $handler->handle($record3);
126 
127  // log is written as none of them are duplicate
128  $handler->flush();
129  $this->assertSame(
130  $record['datetime']->getTimestamp() . ":ERROR:test\n" .
131  $record2['datetime']->getTimestamp() . ":CRITICAL:test\n" .
132  $record3['datetime']->getTimestamp() . ":CRITICAL:test\n",
133  file_get_contents(sys_get_temp_dir() . '/monolog_dedup.log')
134  );
135  $this->assertTrue($test->hasErrorRecords());
136  $this->assertTrue($test->hasCriticalRecords());
137  $this->assertFalse($test->hasWarningRecords());
138 
139  // clear test handler
140  $test->clear();
141  $this->assertFalse($test->hasErrorRecords());
142  $this->assertFalse($test->hasCriticalRecords());
143 
144  // log new records, duplicate log gets GC'd at the end of this flush call
145  $handler->handle($record = $this->getRecord(Logger::ERROR));
146  $handler->handle($record2 = $this->getRecord(Logger::CRITICAL));
147  $handler->flush();
148 
149  // log should now contain the new errors and the previous one that was recent enough
150  $this->assertSame(
151  $record3['datetime']->getTimestamp() . ":CRITICAL:test\n" .
152  $record['datetime']->getTimestamp() . ":ERROR:test\n" .
153  $record2['datetime']->getTimestamp() . ":CRITICAL:test\n",
154  file_get_contents(sys_get_temp_dir() . '/monolog_dedup.log')
155  );
156  $this->assertTrue($test->hasErrorRecords());
157  $this->assertTrue($test->hasCriticalRecords());
158  $this->assertFalse($test->hasWarningRecords());
159  }
const ERROR
Runtime errors.
Definition: Logger.php:58
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
const CRITICAL
Critical conditions.
Definition: Logger.php:65
$handler
$test
Definition: Utf8Test.php:84
+ Here is the call graph for this function:

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