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

EventTest::testMultipleHandlers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
namespace Graze\Monolog;
3
4
use Monolog\TestCase;
5
6
class EventTest extends TestCase
7
{
8
    public function setupMockHandler()
0 ignored issues
show
introduced by
Function has return keyword but no doc block
Loading history...
9
    {
10
        $handler = $this->getMock('Monolog\Handler\HandlerInterface');
11
        $handler->expects($this->once())
12
                ->method('handle');
13
        return $handler;
14
    }
15
16
    public function setupMockHandlerWithValidationCallback($callback)
0 ignored issues
show
introduced by
Function has return keyword but no doc block
Loading history...
17
    {
18
        $handler = $this->setupMockHandler();
19
        $handler->expects($this->once())
20
                ->method('handle')
21
                ->with($this->callback($callback));
22
23
        return $handler;
24
    }
25
26
    public function testConstruct()
27
    {
28
        $this->assertInstanceOf('Graze\Monolog\Event', new Event());
29
    }
30
31
    public function testIdentifier()
32
    {
33
        $callback = function($data) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
34
            return 'foo' === $data['eventIdentifier'];
35
        };
36
        $handler = $this->setupMockHandlerWithValidationCallback($callback);
37
38
        $event = new Event(array($handler));
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
39
        $event->setIdentifier('foo');
40
        $event->publish();
41
    }
42
43
    public function testData()
44
    {
45
        $callback = function($data) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
46
            return 5 === $data['data']['foo'];
47
        };
48
        $handler = $this->setupMockHandlerWithValidationCallback($callback);
49
50
        $event = new Event(array($handler));
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
51
        $event->setData('foo',5);
52
        $event->publish();
53
    }
54
55
    public function testMetadata()
56
    {
57
        $callback = function($data) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
58
            return array() === $data['metadata']['bar'];
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
59
        };
60
        $handler = $this->setupMockHandlerWithValidationCallback($callback);
61
62
        $event = new Event(array($handler));
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
63
        $event->setMetadata('bar',array());
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
64
        $event->publish();
65
    }
66
67
    public function testPublish()
68
    {
69
        $handler = $this->setupMockHandler();
70
71
        $event = new Event(array($handler));
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
72
        $this->assertTrue($event->publish());
73
    }
74
75
    public function testPublishFalseNoHandler()
76
    {
77
        $event = new Event();
78
        $this->assertFalse($event->publish());
79
    }
80
81
    public function testMultipleHandlers()
82
    {
83
        $handlers = array(
0 ignored issues
show
Coding Style introduced by
Short array syntax must be used to define arrays
Loading history...
84
            $this->setupMockHandler(),
85
            $this->setupMockHandler(),
86
        );
87
88
        $event = new Event($handlers);
89
        $this->assertTrue($event->publish());
90
    }
91
}
92