Skip to content

Commit 692105b

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

File tree

4 files changed

+54
-20
lines changed

4 files changed

+54
-20
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.x-dev#f1bd5df0309b9f8b3486b09bf37aedfb042addb6",
2626
"react/event-loop": "^1.2",
27-
"react/promise": "^2.0 || ^1.0"
27+
"react/promise": "^3.2 || ^2.7 || ^1.2.1"
2828
},
2929
"require-dev": {
3030
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36"

src/Client.php

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,14 @@ 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($loop = null, $multicast = null)
3232
{
33+
if ($loop !== null && !$loop instanceof LoopInterface) { // manual type check to support legacy PHP < 7.1
34+
throw new \InvalidArgumentException('Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');
35+
}
36+
if ($multicast !== null && !$multicast instanceof MulticastFactory) { // manual type check to support legacy PHP < 7.1
37+
throw new \InvalidArgumentException('Argument #2 ($multicast) expected null|Clue\React\Multicast\Factory');
38+
}
3339
$this->loop = $loop ?: Loop::get();
3440
$this->multicast = $multicast ?: new MulticastFactory($this->loop);
3541
}
@@ -46,29 +52,28 @@ public function search($searchTarget = 'ssdp:all', $mx = 2)
4652
$socket = $this->multicast->createSender();
4753
// TODO: The TTL for the IP packet SHOULD default to 2 and SHOULD be configurable.
4854

49-
$timer = $this->loop->addTimer($mx, function() use ($socket, &$deferred) {
50-
$deferred->resolve();
51-
$socket->close();
52-
});
53-
54-
$loop = $this->loop;
55-
$deferred = new Deferred(function () use ($socket, &$timer, $loop) {
55+
$messages = [];
56+
$deferred = new Deferred(function () use ($socket, &$timer) {
5657
// canceling resulting promise cancels timer and closes socket
57-
$loop->cancelTimer($timer);
58+
$this->loop->cancelTimer($timer);
5859
$socket->close();
5960
throw new RuntimeException('Cancelled');
6061
});
6162

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

66-
$deferred->progress($message);
67-
});
68+
$that = $this;
69+
$socket->on('message', function ($data, $remote) use (&$messages, $that) {
70+
$message = $that->parseMessage($data, $remote);
71+
$messages[] = $message;
72+
});
6873

69-
$socket->send($data, self::ADDRESS);
74+
$socket->send($data, self::ADDRESS);
7075

71-
return $deferred->promise();
76+
return $deferred->promise();
7277
}
7378

7479
/** @internal */

tests/ClientTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,32 @@ public function testSearchTimeout()
7171

7272
$promise->then($this->expectCallableOnce(), $this->expectCallableNever(), $this->expectCallableNever());
7373
}
74+
75+
public function testCtorThrowsForInvalidLoop()
76+
{
77+
if (method_exists($this, 'expectException')) {
78+
// PHPUnit 5.2+
79+
$this->expectException('InvalidArgumentException');
80+
$this->expectExceptionMessage('Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');
81+
} else {
82+
// legacy PHPUnit
83+
$this->setExpectedException('InvalidArgumentException', 'Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');
84+
}
85+
86+
new Client('loop');
87+
}
88+
89+
public function testCtorThrowsForInvalidMulticast()
90+
{
91+
if (method_exists($this, 'expectException')) {
92+
// PHPUnit 5.2+
93+
$this->expectException('InvalidArgumentException');
94+
$this->expectExceptionMessage('Argument #2 ($multicast) expected null|Clue\React\Multicast\Factory');
95+
} else {
96+
// legacy PHPUnit
97+
$this->setExpectedException('InvalidArgumentException', 'Argument #2 ($multicast) expected null|Clue\React\Multicast\Factory');
98+
}
99+
100+
new Client(null, 'multicast');
101+
}
74102
}

0 commit comments

Comments
 (0)