|
1 | 1 | <?php
|
2 | 2 |
|
| 3 | +namespace Clue\Tests\React\Mdns; |
| 4 | + |
3 | 5 | use Clue\React\Mdns\MulticastExecutor;
|
4 | 6 | use Clue\React\Mdns\Factory;
|
5 | 7 | use React\Dns\Query\Query;
|
6 | 8 |
|
7 | 9 | class MulticastExecutorTest extends TestCase
|
8 | 10 | {
|
9 |
| - private $nameserver; |
10 |
| - private $loop; |
11 |
| - private $parser; |
12 |
| - private $dumper; |
13 |
| - private $sockets; |
14 |
| - |
15 |
| - public function setUp() |
16 |
| - { |
17 |
| - $this->nameserver = Factory::DNS; |
18 |
| - $this->loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); |
19 |
| - $this->parser = $this->getMockBuilder('React\Dns\Protocol\Parser')->getMock(); |
20 |
| - $this->dumper = $this->getMockBuilder('React\Dns\Protocol\BinaryDumper')->getMock(); |
21 |
| - $this->sockets = $this->getMockBuilder('Clue\React\Multicast\Factory')->disableOriginalConstructor()->getMock(); |
22 |
| - } |
23 |
| - |
24 | 11 | public function testQueryWillReturnPromise()
|
25 | 12 | {
|
26 |
| - $executor = new MulticastExecutor($this->loop, $this->parser, $this->dumper, 5, $this->sockets); |
| 13 | + $nameserver = Factory::DNS; |
| 14 | + $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); |
| 15 | + $parser = $this->getMockBuilder('React\Dns\Protocol\Parser')->getMock(); |
| 16 | + $dumper = $this->getMockBuilder('React\Dns\Protocol\BinaryDumper')->getMock(); |
| 17 | + $sockets = $this->getMockBuilder('Clue\React\Multicast\Factory')->disableOriginalConstructor()->getMock(); |
| 18 | + |
| 19 | + $executor = new MulticastExecutor($loop, $parser, $dumper, 5, $sockets); |
27 | 20 |
|
28 | 21 | $socket = $this->getMockBuilder('React\Datagram\SocketInterface')->getMock();
|
29 | 22 |
|
30 |
| - $this->dumper->expects($this->once())->method('toBinary')->will($this->returnValue('message')); |
31 |
| - $this->sockets->expects($this->once())->method('createSender')->will($this->returnValue($socket)); |
| 23 | + $dumper->expects($this->once())->method('toBinary')->will($this->returnValue('message')); |
| 24 | + $sockets->expects($this->once())->method('createSender')->will($this->returnValue($socket)); |
32 | 25 |
|
33 |
| - $socket->expects($this->once())->method('send')->with($this->equalTo('message'), $this->equalTo($this->nameserver)); |
| 26 | + $socket->expects($this->once())->method('send')->with($this->equalTo('message'), $this->equalTo($nameserver)); |
34 | 27 |
|
35 | 28 | $query = new Query('name', 'type', 'class', time());
|
36 | 29 |
|
37 |
| - $ret = $executor->query($this->nameserver, $query); |
| 30 | + $ret = $executor->query($nameserver, $query); |
38 | 31 | $this->assertInstanceOf('React\Promise\PromiseInterface', $ret);
|
39 | 32 | }
|
40 | 33 |
|
41 | 34 | public function testCancellingPromiseWillCloseSocketAndReject()
|
42 | 35 | {
|
43 |
| - $executor = new MulticastExecutor($this->loop, $this->parser, $this->dumper, 5, $this->sockets); |
| 36 | + $nameserver = Factory::DNS; |
| 37 | + $loop = $this->getMockBuilder('React\EventLoop\LoopInterface')->getMock(); |
| 38 | + $parser = $this->getMockBuilder('React\Dns\Protocol\Parser')->getMock(); |
| 39 | + $dumper = $this->getMockBuilder('React\Dns\Protocol\BinaryDumper')->getMock(); |
| 40 | + $sockets = $this->getMockBuilder('Clue\React\Multicast\Factory')->disableOriginalConstructor()->getMock(); |
| 41 | + |
| 42 | + $executor = new MulticastExecutor($loop, $parser, $dumper, 5, $sockets); |
44 | 43 |
|
45 | 44 | $socket = $this->getMockBuilder('React\Datagram\SocketInterface')->getMock();
|
46 | 45 | $socket->expects($this->once())->method('close');
|
47 |
| - $socket->expects($this->once())->method('send')->with($this->equalTo('message'), $this->equalTo($this->nameserver)); |
48 |
| - $this->sockets->expects($this->once())->method('createSender')->will($this->returnValue($socket)); |
| 46 | + $socket->expects($this->once())->method('send')->with($this->equalTo('message'), $this->equalTo($nameserver)); |
| 47 | + $sockets->expects($this->once())->method('createSender')->will($this->returnValue($socket)); |
49 | 48 |
|
50 | 49 | // prefer newer EventLoop 1.0/0.5+ TimerInterface or fall back to legacy namespace
|
51 | 50 | $timer = $this->getMockBuilder(
|
52 | 51 | interface_exists('React\EventLoop\TimerInterface') ? 'React\EventLoop\TimerInterface' : 'React\EventLoop\Timer\TimerInterface'
|
53 | 52 | )->getMock();
|
54 | 53 |
|
55 |
| - $this->loop->expects($this->once())->method('addTimer')->willReturn($timer); |
56 |
| - $this->loop->expects($this->once())->method('cancelTimer')->with($timer); |
| 54 | + $loop->expects($this->once())->method('addTimer')->willReturn($timer); |
| 55 | + $loop->expects($this->once())->method('cancelTimer')->with($timer); |
57 | 56 |
|
58 |
| - $this->dumper->expects($this->once())->method('toBinary')->will($this->returnValue('message')); |
| 57 | + $dumper->expects($this->once())->method('toBinary')->will($this->returnValue('message')); |
59 | 58 |
|
60 | 59 | $query = new Query('name', 'type', 'class', time());
|
61 | 60 |
|
62 |
| - $ret = $executor->query($this->nameserver, $query); |
| 61 | + $ret = $executor->query($nameserver, $query); |
63 | 62 | $this->assertInstanceOf('React\Promise\CancellablePromiseInterface', $ret);
|
64 | 63 |
|
65 | 64 | $ret->cancel();
|
|
0 commit comments