1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace IrishDan\NotificationBundle\Formatter; |
4
|
|
|
|
5
|
|
|
use IrishDan\NotificationBundle\Message\MessageInterface; |
6
|
|
|
use IrishDan\NotificationBundle\Test\Formatter\FormatterTestCase; |
7
|
|
|
|
8
|
|
View Code Duplication |
class PusherDataFormatterTest extends FormatterTestCase |
|
|
|
|
9
|
|
|
{ |
10
|
|
|
public function setUp() |
11
|
|
|
{ |
12
|
|
|
parent::setUp(); |
13
|
|
|
|
14
|
|
|
$pusherManager = $this->getService('notification.pusher_manager'); |
15
|
|
|
$this->formatter = new PusherDataFormatter($pusherManager); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
public function testFormat() |
19
|
|
|
{ |
20
|
|
|
$message = $this->formatter->format($this->notification); |
21
|
|
|
|
22
|
|
|
$this->assertValidDispatchData($message); |
23
|
|
|
$this->assertMessageDataStructure($message); |
24
|
|
|
|
25
|
|
|
$this->assertBasicMessageData($message); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testFormatWithTwig() |
29
|
|
|
{ |
30
|
|
|
$this->setTwig(); |
31
|
|
|
$message = $this->formatter->format($this->notification); |
32
|
|
|
|
33
|
|
|
$this->assertValidDispatchData($message); |
34
|
|
|
$this->assertMessageDataStructure($message); |
35
|
|
|
|
36
|
|
|
$messageData = $message->getMessageData(); |
37
|
|
|
$this->assertEquals('New member', $messageData['title']); |
38
|
|
|
$this->assertEquals('Pusher notification message for jimBob', $messageData['body']); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function assertValidDispatchData(MessageInterface $message) |
42
|
|
|
{ |
43
|
|
|
$this->assertEquals('pusher', $message->getChannel()); |
44
|
|
|
|
45
|
|
|
$dispatchData = $message->getDispatchData(); |
46
|
|
|
$this->assertArrayHasKey('channel', $dispatchData); |
47
|
|
|
|
48
|
|
|
$this->assertEquals('pusher_test_1', $dispatchData['channel']); |
49
|
|
|
$this->assertEquals('pusher_event', $dispatchData['event']); |
50
|
|
|
} |
51
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.