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 Exception;
15 use Monolog\TestCase;
16 use Monolog\Logger;
17 use PHPUnit_Framework_MockObject_MockObject as MockObject;
18  
19 /**
20 * @author Erik Johansson <erik.pm.johansson@gmail.com>
21 * @see https://rollbar.com/docs/notifier/rollbar-php/
22 *
23 * @coversDefaultClass Monolog\Handler\RollbarHandler
24 */
25 class RollbarHandlerTest extends TestCase
26 {
27 /**
28 * @var MockObject
29 */
30 private $rollbarNotifier;
31  
32 /**
33 * @var array
34 */
35 public $reportedExceptionArguments = null;
36  
37 protected function setUp()
38 {
39 parent::setUp();
40  
41 $this->setupRollbarNotifierMock();
42 }
43  
44 /**
45 * When reporting exceptions to Rollbar the
46 * level has to be set in the payload data
47 */
48 public function testExceptionLogLevel()
49 {
50 $handler = $this->createHandler();
51  
52 $handler->handle($this->createExceptionRecord(Logger::DEBUG));
53  
54 $this->assertEquals('debug', $this->reportedExceptionArguments['payload']['level']);
55 }
56  
57 private function setupRollbarNotifierMock()
58 {
59 $this->rollbarNotifier = $this->getMockBuilder('RollbarNotifier')
60 ->setMethods(array('report_message', 'report_exception', 'flush'))
61 ->getMock();
62  
63 $that = $this;
64  
65 $this->rollbarNotifier
66 ->expects($this->any())
67 ->method('report_exception')
68 ->willReturnCallback(function ($exception, $context, $payload) use ($that) {
69 $that->reportedExceptionArguments = compact('exception', 'context', 'payload');
70 });
71 }
72  
73 private function createHandler()
74 {
75 return new RollbarHandler($this->rollbarNotifier, Logger::DEBUG);
76 }
77  
78 private function createExceptionRecord($level = Logger::DEBUG, $message = 'test', $exception = null)
79 {
80 return $this->getRecord($level, $message, array(
81 'exception' => $exception ?: new Exception()
82 ));
83 }
84 }