Skip to content

Commit a68b145

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

File tree

3 files changed

+60
-30
lines changed

3 files changed

+60
-30
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: 5 additions & 5 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",
26-
"react/event-loop": "^1.2",
27-
"react/promise": "^2.0 || ^1.0"
25+
"clue/multicast-react": "^1.2 || ^0.2",
26+
"react/event-loop": "^1.2 || ^0.4",
27+
"react/promise": "^3.0 || ^2.6 || ^1.2"
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: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ class Client
2525
* This value SHOULD NOT be given unless you're sure you want to explicitly use a
2626
* given event loop instance.
2727
*
28-
* @param ?LoopInterface $loop
29-
* @param ?MulticastFactory $multicast
28+
* @param LoopInterface|null $loop
29+
* @param MulticastFactory|null $multicast
3030
*/
31-
public function __construct(LoopInterface $loop = null, MulticastFactory $multicast = null)
31+
public function __construct($loop = null, $multicast = null)
3232
{
3333
$this->loop = $loop ?: Loop::get();
3434
$this->multicast = $multicast ?: new MulticastFactory($this->loop);
@@ -44,31 +44,48 @@ public function search($searchTarget = 'ssdp:all', $mx = 2)
4444
$data .= "\r\n";
4545

4646
$socket = $this->multicast->createSender();
47-
// TODO: The TTL for the IP packet SHOULD default to 2 and SHOULD be configurable.
4847

49-
$timer = $this->loop->addTimer($mx, function() use ($socket, &$deferred) {
50-
$deferred->resolve();
51-
$socket->close();
52-
});
48+
// TODO: The TTL for the IP packet SHOULD default to 2 and SHOULD be configurable.
5349

5450
$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);
51+
$timer = null;
52+
53+
// Erstelle Deferred ohne Canceller-Parameter für bessere Kompatibilität
54+
$deferred = new Deferred();
55+
56+
// Füge die Cancellation-Logik separat hinzu
57+
$promise = $deferred->promise();
58+
if (method_exists($promise, 'cancel')) {
59+
// Für ReactPHP Promise v2
60+
$promise = $promise->then(null, null, null, function () use (&$socket, &$timer, $loop) {
61+
// canceling resulting promise cancels timer and closes socket
62+
if ($timer !== null) {
63+
$loop->cancelTimer($timer);
64+
}
65+
$socket->close();
66+
throw new RuntimeException('Cancelled');
67+
});
68+
}
69+
70+
$timer = $this->loop->addTimer($mx, function() use ($socket, $deferred) {
71+
$deferred->resolve();
5872
$socket->close();
59-
throw new RuntimeException('Cancelled');
6073
});
6174

6275
$that = $this;
6376
$socket->on('message', function ($data, $remote) use ($deferred, $that) {
6477
$message = $that->parseMessage($data, $remote);
65-
66-
$deferred->progress($message);
78+
// React Promise v3+ doesn't support progress(), use notify() instead
79+
if (method_exists($deferred, 'progress')) {
80+
$deferred->progress($message);
81+
} else if (method_exists($deferred, 'notify')) {
82+
$deferred->notify($message);
83+
}
6784
});
6885

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

71-
return $deferred->promise();
88+
return $promise;
7289
}
7390

7491
/** @internal */
@@ -79,6 +96,7 @@ public function parseMessage($message, $remote)
7996
'data' => $message,
8097
'_sender' => $remote
8198
);
99+
82100
return $message;
83101
}
84-
}
102+
}

0 commit comments

Comments
 (0)