Passed
Push — master ( ddd97a...25aa58 )
by Harry
06:46
created

DynamoDbEventHandlerTest::testHandle()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 20
nc 1
nop 0
dl 0
loc 26
rs 8.8571
c 0
b 0
f 0
1
<?php
2
namespace Graze\Monolog\Handler;
3
4
use \Monolog\TestCase;
5
6
class DynamoDbEventHandlerTest extends TestCase
7
{
8
    public function setUp()
9
    {
10
        if (!class_exists('Aws\DynamoDb\DynamoDbClient')) {
11
            $this->markTestSkipped('aws/aws-sdk-php not installed');
12
        }
13
14
        $this->client = $this->getMockBuilder('Aws\DynamoDb\DynamoDbClient')
0 ignored issues
show
Bug Best Practice introduced by
The property client does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
15
            ->setMethods(array('formatAttributes', '__call'))
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
16
            ->disableOriginalConstructor()->getMock();
17
    }
18
19
    public function testConstruct()
20
    {
21
        $this->assertInstanceOf('Graze\Monolog\Handler\DynamoDbEventHandler', new DynamoDbEventHandler($this->client, 'foo'));
22
    }
23
24
    public function testInterface()
25
    {
26
        $this->assertInstanceOf('Monolog\Handler\HandlerInterface', new DynamoDbEventHandler($this->client, 'foo'));
27
    }
28
29
    public function testGetFormatter()
30
    {
31
        $handler = new DynamoDbEventHandler($this->client, 'foo');
32
        $this->assertInstanceOf('Monolog\Formatter\ScalarFormatter', $handler->getFormatter());
33
    }
34
35
    public function testIsHandling()
36
    {
37
        $handler = new DynamoDbEventHandler($this->client, 'foo');
38
        $this->assertTrue($handler->isHandling($this->getRecord()));
39
    }
40
41
    public function testHandle()
42
    {
43
        $record = $this->getRecord();
44
        $formatter = $this->getMock('Monolog\Formatter\FormatterInterface');
45
        $raw = ['foo' => 1, 'bar' => 2];
46
        $formatted = [
47
            'foo' => ['N' => '1'],
48
            'bar' => ['N' => '2']
49
        ];
50
        $handler = new DynamoDbEventHandler($this->client, 'foo');
51
        $handler->setFormatter($formatter);
52
53
        $formatter
54
             ->expects($this->once())
55
             ->method('format')
56
             ->with($record)
57
             ->will($this->returnValue($raw));
58
        $this->client
59
             ->expects($this->once())
60
             ->method('__call')
61
             ->with('putItem', array(array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
62
                 'TableName' => 'foo',
63
                 'Item' => $formatted
64
             )));
65
66
        $handler->handle($record);
67
    }
68
}
69