|
| 1 | +<?php |
| 2 | + |
| 3 | +use Clue\React\Ssdp\Client; |
| 4 | +use React\EventLoop\Factory; |
| 5 | + |
| 6 | +class ClientTest extends TestCase |
| 7 | +{ |
| 8 | + public function testCtor() |
| 9 | + { |
| 10 | + $loop = $this->getMock('React\EventLoop\LoopInterface'); |
| 11 | + new Client($loop); |
| 12 | + } |
| 13 | + |
| 14 | + public function testSearchCancel() |
| 15 | + { |
| 16 | + $loop = $this->getMock('React\EventLoop\LoopInterface'); |
| 17 | + $multicast = $this->getMockBuilder('Clue\React\Multicast\Factory')->disableOriginalConstructor()->getMock(); |
| 18 | + $client = new Client($loop, $multicast); |
| 19 | + |
| 20 | + $socket = $this->getMock('React\Datagram\SocketInterface'); |
| 21 | + $socket->expects($this->once())->method('send'); |
| 22 | + |
| 23 | + $timer = $this->getMock('React\EventLoop\Timer\TimerInterface'); |
| 24 | + $loop->expects($this->once())->method('addTimer')->will($this->returnValue($timer)); |
| 25 | + |
| 26 | + $multicast->expects($this->once())->method('createSender')->will($this->returnValue($socket)); |
| 27 | + |
| 28 | + $promise = $client->search(); |
| 29 | + |
| 30 | + $this->assertInstanceOf('React\Promise\PromiseInterface', $promise); |
| 31 | + |
| 32 | + if (!($promise instanceof React\Promise\CancellablePromiseInterface)) { |
| 33 | + $this->markTestSkipped(); |
| 34 | + } |
| 35 | + |
| 36 | + $socket->expects($this->once())->method('close'); |
| 37 | + $timer->expects($this->once())->method('cancel'); |
| 38 | + |
| 39 | + $promise->cancel(); |
| 40 | + |
| 41 | + $promise->then(null, $this->expectCallableOnce()); |
| 42 | + } |
| 43 | + |
| 44 | + public function testSearchTimeout() |
| 45 | + { |
| 46 | + $loop = Factory::create(); |
| 47 | + $client = new Client($loop); |
| 48 | + |
| 49 | + $promise = $client->search('ssdp:all', 0.01); |
| 50 | + |
| 51 | + $loop->run(); |
| 52 | + |
| 53 | + $promise->then($this->expectCallableOnce(), $this->expectCallableNever(), $this->expectCallableNever()); |
| 54 | + } |
| 55 | +} |
0 commit comments