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]); |
|
|
|
|
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
|
|
|
|
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.