DynamoDbHandlerTest.php 2.1 KB

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