1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sonata package. |
5
|
|
|
* |
6
|
|
|
* (c) Thomas Rabaix <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Sonata\NotificationBundle\Tests\Consumer; |
13
|
|
|
|
14
|
|
|
use Sonata\NotificationBundle\Consumer\ConsumerEvent; |
15
|
|
|
use Sonata\NotificationBundle\Consumer\LoggerConsumer; |
16
|
|
|
use Sonata\NotificationBundle\Tests\Entity\Message; |
17
|
|
|
|
18
|
|
|
class LoggerConsumerTest extends \PHPUnit_Framework_TestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @dataProvider calledTypeProvider |
22
|
|
|
* |
23
|
|
|
* @param $type |
24
|
|
|
* @param $calledType |
25
|
|
|
*/ |
26
|
|
|
public function testProcess($type, $calledType) |
27
|
|
|
{ |
28
|
|
|
$logger = $this->getMock('Psr\Log\LoggerInterface'); |
29
|
|
|
$logger->expects($this->once())->method($calledType); |
30
|
|
|
|
31
|
|
|
$message = new Message(); |
32
|
|
|
$message->setBody(array( |
33
|
|
|
'level' => $type, |
34
|
|
|
'message' => 'Alert - Area 52 get compromised!!', |
35
|
|
|
)); |
36
|
|
|
|
37
|
|
|
$event = new ConsumerEvent($message); |
38
|
|
|
|
39
|
|
|
$consumer = new LoggerConsumer($logger); |
40
|
|
|
$consumer->process($event); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return array[] |
45
|
|
|
*/ |
46
|
|
|
public function calledTypeProvider() |
47
|
|
|
{ |
48
|
|
|
return array( |
49
|
|
|
array('emerg', 'emergency'), |
50
|
|
|
array('alert', 'alert'), |
51
|
|
|
array('crit', 'critical'), |
52
|
|
|
array('err', 'error'), |
53
|
|
|
array('warn', 'warning'), |
54
|
|
|
array('notice', 'notice'), |
55
|
|
|
array('info', 'info'), |
56
|
|
|
array('debug', 'debug'), |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @expectedException \Sonata\NotificationBundle\Exception\InvalidParameterException |
62
|
|
|
*/ |
63
|
|
|
public function testInvalidType() |
64
|
|
|
{ |
65
|
|
|
$logger = $this->getMock('Psr\Log\LoggerInterface'); |
66
|
|
|
|
67
|
|
|
$message = new Message(); |
68
|
|
|
$message->setBody(array( |
69
|
|
|
'level' => 'ERROR', |
70
|
|
|
'message' => 'Alert - Area 52 get compromised!!', |
71
|
|
|
)); |
72
|
|
|
|
73
|
|
|
$event = new ConsumerEvent($message); |
74
|
|
|
|
75
|
|
|
$consumer = new LoggerConsumer($logger); |
76
|
|
|
$consumer->process($event); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|