Skip to content

Commit 8b9308a

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

File tree

4 files changed

+55
-21
lines changed

4 files changed

+55
-21
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.1",
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: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,15 @@ class Client
1818
/** @var MulticastFactory */
1919
private $multicast;
2020

21-
/**
22-
* This class takes an optional `LoopInterface|null $loop` parameter that can be used to
23-
* pass the event loop instance to use for this object. You can use a `null` value
24-
* here in order to use the [default loop](https://github.com/reactphp/event-loop#loop).
25-
* This value SHOULD NOT be given unless you're sure you want to explicitly use a
26-
* given event loop instance.
27-
*
28-
* @param ?LoopInterface $loop
29-
* @param ?MulticastFactory $multicast
30-
*/
31-
public function __construct(LoopInterface $loop = null, MulticastFactory $multicast = null)
21+
public function __construct($loop = null, $multicast = null)
3222
{
23+
if ($loop !== null && !$loop instanceof LoopInterface) {
24+
throw new \InvalidArgumentException('Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');
25+
}
26+
if ($multicast !== null && !$multicast instanceof MulticastFactory) {
27+
throw new \InvalidArgumentException('Argument #2 ($multicast) expected null|Clue\React\Multicast\Factory');
28+
}
29+
3330
$this->loop = $loop ?: Loop::get();
3431
$this->multicast = $multicast ?: new MulticastFactory($this->loop);
3532
}
@@ -46,8 +43,11 @@ public function search($searchTarget = 'ssdp:all', $mx = 2)
4643
$socket = $this->multicast->createSender();
4744
// TODO: The TTL for the IP packet SHOULD default to 2 and SHOULD be configurable.
4845

49-
$timer = $this->loop->addTimer($mx, function() use ($socket, &$deferred) {
50-
$deferred->resolve();
46+
$messages = [];
47+
48+
$timer = $this->loop->addTimer($mx, function() use ($socket, &$deferred, &$messages) {
49+
// resolve promise with all collected messages
50+
$deferred->resolve($messages);
5151
$socket->close();
5252
});
5353

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

6262
$that = $this;
63-
$socket->on('message', function ($data, $remote) use ($deferred, $that) {
63+
$socket->on('message', function ($data, $remote) use ($that, &$messages) {
6464
$message = $that->parseMessage($data, $remote);
6565

66-
$deferred->progress($message);
66+
$messages[] = $message;
6767
});
6868

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

tests/ClientTest.php

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,41 @@ 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+
81+
public function testCtorThrowsForInvalidLoop()
82+
{
83+
if (method_exists($this, 'expectException')) {
84+
// PHPUnit 5.2+
85+
$this->expectException('InvalidArgumentException');
86+
$this->expectExceptionMessage('Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');
87+
} else {
88+
// legacy PHPUnit
89+
$this->setExpectedException('InvalidArgumentException', 'Argument #1 ($loop) expected null|React\EventLoop\LoopInterface');
90+
}
91+
92+
new Client('invalid-loop');
7393
}
94+
95+
public function testCtorThrowsForInvalidMulticast()
96+
{
97+
if (method_exists($this, 'expectException')) {
98+
$this->expectException('InvalidArgumentException');
99+
$this->expectExceptionMessage('Argument #2 ($multicast) expected null|Clue\React\Multicast\Factory');
100+
} else {
101+
$this->setExpectedException('InvalidArgumentException', 'Argument #2 ($multicast) expected null|Clue\React\Multicast\Factory');
102+
}
103+
104+
new Client(null, 'invalid-multicast');
105+
}
106+
74107
}

0 commit comments

Comments
 (0)