-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathClientTest.php
More file actions
102 lines (77 loc) · 3.36 KB
/
ClientTest.php
File metadata and controls
102 lines (77 loc) · 3.36 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
namespace Clue\Tests\React\Ssdp;
use Clue\React\Ssdp\Client;
use React\EventLoop\Loop;
class ClientTest extends TestCase
{
public function testConstructWithoutLoopAssignsLoopAutomatically()
{
$client = new Client();
$ref = new \ReflectionProperty($client, 'loop');
$ref->setAccessible(true);
$loop = $ref->getValue($client);
$this->assertInstanceOf('React\EventLoop\LoopInterface', $loop);
}
/**
* @doesNotPerformAssertions
*/
public function testCtor()
{
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
new Client($loop);
}
public function testSearchCancel()
{
$loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock();
$multicast = $this->getMockBuilder('Clue\React\Multicast\Factory')->disableOriginalConstructor()->getMock();
$client = new Client($loop, $multicast);
$socket = $this->getMockBuilder('React\Datagram\SocketInterface')->getMock();
$socket->expects($this->once())->method('send');
// prefer newer EventLoop 1.0/0.5+ TimerInterface or fall back to legacy namespace
$timer = $this->getMockBuilder(
interface_exists('React\EventLoop\TimerInterface') ? 'React\EventLoop\TimerInterface' : 'React\EventLoop\Timer\TimerInterface'
)->getMock();
$loop->expects($this->once())->method('addTimer')->willReturn($timer);
$loop->expects($this->once())->method('cancelTimer')->with($timer);
$multicast->expects($this->once())->method('createSender')->will($this->returnValue($socket));
$promise = $client->search();
$this->assertInstanceOf('React\Promise\PromiseInterface', $promise);
if (!($promise instanceof \React\Promise\CancellablePromiseInterface)) {
$this->markTestSkipped();
}
$socket->expects($this->once())->method('close');
$promise->cancel();
$promise->then(null, $this->expectCallableOnce());
}
public function testSearchTimeout()
{
$client = new Client();
$promise = $client->search('ssdp:all', 0.01);
Loop::run();
$promise->then($this->expectCallableOnce(), $this->expectCallableNever(), $this->expectCallableNever());
}
public function testCtorThrowsForInvalidLoop()
{
if (method_exists($this, 'expectException')) {
// PHPUnit 5.2+
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');
} else {
// legacy PHPUnit
$this->setExpectedException('InvalidArgumentException', 'Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');
}
new Client('loop');
}
public function testCtorThrowsForInvalidMulticast()
{
if (method_exists($this, 'expectException')) {
// PHPUnit 5.2+
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage('Argument #2 ($multicast) expected null|Clue\React\Multicast\Factory');
} else {
// legacy PHPUnit
$this->setExpectedException('InvalidArgumentException', 'Argument #2 ($multicast) expected null|Clue\React\Multicast\Factory');
}
new Client(null, 'multicast');
}
}