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

EventChannelTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 56
rs 10
c 2
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 12 1
A testDispatch() 0 12 1
A testDispatchWithWrongChannelKey() 0 12 1
A testChannelDataIsPassedToAdapter() 0 10 1
1
<?php
2
3
namespace IrishDan\NotificationBundle\Test\Channel;
4
5
use IrishDan\NotificationBundle\Channel\EventChannel;
6
use IrishDan\NotificationBundle\Exception\MessageDispatchException;
7
use IrishDan\NotificationBundle\Test\Adapter\DummyAdapter;
8
use IrishDan\NotificationBundle\Test\NotificationTestCase;
9
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
10
11
class EventChannelTest extends NotificationTestCase
12
{
13
    protected $eventChannel;
14
    protected $eventDispatcher;
15
    protected $notification;
16
17
    public function setUp()
18
    {
19
        parent::setUp();
20
21
        $this->notification = $this->getNotificationWithUser();
22
23
        $this->eventDispatcher = $this->getMockBuilder(EventDispatcherInterface::class)
24
            ->disableOriginalConstructor()
25
            ->getMock();
26
27
        $this->eventChannel = new EventChannel($this->eventDispatcher);
28
    }
29
30
    public function testDispatch()
31
    {
32
        $this->eventDispatcher->expects($this->once())->method('dispatch');
33
34
        $adapter = $this->getMockAdapter(false, true);
35
        $this->eventChannel->setAdapters('default', $adapter, []);
36
37
        $message = $this->getTestMessage();
38
        $message->setChannel('default');
39
40
        $this->eventChannel->dispatch($message);
41
    }
42
43
    public function testDispatchWithWrongChannelKey()
44
    {
45
        $dispatcher = $this->getMockAdapter();
46
        $this->eventChannel->setAdapters('default', $dispatcher, []);
47
48
        $message = $this->getTestMessage();
49
        $message->setChannel('not-default');
50
51
        $this->setExpectedException(MessageDispatchException::class);
52
53
        $this->eventChannel->dispatch($message);
54
    }
55
56
    public function testChannelDataIsPassedToAdapter()
57
    {
58
        $adapter = new DummyAdapter('test_channel', ['a' => 1]);
0 ignored issues
show
Unused Code introduced by
The call to DummyAdapter::__construct() has too many arguments starting with 'test_channel'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
59
60
        $this->eventChannel->setAdapters('test_channel', $adapter, ['a' => 1]);
61
62
        $this->assertEquals('test_channel', $adapter->getChannelName());
63
        $configuration = ['a' => 1];
64
        $this->assertEquals($configuration, $adapter->getConfiguration());
65
    }
66
}
67