DynamoDbHandlerTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. class DynamoDbHandlerTest extends TestCase
  13. {
  14. private $client;
  15. public function setUp()
  16. {
  17. if (!class_exists('Aws\DynamoDb\DynamoDbClient')) {
  18. $this->markTestSkipped('aws/aws-sdk-php not installed');
  19. }
  20. $this->client = $this->getMockBuilder('Aws\DynamoDb\DynamoDbClient')
  21. ->setMethods(['formatAttributes', '__call'])
  22. ->disableOriginalConstructor()
  23. ->getMock();
  24. }
  25. public function testConstruct()
  26. {
  27. $this->assertInstanceOf('Monolog\Handler\DynamoDbHandler', new DynamoDbHandler($this->client, 'foo'));
  28. }
  29. public function testInterface()
  30. {
  31. $this->assertInstanceOf('Monolog\Handler\HandlerInterface', new DynamoDbHandler($this->client, 'foo'));
  32. }
  33. public function testGetFormatter()
  34. {
  35. $handler = new DynamoDbHandler($this->client, 'foo');
  36. $this->assertInstanceOf('Monolog\Formatter\ScalarFormatter', $handler->getFormatter());
  37. }
  38. public function testHandle()
  39. {
  40. $record = $this->getRecord();
  41. $formatter = $this->createMock('Monolog\Formatter\FormatterInterface');
  42. $formatted = ['foo' => 1, 'bar' => 2];
  43. $handler = new DynamoDbHandler($this->client, 'foo');
  44. $handler->setFormatter($formatter);
  45. $formatter
  46. ->expects($this->once())
  47. ->method('format')
  48. ->with($record)
  49. ->will($this->returnValue($formatted));
  50. $this->client
  51. ->expects($this->once())
  52. ->method('formatAttributes')
  53. ->with($this->isType('array'))
  54. ->will($this->returnValue($formatted));
  55. $this->client
  56. ->expects($this->once())
  57. ->method('__call')
  58. ->with('putItem', [[
  59. 'TableName' => 'foo',
  60. 'Item' => $formatted,
  61. ]]);
  62. $handler->handle($record);
  63. }
  64. }