DynamoDbEventHandlerTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 65
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstruct() 0 3 1
A testInterface() 0 3 1
A testGetFormatter() 0 4 1
A testIsHandling() 0 4 1
A setUp() 0 9 2
A testHandle() 0 30 1
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(['formatAttributes', '__call'])
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
            ->method('formatAttributes')
60
            ->with($raw)
61
            ->will($this->returnValue($formatted));
62
        $this->client
63
             ->expects($this->once())
64
             ->method('__call')
65
             ->with('putItem', [[
66
                 'TableName' => 'foo',
67
                 'Item' => $formatted
68
             ]]);
69
70
        $handler->handle($record);
71
    }
72
}
73