Geen omschrijving

DynamoDbHandlerTest.php 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. $isV3 = defined('Aws\Sdk::VERSION') && version_compare(\Aws\Sdk::VERSION, '3.0', '>=');
  45. if ($isV3) {
  46. $expFormatted = array('foo' => array('N' => 1), 'bar' => array('N' => 2));
  47. } else {
  48. $expFormatted = $formatted;
  49. }
  50. $formatter
  51. ->expects($this->once())
  52. ->method('format')
  53. ->with($record)
  54. ->will($this->returnValue($formatted));
  55. $this->client
  56. ->expects($isV3 ? $this->never() : $this->once())
  57. ->method('formatAttributes')
  58. ->with($this->isType('array'))
  59. ->will($this->returnValue($formatted));
  60. $this->client
  61. ->expects($this->once())
  62. ->method('__call')
  63. ->with('putItem', array(array(
  64. 'TableName' => 'foo',
  65. 'Item' => $expFormatted,
  66. )));
  67. $handler->handle($record);
  68. }
  69. }