Skip to content

Commit 27f3ab9

Browse files
committed
Run tests on PHP 8.4 and update test environment
1 parent da2e173 commit 27f3ab9

File tree

3 files changed

+29
-19
lines changed

3 files changed

+29
-19
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ on:
77
jobs:
88
PHPUnit:
99
name: PHPUnit (PHP ${{ matrix.php }})
10-
runs-on: ubuntu-22.04
10+
runs-on: ubuntu-24.04
1111
strategy:
1212
matrix:
1313
php:
14+
- 8.4
1415
- 8.3
1516
- 8.2
1617
- 8.1
@@ -38,7 +39,7 @@ jobs:
3839

3940
PHPUnit-hhvm:
4041
name: PHPUnit (HHVM)
41-
runs-on: ubuntu-22.04
42+
runs-on: ubuntu-24.04
4243
continue-on-error: true
4344
steps:
4445
- uses: actions/checkout@v4

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
},
2323
"require": {
2424
"php": ">=5.3",
25-
"clue/multicast-react": "^1.0 || ^0.2",
25+
"clue/multicast-react": "^1.2 || ^0.2",
2626
"react/event-loop": "^1.2",
27-
"react/promise": "^2.0 || ^1.0"
27+
"react/promise": "^2.6.0"
2828
},
2929
"require-dev": {
3030
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36"

src/Client.php

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Client
2828
* @param ?LoopInterface $loop
2929
* @param ?MulticastFactory $multicast
3030
*/
31-
public function __construct(LoopInterface $loop = null, MulticastFactory $multicast = null)
31+
public function __construct(?LoopInterface $loop = null, ?MulticastFactory $multicast = null)
3232
{
3333
$this->loop = $loop ?: Loop::get();
3434
$this->multicast = $multicast ?: new MulticastFactory($this->loop);
@@ -46,29 +46,38 @@ public function search($searchTarget = 'ssdp:all', $mx = 2)
4646
$socket = $this->multicast->createSender();
4747
// TODO: The TTL for the IP packet SHOULD default to 2 and SHOULD be configurable.
4848

49-
$timer = $this->loop->addTimer($mx, function() use ($socket, &$deferred) {
50-
$deferred->resolve();
51-
$socket->close();
52-
});
53-
5449
$loop = $this->loop;
55-
$deferred = new Deferred(function () use ($socket, &$timer, $loop) {
50+
$timer = null;
51+
52+
$deferred = new Deferred(function () use (&$socket, &$timer, $loop) {
5653
// canceling resulting promise cancels timer and closes socket
57-
$loop->cancelTimer($timer);
54+
if ($timer !== null) {
55+
$loop->cancelTimer($timer);
56+
}
5857
$socket->close();
5958
throw new RuntimeException('Cancelled');
6059
});
6160

62-
$that = $this;
63-
$socket->on('message', function ($data, $remote) use ($deferred, $that) {
64-
$message = $that->parseMessage($data, $remote);
61+
$timer = $this->loop->addTimer($mx, function() use ($socket, $deferred) {
62+
$deferred->resolve();
63+
$socket->close();
64+
});
6565

66-
$deferred->progress($message);
67-
});
66+
$that = $this;
67+
$socket->on('message', function ($data, $remote) use ($deferred, $that) {
68+
$message = $that->parseMessage($data, $remote);
69+
70+
// React Promise v3+ doesn't support progress(), use notify() instead
71+
if (method_exists($deferred, 'progress')) {
72+
$deferred->progress($message);
73+
} else {
74+
$deferred->notify($message);
75+
}
76+
});
6877

69-
$socket->send($data, self::ADDRESS);
78+
$socket->send($data, self::ADDRESS);
7079

71-
return $deferred->promise();
80+
return $deferred->promise();
7281
}
7382

7483
/** @internal */

0 commit comments

Comments
 (0)