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

SnsEventHandlerTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testHandle() 0 22 1
A testInterface() 0 3 1
A testConstruct() 0 3 1
A testGetFormatter() 0 4 1
A setUp() 0 9 2
A testIsHandling() 0 4 1
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')
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\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 = array('foo' => 1, 'bar' => 2);
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
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', array(array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
58
                 'TopicArn' => 'foo',
59
                 'Message' => $formatted,
60
             )));
61
62
        $handler->handle($record);
63
    }
64
}
65