RavenHandlerTest.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. /*
  3. * This file is part of the Monolog package.
  4. *
  5. * (c) Jordi Boggiano <j.boggiano@seld.be>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Monolog\Handler;
  11. use Monolog\TestCase;
  12. use Monolog\Logger;
  13. use Monolog\Handler\RavenHandler;
  14. class RavenHandlerTest extends TestCase
  15. {
  16. public function setUp()
  17. {
  18. if (!class_exists("Raven_Client")) {
  19. $this->markTestSkipped("raven/raven not installed");
  20. }
  21. require_once __DIR__ . '/MockRavenClient.php';
  22. }
  23. /**
  24. * @covers Monolog\Handler\RavenHandler::__construct
  25. */
  26. public function testConstruct()
  27. {
  28. $handler = new RavenHandler($this->getRavenClient());
  29. $this->assertInstanceOf('Monolog\Handler\RavenHandler', $handler);
  30. }
  31. protected function getHandler($ravenClient)
  32. {
  33. $handler = new RavenHandler($ravenClient);
  34. return $handler;
  35. }
  36. protected function getRavenClient()
  37. {
  38. $dsn = 'http://43f6017361224d098402974103bfc53d:a6a0538fc2934ba2bed32e08741b2cd3@marca.python.live.cheggnet.com:9000/1';
  39. return new MockRavenClient($dsn);
  40. }
  41. public function testDebug()
  42. {
  43. $ravenClient = $this->getRavenClient();
  44. $handler = $this->getHandler($ravenClient);
  45. $record = $this->getRecord(Logger::DEBUG, "A test debug message");
  46. $handler->handle($record);
  47. $this->assertEquals($ravenClient::DEBUG, $ravenClient->lastData['level']);
  48. $this->assertContains($record['message'], $ravenClient->lastData['message']);
  49. }
  50. public function testWarning()
  51. {
  52. $ravenClient = $this->getRavenClient();
  53. $handler = $this->getHandler($ravenClient);
  54. $record = $this->getRecord(Logger::WARNING, "A test warning message");
  55. $handler->handle($record);
  56. $this->assertEquals($ravenClient::WARNING, $ravenClient->lastData['level']);
  57. $this->assertContains($record['message'], $ravenClient->lastData['message']);
  58. }
  59. public function testException()
  60. {
  61. $ravenClient = $this->getRavenClient();
  62. $handler = $this->getHandler($ravenClient);
  63. try {
  64. $this->methodThatThrowsAnException();
  65. } catch (\Exception $e) {
  66. $record = $this->getRecord(Logger::ERROR, $e->getMessage(), array('exception' => $e));
  67. $handler->handle($record);
  68. }
  69. $this->assertEquals($record['message'], $ravenClient->lastData['message']);
  70. }
  71. private function methodThatThrowsAnException()
  72. {
  73. throw new \Exception('This is an exception');
  74. }
  75. }