scratch – Blame information for rev

Subversion Repositories:
Rev:
Rev Author Line No. Line
115 office 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  
14 use Monolog\TestCase;
15  
16 class DynamoDbHandlerTest extends TestCase
17 {
18 private $client;
19  
20 public function setUp()
21 {
22 if (!class_exists('Aws\DynamoDb\DynamoDbClient')) {
23 $this->markTestSkipped('aws/aws-sdk-php not installed');
24 }
25  
26 $this->client = $this->getMockBuilder('Aws\DynamoDb\DynamoDbClient')
27 ->setMethods(array('formatAttributes', '__call'))
28 ->disableOriginalConstructor()->getMock();
29 }
30  
31 public function testConstruct()
32 {
33 $this->assertInstanceOf('Monolog\Handler\DynamoDbHandler', new DynamoDbHandler($this->client, 'foo'));
34 }
35  
36 public function testInterface()
37 {
38 $this->assertInstanceOf('Monolog\Handler\HandlerInterface', new DynamoDbHandler($this->client, 'foo'));
39 }
40  
41 public function testGetFormatter()
42 {
43 $handler = new DynamoDbHandler($this->client, 'foo');
44 $this->assertInstanceOf('Monolog\Formatter\ScalarFormatter', $handler->getFormatter());
45 }
46  
47 public function testHandle()
48 {
49 $record = $this->getRecord();
50 $formatter = $this->getMock('Monolog\Formatter\FormatterInterface');
51 $formatted = array('foo' => 1, 'bar' => 2);
52 $handler = new DynamoDbHandler($this->client, 'foo');
53 $handler->setFormatter($formatter);
54  
55 $isV3 = defined('Aws\Sdk::VERSION') && version_compare(\Aws\Sdk::VERSION, '3.0', '>=');
56 if ($isV3) {
57 $expFormatted = array('foo' => array('N' => 1), 'bar' => array('N' => 2));
58 } else {
59 $expFormatted = $formatted;
60 }
61  
62 $formatter
63 ->expects($this->once())
64 ->method('format')
65 ->with($record)
66 ->will($this->returnValue($formatted));
67 $this->client
68 ->expects($isV3 ? $this->never() : $this->once())
69 ->method('formatAttributes')
70 ->with($this->isType('array'))
71 ->will($this->returnValue($formatted));
72 $this->client
73 ->expects($this->once())
74 ->method('__call')
75 ->with('putItem', array(array(
76 'TableName' => 'foo',
77 'Item' => $expFormatted,
78 )));
79  
80 $handler->handle($record);
81 }
82 }