scratch – Blame information for rev

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 use Monolog\Formatter\LineFormatter;
17 use Monolog\Processor\WebProcessor;
18  
19 class AbstractHandlerTest extends TestCase
20 {
21 /**
22 * @covers Monolog\Handler\AbstractHandler::__construct
23 * @covers Monolog\Handler\AbstractHandler::getLevel
24 * @covers Monolog\Handler\AbstractHandler::setLevel
25 * @covers Monolog\Handler\AbstractHandler::getBubble
26 * @covers Monolog\Handler\AbstractHandler::setBubble
27 * @covers Monolog\Handler\AbstractHandler::getFormatter
28 * @covers Monolog\Handler\AbstractHandler::setFormatter
29 */
30 public function testConstructAndGetSet()
31 {
32 $handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler', array(Logger::WARNING, false));
33 $this->assertEquals(Logger::WARNING, $handler->getLevel());
34 $this->assertEquals(false, $handler->getBubble());
35  
36 $handler->setLevel(Logger::ERROR);
37 $handler->setBubble(true);
38 $handler->setFormatter($formatter = new LineFormatter);
39 $this->assertEquals(Logger::ERROR, $handler->getLevel());
40 $this->assertEquals(true, $handler->getBubble());
41 $this->assertSame($formatter, $handler->getFormatter());
42 }
43  
44 /**
45 * @covers Monolog\Handler\AbstractHandler::handleBatch
46 */
47 public function testHandleBatch()
48 {
49 $handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler');
50 $handler->expects($this->exactly(2))
51 ->method('handle');
52 $handler->handleBatch(array($this->getRecord(), $this->getRecord()));
53 }
54  
55 /**
56 * @covers Monolog\Handler\AbstractHandler::isHandling
57 */
58 public function testIsHandling()
59 {
60 $handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler', array(Logger::WARNING, false));
61 $this->assertTrue($handler->isHandling($this->getRecord()));
62 $this->assertFalse($handler->isHandling($this->getRecord(Logger::DEBUG)));
63 }
64  
65 /**
66 * @covers Monolog\Handler\AbstractHandler::__construct
67 */
68 public function testHandlesPsrStyleLevels()
69 {
70 $handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler', array('warning', false));
71 $this->assertFalse($handler->isHandling($this->getRecord(Logger::DEBUG)));
72 $handler->setLevel('debug');
73 $this->assertTrue($handler->isHandling($this->getRecord(Logger::DEBUG)));
74 }
75  
76 /**
77 * @covers Monolog\Handler\AbstractHandler::getFormatter
78 * @covers Monolog\Handler\AbstractHandler::getDefaultFormatter
79 */
80 public function testGetFormatterInitializesDefault()
81 {
82 $handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler');
83 $this->assertInstanceOf('Monolog\Formatter\LineFormatter', $handler->getFormatter());
84 }
85  
86 /**
87 * @covers Monolog\Handler\AbstractHandler::pushProcessor
88 * @covers Monolog\Handler\AbstractHandler::popProcessor
89 * @expectedException LogicException
90 */
91 public function testPushPopProcessor()
92 {
93 $logger = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler');
94 $processor1 = new WebProcessor;
95 $processor2 = new WebProcessor;
96  
97 $logger->pushProcessor($processor1);
98 $logger->pushProcessor($processor2);
99  
100 $this->assertEquals($processor2, $logger->popProcessor());
101 $this->assertEquals($processor1, $logger->popProcessor());
102 $logger->popProcessor();
103 }
104  
105 /**
106 * @covers Monolog\Handler\AbstractHandler::pushProcessor
107 * @expectedException InvalidArgumentException
108 */
109 public function testPushProcessorWithNonCallable()
110 {
111 $handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler');
112  
113 $handler->pushProcessor(new \stdClass());
114 }
115 }