DoctrineCouchDBHandlerTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php declare(strict_types=1);
  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\Level;
  12. class DoctrineCouchDBHandlerTest extends \Monolog\Test\MonologTestCase
  13. {
  14. protected function setUp(): void
  15. {
  16. if (!class_exists('Doctrine\CouchDB\CouchDBClient')) {
  17. $this->markTestSkipped('The "doctrine/couchdb" package is not installed');
  18. }
  19. }
  20. public function testHandle()
  21. {
  22. $client = $this->getMockBuilder('Doctrine\\CouchDB\\CouchDBClient')
  23. ->onlyMethods(['postDocument'])
  24. ->disableOriginalConstructor()
  25. ->getMock();
  26. $record = $this->getRecord(Level::Warning, 'test', ['data' => new \stdClass, 'foo' => 34]);
  27. $expected = [
  28. 'message' => 'test',
  29. 'context' => ['data' => ['stdClass' => []], 'foo' => 34],
  30. 'level' => Level::Warning->value,
  31. 'level_name' => 'WARNING',
  32. 'channel' => 'test',
  33. 'datetime' => (string) $record->datetime,
  34. 'extra' => [],
  35. ];
  36. $client->expects($this->once())
  37. ->method('postDocument')
  38. ->with($expected);
  39. $handler = new DoctrineCouchDBHandler($client);
  40. $handler->handle($record);
  41. }
  42. }