Skip to content

Commit 05c4621

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

File tree

4 files changed

+53
-10
lines changed

4 files changed

+53
-10
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: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ class Client
3030
*/
3131
public function __construct(LoopInterface $loop = null, MulticastFactory $multicast = null)
3232
{
33+
if ($loop !== null && !$loop instanceof LoopInterface) {
34+
throw new \InvalidArgumentException('Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');
35+
}
36+
if ($multicast !== null && !$multicast instanceof MulticastFactory) {
37+
throw new \InvalidArgumentException('Argument #2 ($multicast) expected null|Clue\React\Multicast\Factory');
38+
}
39+
3340
$this->loop = $loop ?: Loop::get();
3441
$this->multicast = $multicast ?: new MulticastFactory($this->loop);
3542
}
@@ -46,8 +53,11 @@ public function search($searchTarget = 'ssdp:all', $mx = 2)
4653
$socket = $this->multicast->createSender();
4754
// TODO: The TTL for the IP packet SHOULD default to 2 and SHOULD be configurable.
4855

49-
$timer = $this->loop->addTimer($mx, function() use ($socket, &$deferred) {
50-
$deferred->resolve();
56+
$messages = array();
57+
58+
$timer = $this->loop->addTimer($mx, function() use ($socket, &$deferred, &$messages) {
59+
// resolve promise with all collected messages
60+
$deferred->resolve($messages);
5161
$socket->close();
5262
});
5363

@@ -60,10 +70,10 @@ public function search($searchTarget = 'ssdp:all', $mx = 2)
6070
});
6171

6272
$that = $this;
63-
$socket->on('message', function ($data, $remote) use ($deferred, $that) {
73+
$socket->on('message', function ($data, $remote) use ($that, &$messages) {
6474
$message = $that->parseMessage($data, $remote);
6575

66-
$deferred->progress($message);
76+
$messages[] = $message;
6777
});
6878

6979
$socket->send($data, self::ADDRESS);

tests/ClientTest.php

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,40 @@ public function testSearchTimeout()
6767

6868
$promise = $client->search('ssdp:all', 0.01);
6969

70-
Loop::run();
70+
$result = null;
71+
$promise->then(function ($value) use (&$result) {
72+
$result = $value;
73+
});
7174

72-
$promise->then($this->expectCallableOnce(), $this->expectCallableNever(), $this->expectCallableNever());
75+
Loop::run();
76+
77+
$this->assertTrue(is_array($result), 'Expected result to be an array');
78+
}
79+
80+
public function testCtorThrowsForInvalidLoop()
81+
{
82+
if (method_exists($this, 'expectException')) {
83+
// PHPUnit 5.2+
84+
$this->expectException('InvalidArgumentException');
85+
$this->expectExceptionMessage('Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');
86+
} else {
87+
// legacy PHPUnit
88+
$this->setExpectedException('InvalidArgumentException', 'Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');
89+
}
90+
91+
new Client('invalid-loop');
7392
}
93+
94+
public function testCtorThrowsForInvalidMulticast()
95+
{
96+
if (method_exists($this, 'expectException')) {
97+
$this->expectException('InvalidArgumentException');
98+
$this->expectExceptionMessage('Argument #2 ($multicast) expected null|Clue\React\Multicast\Factory');
99+
} else {
100+
$this->setExpectedException('InvalidArgumentException', 'Argument #2 ($multicast) expected null|Clue\React\Multicast\Factory');
101+
}
102+
103+
new Client(null, 'invalid-multicast');
104+
}
105+
74106
}

0 commit comments

Comments
 (0)