DynamoDbHandlerTest.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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')->disableOriginalConstructor()->getMock();
  20. }
  21. public function testConstruct()
  22. {
  23. $this->assertInstanceOf('Monolog\Handler\DynamoDbHandler', new DynamoDbHandler($this->client, 'foo'));
  24. }
  25. public function testInterface()
  26. {
  27. $this->assertInstanceOf('Monolog\Handler\HandlerInterface', new DynamoDbHandler($this->client, 'foo'));
  28. }
  29. public function testGetFormatter()
  30. {
  31. $handler = new DynamoDbHandler($this->client, 'foo');
  32. $this->assertInstanceOf('Monolog\Formatter\ScalarFormatter', $handler->getFormatter());
  33. }
  34. public function testHandle()
  35. {
  36. $record = $this->getRecord();
  37. $formatter = $this->getMock('Monolog\Formatter\FormatterInterface');
  38. $formatted = array('foo' => 1, 'bar' => 2);
  39. $handler = new DynamoDbHandler($this->client, 'foo');
  40. $handler->setFormatter($formatter);
  41. $formatter
  42. ->expects($this->once())
  43. ->method('format')
  44. ->with($record)
  45. ->will($this->returnValue($formatted));
  46. $this->client
  47. ->expects($this->once())
  48. ->method('formatAttributes')
  49. ->with($this->isType('array'))
  50. ->will($this->returnValue($formatted));
  51. $this->client
  52. ->expects($this->once())
  53. ->method('__call')
  54. ->with('putItem', array(array(
  55. 'TableName' => 'foo',
  56. 'Item' => $formatted
  57. )));
  58. $handler->handle($record);
  59. }
  60. }