scratch – Blame information for rev 115

Subversion Repositories:
Rev:
Rev Author Line No. Line
115 office 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  
14 use Monolog\TestCase;
15 use Monolog\Logger;
16  
17 class WhatFailureGroupHandlerTest extends TestCase
18 {
19 /**
20 * @covers Monolog\Handler\WhatFailureGroupHandler::__construct
21 * @expectedException InvalidArgumentException
22 */
23 public function testConstructorOnlyTakesHandler()
24 {
25 new WhatFailureGroupHandler(array(new TestHandler(), "foo"));
26 }
27  
28 /**
29 * @covers Monolog\Handler\WhatFailureGroupHandler::__construct
30 * @covers Monolog\Handler\WhatFailureGroupHandler::handle
31 */
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  
45 /**
46 * @covers Monolog\Handler\WhatFailureGroupHandler::handleBatch
47 */
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  
60 /**
61 * @covers Monolog\Handler\WhatFailureGroupHandler::isHandling
62 */
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  
72 /**
73 * @covers Monolog\Handler\WhatFailureGroupHandler::handle
74 */
75 public function testHandleUsesProcessors()
76 {
77 $test = new TestHandler();
78 $handler = new WhatFailureGroupHandler(array($test));
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  
90 /**
91 * @covers Monolog\Handler\WhatFailureGroupHandler::handle
92 */
93 public function testHandleException()
94 {
95 $test = new TestHandler();
96 $exception = new ExceptionTestHandler();
97 $handler = new WhatFailureGroupHandler(array($exception, $test, $exception));
98 $handler->pushProcessor(function ($record) {
99 $record['extra']['foo'] = true;
100  
101 return $record;
102 });
103 $handler->handle($this->getRecord(Logger::WARNING));
104 $this->assertTrue($test->hasWarningRecords());
105 $records = $test->getRecords();
106 $this->assertTrue($records[0]['extra']['foo']);
107 }
108 }
109  
110 class ExceptionTestHandler extends TestHandler
111 {
112 /**
113 * {@inheritdoc}
114 */
115 public function handle(array $record)
116 {
117 parent::handle($record);
118  
119 throw new \Exception("ExceptionTestHandler::handle");
120 }
121 }