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') |
|
|
|
|
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
|
|
|
|