DoctrineCouchDBHandlerTest.php 1.4 KB

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