ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
WhatFailureGroupHandlerTest.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 {
24  {
25  new WhatFailureGroupHandler(array(new TestHandler(), "foo"));
26  }
27 
32  public function testHandle()
33  {
34  $testHandlers = array(new TestHandler(), new TestHandler());
35  $handler = new WhatFailureGroupHandler($testHandlers);
36  $handler->handle($this->getRecord(Logger::DEBUG));
37  $handler->handle($this->getRecord(Logger::INFO));
38  foreach ($testHandlers as $test) {
39  $this->assertTrue($test->hasDebugRecords());
40  $this->assertTrue($test->hasInfoRecords());
41  $this->assertTrue(count($test->getRecords()) === 2);
42  }
43  }
44 
48  public function testHandleBatch()
49  {
50  $testHandlers = array(new TestHandler(), new TestHandler());
51  $handler = new WhatFailureGroupHandler($testHandlers);
52  $handler->handleBatch(array($this->getRecord(Logger::DEBUG), $this->getRecord(Logger::INFO)));
53  foreach ($testHandlers as $test) {
54  $this->assertTrue($test->hasDebugRecords());
55  $this->assertTrue($test->hasInfoRecords());
56  $this->assertTrue(count($test->getRecords()) === 2);
57  }
58  }
59 
63  public function testIsHandling()
64  {
65  $testHandlers = array(new TestHandler(Logger::ERROR), new TestHandler(Logger::WARNING));
66  $handler = new WhatFailureGroupHandler($testHandlers);
67  $this->assertTrue($handler->isHandling($this->getRecord(Logger::ERROR)));
68  $this->assertTrue($handler->isHandling($this->getRecord(Logger::WARNING)));
69  $this->assertFalse($handler->isHandling($this->getRecord(Logger::DEBUG)));
70  }
71 
75  public function testHandleUsesProcessors()
76  {
77  $test = new TestHandler();
79  $handler->pushProcessor(function ($record) {
80  $record['extra']['foo'] = true;
81 
82  return $record;
83  });
84  $handler->handle($this->getRecord(Logger::WARNING));
85  $this->assertTrue($test->hasWarningRecords());
86  $records = $test->getRecords();
87  $this->assertTrue($records[0]['extra']['foo']);
88  }
89 
94  {
95  $testHandlers = array(new TestHandler(), new TestHandler());
96  $handler = new WhatFailureGroupHandler($testHandlers);
97  $handler->pushProcessor(function ($record) {
98  $record['extra']['foo'] = true;
99 
100  return $record;
101  });
102  $handler->handleBatch(array($this->getRecord(Logger::DEBUG), $this->getRecord(Logger::INFO)));
103  foreach ($testHandlers as $test) {
104  $this->assertTrue($test->hasDebugRecords());
105  $this->assertTrue($test->hasInfoRecords());
106  $this->assertTrue(count($test->getRecords()) === 2);
107  $records = $test->getRecords();
108  $this->assertTrue($records[0]['extra']['foo']);
109  $this->assertTrue($records[1]['extra']['foo']);
110  }
111  }
112 
116  public function testHandleException()
117  {
118  $test = new TestHandler();
119  $exception = new ExceptionTestHandler();
120  $handler = new WhatFailureGroupHandler(array($exception, $test, $exception));
121  $handler->pushProcessor(function ($record) {
122  $record['extra']['foo'] = true;
123 
124  return $record;
125  });
126  $handler->handle($this->getRecord(Logger::WARNING));
127  $this->assertTrue($test->hasWarningRecords());
128  $records = $test->getRecords();
129  $this->assertTrue($records[0]['extra']['foo']);
130  }
131 }
132 
134 {
138  public function handle(array $record)
139  {
140  parent::handle($record);
141 
142  throw new \Exception("ExceptionTestHandler::handle");
143  }
144 }
const DEBUG
Detailed debug information.
Definition: Logger.php:33
const ERROR
Runtime errors.
Definition: Logger.php:58
testHandle()
Monolog::__construct Monolog::handle
testConstructorOnlyTakesHandler()
Monolog::__construct InvalidArgumentException
$records
Definition: simple_test.php:22
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
Forwards records to multiple handlers suppressing failures of each handler and continuing through to ...
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:53
handle(array $record)
{Handles a record.All records may be passed to this method, and the handler should discard those that...
Used for testing purposes.
Definition: TestHandler.php:66
$handler
$test
Definition: Utf8Test.php:84
const INFO
Interesting events.
Definition: Logger.php:40