|
1
|
|
|
<?php |
|
2
|
|
|
namespace Graze\Monolog\Handler; |
|
3
|
|
|
|
|
4
|
|
|
use Monolog\TestCase; |
|
5
|
|
|
|
|
6
|
|
|
class SnsEventHandlerTest extends TestCase |
|
7
|
|
|
{ |
|
8
|
|
|
public function setUp() |
|
9
|
|
|
{ |
|
10
|
|
|
if (!class_exists('Aws\Sns\SnsClient')) { |
|
11
|
|
|
$this->markTestSkipped('aws/aws-sdk-php not installed'); |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
$this->client = $this->getMockBuilder('Aws\Sns\SnsClient') |
|
|
|
|
|
|
15
|
|
|
->setMethods(['formatAttributes', '__call']) |
|
16
|
|
|
->disableOriginalConstructor()->getMock(); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function testConstruct() |
|
20
|
|
|
{ |
|
21
|
|
|
$this->assertInstanceOf('Graze\Monolog\Handler\SnsEventHandler', new SnsEventHandler($this->client, 'foo')); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function testInterface() |
|
25
|
|
|
{ |
|
26
|
|
|
$this->assertInstanceOf('Monolog\Handler\HandlerInterface', new SnsEventHandler($this->client, 'foo')); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function testGetFormatter() |
|
30
|
|
|
{ |
|
31
|
|
|
$handler = new SnsEventHandler($this->client, 'foo'); |
|
32
|
|
|
$this->assertInstanceOf('Graze\Monolog\Formatter\JsonDateAwareFormatter', $handler->getFormatter()); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testIsHandling() |
|
36
|
|
|
{ |
|
37
|
|
|
$handler = new SnsEventHandler($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
|
|
|
$formatted = ['foo' => 1, 'bar' => 2]; |
|
46
|
|
|
$handler = new SnsEventHandler($this->client, 'foo'); |
|
47
|
|
|
$handler->setFormatter($formatter); |
|
48
|
|
|
|
|
49
|
|
|
$formatter |
|
50
|
|
|
->expects($this->once()) |
|
51
|
|
|
->method('format') |
|
52
|
|
|
->with($record) |
|
53
|
|
|
->will($this->returnValue($formatted)); |
|
54
|
|
|
$this->client |
|
55
|
|
|
->expects($this->once()) |
|
56
|
|
|
->method('__call') |
|
57
|
|
|
->with('publish', [[ |
|
58
|
|
|
'TopicArn' => 'foo', |
|
59
|
|
|
'Message' => $formatted, |
|
60
|
|
|
]]); |
|
61
|
|
|
|
|
62
|
|
|
$handler->handle($record); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|