Skip to content

Commit 58c2a3b

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

File tree

4 files changed

+82
-32
lines changed

4 files changed

+82
-32
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 9 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
@@ -24,30 +25,41 @@ jobs:
2425
- 5.5
2526
- 5.4
2627
- 5.3
28+
fail-fast: false
2729
steps:
2830
- uses: actions/checkout@v4
2931
- uses: shivammathur/setup-php@v2
3032
with:
3133
php-version: ${{ matrix.php }}
3234
coverage: xdebug
33-
- run: composer install
34-
- run: vendor/bin/phpunit --coverage-text
35-
if: ${{ matrix.php >= 7.3 }}
36-
- run: vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy
37-
if: ${{ matrix.php < 7.3 }}
35+
env:
36+
# Für PHP 8.4 Deprecation Warnings als nicht-fatal behandeln
37+
fail-fast: false
38+
- name: Install dependencies (Modern PHP)
39+
if: ${{ matrix.php >= '7.3' }}
40+
run: composer install --prefer-dist --no-progress
41+
- name: Install dependencies (Legacy PHP)
42+
if: ${{ matrix.php < '7.3' }}
43+
run: composer install --prefer-dist --no-progress --ignore-platform-reqs
44+
- name: Run tests (Modern PHP)
45+
if: ${{ matrix.php >= '7.3' }}
46+
run: vendor/bin/phpunit --coverage-text
47+
- name: Run tests (Legacy PHP)
48+
if: ${{ matrix.php < '7.3' }}
49+
run: vendor/bin/phpunit --coverage-text -c phpunit.xml.legacy
3850

3951
PHPUnit-hhvm:
4052
name: PHPUnit (HHVM)
41-
runs-on: ubuntu-22.04
53+
runs-on: ubuntu-24.04
4254
continue-on-error: true
4355
steps:
4456
- uses: actions/checkout@v4
4557
- run: cp "$(which composer)" composer.phar && ./composer.phar self-update --2.2 # downgrade Composer for HHVM
4658
- name: Run hhvm composer.phar install
4759
uses: docker://hhvm/hhvm:3.30-lts-latest
4860
with:
49-
args: hhvm composer.phar install
61+
args: hhvm composer.phar install --ignore-platform-reqs
5062
- name: Run hhvm vendor/bin/phpunit
5163
uses: docker://hhvm/hhvm:3.30-lts-latest
5264
with:
53-
args: hhvm vendor/bin/phpunit
65+
args: hhvm vendor/bin/phpunit

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
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": "^3.2 || ^2.7 || ^1.2.1"
2828
},
2929
"require-dev": {
30-
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36"
30+
"phpunit/phpunit": "^9.6 || ^7.5 || ^5.7 || ^4.8.36"
3131
}
32-
}
32+
}

src/Client.php

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,15 @@ 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+
}
39+
3340
$this->loop = $loop ?: Loop::get();
3441
$this->multicast = $multicast ?: new MulticastFactory($this->loop);
3542
}
@@ -44,31 +51,33 @@ public function search($searchTarget = 'ssdp:all', $mx = 2)
4451
$data .= "\r\n";
4552

4653
$socket = $this->multicast->createSender();
47-
// 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-
});
55+
// TODO: The TTL for the IP packet SHOULD default to 2 and SHOULD be configurable.
5356

5457
$loop = $this->loop;
55-
$deferred = new Deferred(function () use ($socket, &$timer, $loop) {
56-
// canceling resulting promise cancels timer and closes socket
57-
$loop->cancelTimer($timer);
58-
$socket->close();
59-
throw new RuntimeException('Cancelled');
60-
});
58+
$timer = null;
6159

62-
$that = $this;
63-
$socket->on('message', function ($data, $remote) use ($deferred, $that) {
64-
$message = $that->parseMessage($data, $remote);
60+
$deferred = new Deferred();
6561

66-
$deferred->progress($message);
62+
$timer = $this->loop->addTimer($mx, function() use ($socket, $deferred) {
63+
$deferred->resolve();
64+
$socket->close();
6765
});
6866

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

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

7483
/** @internal */
@@ -79,6 +88,7 @@ public function parseMessage($message, $remote)
7988
'data' => $message,
8089
'_sender' => $remote
8190
);
91+
8292
return $message;
8393
}
84-
}
94+
}

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('invalid');
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, 'invalid');
101+
}
74102
}

0 commit comments

Comments
 (0)