forked from clue/reactphp-multicast
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionalTest.php
More file actions
77 lines (59 loc) · 2.15 KB
/
FunctionalTest.php
File metadata and controls
77 lines (59 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace Clue\Tests\React\Multicast;
use Clue\React\Multicast\Factory;
class FunctionalTest extends TestCase
{
private $loop;
private $factory;
private $address = '224.224.244.244:2244';
/**
* @before
*/
public function setUpMocks()
{
$this->loop = \React\EventLoop\Factory::create();
$this->factory = new Factory($this->loop);
}
/** @doesNotPerformAssertions */
public function testSenderWithNoReceiver()
{
$sender = $this->factory->createSender();
// send a single message and do not receive anything
$sender->pause();
$sender->send('hello?', $this->address);
$this->loop->run();
}
public function testMultipleReceivers()
{
try {
$receiver1 = $this->factory->createReceiver($this->address);
} catch (\BadMethodCallException $e) {
$this->markTestSkipped('No multicast support');
}
$receiver2 = $this->factory->createReceiver($this->address);
$sender = $this->factory->createSender();
// expect both receivers receive a single message
$receiver1->on('message', $this->expectCallableOnce());
$receiver2->on('message', $this->expectCallableOnce());
// stop waiting for further messages once the first message arrived
$receiver1->on('message', array($receiver1, 'pause'));
$receiver2->on('message', array($receiver2, 'pause'));
// send a single message and do not receive anything
$sender->pause();
$sender->send('message', $this->address);
$this->loop->run();
}
public function testConstructWithoutLoopAssignsLoopAutomatically()
{
$factory = new Factory();
$ref = new \ReflectionProperty($factory, 'loop');
$ref->setAccessible(true);
$loop = $ref->getValue($factory);
$this->assertInstanceOf('React\EventLoop\LoopInterface', $loop);
}
public function testCtorThrowsForInvalidLoop()
{
$this->setExpectedException('InvalidArgumentException', 'Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');
new Factory('loop');
}
}