Completed
Push — master ( db8ff8...4137d9 )
by dan
01:59
created

DirectChannelTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 29.41 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 20
loc 68
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getChannel() 0 11 1
A setUp() 0 6 1
A testFormat() 0 9 1
A testDispatch() 11 11 1
A testFormatAndDispatch() 9 9 1
A testChannelDataIsPassedToAdapter() 0 12 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\Channel;
4
5
use IrishDan\NotificationBundle\Channel\DirectChannel;
6
use IrishDan\NotificationBundle\Test\Adapter\DummyAdapter;
7
use IrishDan\NotificationBundle\Test\NotificationTestCase;
8
9
class DirectChannelTest extends NotificationTestCase
10
{
11
    protected $notification;
12
13
    public function getChannel($adapter)
14
    {
15
        $config = [
16
            'key' => '123abc',
17
            'id' => 123456,
18
        ];
19
20
        $channelName = 'test_channel';
21
22
        return new DirectChannel($config, $channelName, $adapter);
23
    }
24
25
    public function setUp()
26
    {
27
        parent::setUp();
28
29
        $this->notification = $this->getNotificationWithUser();
30
    }
31
32
    public function testFormat()
33
    {
34
        $adapter = $this->getMockAdapter(true);
35
        $channel = $this->getChannel($adapter);
36
37
        $message = $channel->format($this->notification);
38
39
        $this->assertInstanceOf('IrishDan\NotificationBundle\Message\MessageInterface', $message);
40
    }
41
42 View Code Duplication
    public function testDispatch()
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...
43
    {
44
        $message = $this->getTestMessage();
45
46
        $adapter = $this->getMockAdapter(false, true);
47
        $channel = $this->getChannel($adapter);
48
49
        $dispatched = $channel->dispatch($message);
50
51
        $this->assertTrue($dispatched);
52
    }
53
54 View Code Duplication
    public function testFormatAndDispatch()
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...
55
    {
56
        $adapter = $this->getMockAdapter(true, true);
57
        $channel = $this->getChannel($adapter);
58
59
        $dispatched = $channel->formatAndDispatch($this->notification);
60
61
        $this->assertTrue($dispatched);
62
    }
63
64
    public function testChannelDataIsPassedToAdapter()
65
    {
66
        $adapter = new DummyAdapter();
67
        $this->getChannel($adapter);
68
69
        $this->assertEquals('test_channel', $adapter->getChannelName());
70
        $configuration = [
71
            'key' => '123abc',
72
            'id' => 123456,
73
        ];
74
        $this->assertEquals($configuration, $adapter->getConfiguration());
75
    }
76
}
77