ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
DynamoDbHandlerTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the Monolog package.
5  *
6  * (c) Jordi Boggiano <j.boggiano@seld.be>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 namespace Monolog\Handler;
13 
15 
17 {
18  public function setUp()
19  {
20  if (!class_exists('Aws\DynamoDb\DynamoDbClient')) {
21  $this->markTestSkipped('aws/aws-sdk-php not installed');
22  }
23 
24  $this->client = $this->getMockBuilder('Aws\DynamoDb\DynamoDbClient')
25  ->setMethods(array('formatAttributes', '__call'))
26  ->disableOriginalConstructor()->getMock();
27  }
28 
29  public function testConstruct()
30  {
31  $this->assertInstanceOf('Monolog\Handler\DynamoDbHandler', new DynamoDbHandler($this->client, 'foo'));
32  }
33 
34  public function testInterface()
35  {
36  $this->assertInstanceOf('Monolog\Handler\HandlerInterface', new DynamoDbHandler($this->client, 'foo'));
37  }
38 
39  public function testGetFormatter()
40  {
41  $handler = new DynamoDbHandler($this->client, 'foo');
42  $this->assertInstanceOf('Monolog\Formatter\ScalarFormatter', $handler->getFormatter());
43  }
44 
45  public function testHandle()
46  {
47  $record = $this->getRecord();
48  $formatter = $this->getMock('Monolog\Formatter\FormatterInterface');
49  $formatted = array('foo' => 1, 'bar' => 2);
50  $handler = new DynamoDbHandler($this->client, 'foo');
51  $handler->setFormatter($formatter);
52 
53  $formatter
54  ->expects($this->once())
55  ->method('format')
56  ->with($record)
57  ->will($this->returnValue($formatted));
58  $this->client
59  ->expects($this->once())
60  ->method('formatAttributes')
61  ->with($this->isType('array'))
62  ->will($this->returnValue($formatted));
63  $this->client
64  ->expects($this->once())
65  ->method('__call')
66  ->with('putItem', array(array(
67  'TableName' => 'foo',
68  'Item' => $formatted
69  )));
70 
71  $handler->handle($record);
72  }
73 }
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
Amazon DynamoDB handler (http://aws.amazon.com/dynamodb/)