DynamoDbHandlerTest.php 2.2 KB

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