DatabaseMessageAdapterTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 66.07 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 37
loc 56
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 11 1
A testFormat() 9 9 1
A testFormatWithTwig() 18 18 1
A assertValidDispatchData() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace IrishDan\NotificationBundle\Test\Adapter;
4
5
use IrishDan\NotificationBundle\Adapter\DatabaseMessageAdapter;
6
use IrishDan\NotificationBundle\DatabaseNotificationManager;
7
use IrishDan\NotificationBundle\Message\MessageInterface;
8
9
10
class DatabaseMessageAdapterTest extends AdapterTestCase
11
{
12
    protected $databaseManager;
13
14
    public function setUp()
15
    {
16
        parent::setUp();
17
        // Mock the DB manager
18
        $this->databaseManager = $this->getMockBuilder(DatabaseNotificationManager::class)
19
            ->disableOriginalConstructor()
20
            ->getMock();
21
22
        $this->adapter = new DatabaseMessageAdapter($this->databaseManager);
23
        $this->adapter->setChannelName('database');
24
    }
25
26 View Code Duplication
    public function testFormat()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
27
    {
28
        $message = $this->adapter->format($this->notification);
29
30
        $this->assertValidDispatchData($message);
31
        $this->assertMessageDataStructure($message);
32
33
        $this->assertBasicMessageData($message);
34
    }
35
36 View Code Duplication
    public function testFormatWithTwig()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
37
    {
38
        $this->setTwig();
39
        $message = $this->adapter->format($this->notification);
40
41
        $this->assertValidDispatchData($message);
42
        $this->assertMessageDataStructure($message);
43
44
        $messageData = $message->getMessageData();
45
        $this->assertEquals('New member', $messageData['title']);
46
        $message = 'Hello jimBob
47
Notification message for jimBob
48
Sincerely yours,
49
NotificationBundle
50
Sent via database channel.';
51
52
        $this->assertEquals($message, $messageData['body']);
53
    }
54
55 View Code Duplication
    public function assertValidDispatchData(MessageInterface $message)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
56
    {
57
        $this->assertEquals('database', $message->getChannel());
58
59
        $dispatchData = $message->getDispatchData();
60
        $this->assertEquals(1, $dispatchData['id']);
61
        $this->assertArrayHasKey('uuid', $dispatchData);
62
        $this->assertArrayHasKey('notifiable', $dispatchData);
63
        $this->assertArrayHasKey('type', $dispatchData);
64
    }
65
}