Skip to content

Commit 3c03e64

Browse files
committed
Forward compatibility with stable EventLoop 1.0 and 0.5
1 parent af99a21 commit 3c03e64

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
},
1616
"require": {
1717
"php": ">=5.3",
18-
"react/event-loop": "~0.4.0|~0.3.0",
19-
"react/promise": "~2.0|~1.0",
20-
"clue/multicast-react": "~0.2.0"
18+
"clue/multicast-react": "^1.0 || ^0.2",
19+
"react/event-loop": "^1.0 || ^0.5 || ^0.4 || ^0.3",
20+
"react/promise": "^2.0 || ^1.0"
2121
},
2222
"require-dev": {
2323
"phpunit/phpunit": "^6.0 || ^5.7 || ^4.8.35"

src/Client.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ public function search($searchTarget = 'ssdp:all', $mx = 2)
4040
$socket->close();
4141
});
4242

43-
$deferred = new Deferred(function () use ($socket, &$timer) {
43+
$loop = $this->loop;
44+
$deferred = new Deferred(function () use ($socket, &$timer, $loop) {
4445
// canceling resulting promise cancels timer and closes socket
45-
$timer->cancel();
46+
$loop->cancelTimer($timer);
4647
$socket->close();
4748
throw new RuntimeException('Cancelled');
4849
});

tests/ClientTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,13 @@ public function testSearchCancel()
2323
$socket = $this->getMockBuilder('React\Datagram\SocketInterface')->getMock();
2424
$socket->expects($this->once())->method('send');
2525

26-
$timer = $this->getMockBuilder('React\EventLoop\Timer\TimerInterface')->getMock();
27-
$loop->expects($this->once())->method('addTimer')->will($this->returnValue($timer));
26+
// prefer newer EventLoop 1.0/0.5+ TimerInterface or fall back to legacy namespace
27+
$timer = $this->getMockBuilder(
28+
interface_exists('React\EventLoop\TimerInterface') ? 'React\EventLoop\TimerInterface' : 'React\EventLoop\Timer\TimerInterface'
29+
)->getMock();
30+
31+
$loop->expects($this->once())->method('addTimer')->willReturn($timer);
32+
$loop->expects($this->once())->method('cancelTimer')->with($timer);
2833

2934
$multicast->expects($this->once())->method('createSender')->will($this->returnValue($socket));
3035

@@ -37,7 +42,6 @@ public function testSearchCancel()
3742
}
3843

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

4246
$promise->cancel();
4347

0 commit comments

Comments
 (0)