MongoDBHandlerTest.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. class MongoDBHandlerTest extends TestCase
  14. {
  15. public function testHandle()
  16. {
  17. $mongo = $this->getMock('Mongo', array('selectCollection'));
  18. $collection = $this->getMock('stdClass', array('save'));
  19. $mongo->expects($this->once())
  20. ->method('selectCollection')
  21. ->with('DB', 'Collection')
  22. ->will($this->returnValue($collection));
  23. $record = $this->getRecord(Logger::WARNING, 'test', array('data' => new \stdClass, 'foo' => 34));
  24. $expected = array(
  25. 'message' => 'test',
  26. 'context' => array('data' => '[object] (stdClass: {})', 'foo' => 34),
  27. 'level' => Logger::WARNING,
  28. 'level_name' => 'WARNING',
  29. 'channel' => 'test',
  30. 'datetime' => $record['datetime']->format('Y-m-d H:i:s'),
  31. 'extra' => array(),
  32. );
  33. $collection->expects($this->once())
  34. ->method('save')
  35. ->with($expected);
  36. $handler = new MongoDBHandler($mongo, 'DB', 'Collection');
  37. $handler->handle($record);
  38. }
  39. }
  40. if (!class_exists('Mongo')) {
  41. class Mongo
  42. {
  43. public function selectCollection() {}
  44. }
  45. }