1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SfCod\SocketIoBundle\Tests; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use SfCod\SocketIoBundle\Events\EventInterface; |
7
|
|
|
use SfCod\SocketIoBundle\Events\EventPublisherInterface; |
8
|
|
|
use SfCod\SocketIoBundle\Events\EventSubscriberInterface; |
9
|
|
|
use SfCod\SocketIoBundle\Service\Broadcast; |
10
|
|
|
use SfCod\SocketIoBundle\Tests\Data\LoadTrait; |
11
|
|
|
use SfCod\SocketIoBundle\Tests\Data\MarkAsReadSubscriber; |
12
|
|
|
use Symfony\Component\Process\Process; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class BroadcastTest. |
16
|
|
|
* |
17
|
|
|
* @author Virchenko Maksim <[email protected]> |
18
|
|
|
* |
19
|
|
|
* @package SfCod\SocketIoBundle\Tests |
20
|
|
|
*/ |
21
|
|
|
class BroadcastTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
use LoadTrait; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var Broadcast |
27
|
|
|
*/ |
28
|
|
|
private $broadcast; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Set up test. |
32
|
|
|
*/ |
33
|
|
|
protected function setUp() |
34
|
|
|
{ |
35
|
|
|
$this->configure(); |
36
|
|
|
|
37
|
|
|
$this->broadcast = $this->container->get(Broadcast::class); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Test on. |
42
|
|
|
* |
43
|
|
|
* @throws \Exception |
44
|
|
|
*/ |
45
|
|
|
public function testOn() |
46
|
|
|
{ |
47
|
|
|
$result = $this->broadcast->on(MarkAsReadSubscriber::name(), []); |
48
|
|
|
|
49
|
|
|
$this->assertInstanceOf(Process::class, $result); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Test process. |
54
|
|
|
*/ |
55
|
|
|
public function testProcess() |
56
|
|
|
{ |
57
|
|
|
$data = range(1, 10); |
58
|
|
|
|
59
|
|
|
$handler = $this->getMockBuilder([EventInterface::class, EventSubscriberInterface::class])->getMock(); |
60
|
|
|
$handler |
61
|
|
|
->expects($this->once()) |
62
|
|
|
->method('setPayload') |
63
|
|
|
->with($data); |
64
|
|
|
$handler |
65
|
|
|
->expects($this->once()) |
66
|
|
|
->method('handle'); |
67
|
|
|
|
68
|
|
|
$this->container->set(sprintf('socketio.%s', get_class($handler)), $handler); |
69
|
|
|
$this->broadcast->process(get_class($handler), $data); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
// /** |
73
|
|
|
// */ |
74
|
|
|
// public function testEmit() |
75
|
|
|
// { |
76
|
|
|
// $data = range(1, 10); |
77
|
|
|
// |
78
|
|
|
// $handler = $this->getMockBuilder([EventInterface::class, EventPublisherInterface::class])->getMock(); |
79
|
|
|
// $handler |
80
|
|
|
// ->expects($this->once()) |
81
|
|
|
// ->method('setPayload') |
82
|
|
|
// ->with($data); |
83
|
|
|
// $handler |
84
|
|
|
// ->expects($this->once()) |
85
|
|
|
// ->method('fire'); |
86
|
|
|
// |
87
|
|
|
// $this->container->set(sprintf('socketio.%s', get_class($handler)), $handler); |
88
|
|
|
// $this->broadcast->emit(get_class($handler), $data); |
89
|
|
|
// } |
90
|
|
|
|
91
|
|
|
// /** |
92
|
|
|
// */ |
93
|
|
|
// public function testChannels() |
94
|
|
|
// { |
95
|
|
|
// |
96
|
|
|
// } |
97
|
|
|
} |
98
|
|
|
|