|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SfCod\SocketIoBundle\Tests\Service; |
|
4
|
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
|
6
|
|
|
use Psr\Log\LoggerInterface; |
|
7
|
|
|
use SfCod\SocketIoBundle\Events\EventInterface; |
|
8
|
|
|
use SfCod\SocketIoBundle\Events\EventPublisherInterface; |
|
9
|
|
|
use SfCod\SocketIoBundle\Events\EventSubscriberInterface; |
|
10
|
|
|
use SfCod\SocketIoBundle\Service\Broadcast; |
|
11
|
|
|
use SfCod\SocketIoBundle\Service\EventManager; |
|
12
|
|
|
use SfCod\SocketIoBundle\Service\RedisDriver; |
|
13
|
|
|
use SfCod\SocketIoBundle\Tests\Data\LoadTrait; |
|
14
|
|
|
use SfCod\SocketIoBundle\Tests\Data\MarkAsReadSubscriber; |
|
15
|
|
|
use Symfony\Component\Process\Process; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Class BroadcastTest. |
|
19
|
|
|
* |
|
20
|
|
|
* @author Virchenko Maksim <[email protected]> |
|
21
|
|
|
* |
|
22
|
|
|
* @package SfCod\SocketIoBundle\Tests |
|
23
|
|
|
*/ |
|
24
|
|
|
class BroadcastTest extends TestCase |
|
25
|
|
|
{ |
|
26
|
|
|
use LoadTrait; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @var Broadcast |
|
30
|
|
|
*/ |
|
31
|
|
|
private $broadcast; |
|
32
|
|
|
private $eventManagerMock; |
|
33
|
|
|
private $processMock; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Set up test. |
|
37
|
|
|
*/ |
|
38
|
|
|
protected function setUp() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->configure(); |
|
41
|
|
|
$redisDriverMock = $this->createMock(RedisDriver::class); |
|
42
|
|
|
$eventManagerMock = $this->createMock(EventManager::class); |
|
43
|
|
|
$this->eventManagerMock = $eventManagerMock; |
|
44
|
|
|
$loggerMock = $this->createMock(LoggerInterface::class); |
|
45
|
|
|
$processMock = $this->createMock(\SfCod\SocketIoBundle\Service\Process::class); |
|
46
|
|
|
$this->processMock = $processMock; |
|
47
|
|
|
|
|
48
|
|
|
$this->broadcast = new Broadcast($redisDriverMock, $eventManagerMock, $loggerMock, $processMock); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Test on. |
|
53
|
|
|
* |
|
54
|
|
|
* @throws \Exception |
|
55
|
|
|
*/ |
|
56
|
|
|
public function testOn() |
|
57
|
|
|
{ |
|
58
|
|
|
$this->processMock->method('run')->willReturn(new Process([])); |
|
59
|
|
|
$result = $this->broadcast->on(MarkAsReadSubscriber::name(), []); |
|
60
|
|
|
|
|
61
|
|
|
self::assertInstanceOf(Process::class, $result); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Test process. |
|
66
|
|
|
*/ |
|
67
|
|
|
public function testProcess() |
|
68
|
|
|
{ |
|
69
|
|
|
$data = range(1, 10); |
|
70
|
|
|
|
|
71
|
|
|
$handler = $this->getMockBuilder([EventInterface::class, EventSubscriberInterface::class])->getMock(); |
|
72
|
|
|
$handler |
|
73
|
|
|
->expects(self::once()) |
|
74
|
|
|
->method('setPayload') |
|
75
|
|
|
->with($data); |
|
76
|
|
|
$handler |
|
77
|
|
|
->expects(self::once()) |
|
78
|
|
|
->method('handle'); |
|
79
|
|
|
|
|
80
|
|
|
$this->eventManagerMock->method('resolve')->willReturn($handler); |
|
81
|
|
|
$this->broadcast->process(get_class($handler), $data); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
*/ |
|
86
|
|
|
public function testEmit() |
|
87
|
|
|
{ |
|
88
|
|
|
$data = range(1, 10); |
|
89
|
|
|
|
|
90
|
|
|
$handler = $this->getMockBuilder([EventInterface::class, EventPublisherInterface::class])->getMock(); |
|
91
|
|
|
$handler |
|
92
|
|
|
->expects(self::once()) |
|
93
|
|
|
->method('setPayload') |
|
94
|
|
|
->with($data); |
|
95
|
|
|
$handler |
|
96
|
|
|
->expects(self::once()) |
|
97
|
|
|
->method('fire'); |
|
98
|
|
|
$this->eventManagerMock->method('resolve')->willReturn($handler); |
|
99
|
|
|
$this->broadcast->emit(get_class($handler), $data); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
// /** |
|
103
|
|
|
// */ |
|
104
|
|
|
// public function testChannels() |
|
105
|
|
|
// { |
|
106
|
|
|
// |
|
107
|
|
|
// } |
|
108
|
|
|
} |
|
109
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: