Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
},
"require": {
"php": ">=5.3",
"react/event-loop": "~0.4.0|~0.3.0",
"react/promise": "~2.0|~1.0",
"clue/multicast-react": "~0.2.0"
"clue/multicast-react": "^1.0 || ^0.2",
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
"react/promise": "^2.0 || ^1.0"
},
"require-dev": {
"phpunit/phpunit": "^6.0 || ^5.7 || ^4.8.35"
Expand Down
5 changes: 3 additions & 2 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ public function search($searchTarget = 'ssdp:all', $mx = 2)
$socket->close();
});

$deferred = new Deferred(function () use ($socket, &$timer) {
$loop = $this->loop;
$deferred = new Deferred(function () use ($socket, &$timer, $loop) {
// canceling resulting promise cancels timer and closes socket
$timer->cancel();
$loop->cancelTimer($timer);
$socket->close();
throw new RuntimeException('Cancelled');
});
Expand Down
10 changes: 7 additions & 3 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,13 @@ public function testSearchCancel()
$socket = $this->getMockBuilder('React\Datagram\SocketInterface')->getMock();
$socket->expects($this->once())->method('send');

$timer = $this->getMockBuilder('React\EventLoop\Timer\TimerInterface')->getMock();
$loop->expects($this->once())->method('addTimer')->will($this->returnValue($timer));
// 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));

Expand All @@ -37,7 +42,6 @@ public function testSearchCancel()
}

$socket->expects($this->once())->method('close');
$timer->expects($this->once())->method('cancel');

$promise->cancel();

Expand Down