From d08465432c6417fadc3d276b2e8ae85061bb02fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sun, 25 Jan 2026 22:51:04 +0100 Subject: [PATCH] Improve PHP 8.5+ support and update test environment --- .github/workflows/ci.yml | 3 ++- composer.json | 4 ++-- src/MessageEvent.php | 2 +- tests/EventSourceTest.php | 12 +++++++++--- tests/MessageEventTest.php | 2 ++ 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a2dfd62..ad528ed 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,6 +11,7 @@ jobs: strategy: matrix: php: + - 8.5 - 8.4 - 8.3 - 8.2 @@ -25,7 +26,7 @@ jobs: - 5.5 - 5.4 steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v6 - uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} diff --git a/composer.json b/composer.json index d6d5c20..809fc08 100644 --- a/composer.json +++ b/composer.json @@ -13,9 +13,9 @@ "require": { "php": ">=5.4", "evenement/evenement": "^3.0 || ^2.0", - "react/event-loop": "^1.2", + "react/event-loop": "^1.6", "react/http": "^1.11", - "react/promise": "^3.2 || ^2.10 || ^1.2.1" + "react/promise": "^3.3 || ^2.10 || ^1.2.1" }, "require-dev": { "phpunit/phpunit": "^9.6 || ^8.5 || ^5.7 || ^4.8.36" diff --git a/src/MessageEvent.php b/src/MessageEvent.php index 08c87da..d9e8dee 100644 --- a/src/MessageEvent.php +++ b/src/MessageEvent.php @@ -34,7 +34,7 @@ public static function parse($data, $lastEventId, &$retryTime = 0.0) $id = self::utf8($value); } elseif ($name === 'event' && $value !== '') { $type = self::utf8($value); - } elseif ($name === 'retry' && $value === (string)(int)$value && $value >= 0) { + } elseif ($name === 'retry' && $value >= 0 && $value <= \PHP_INT_MAX && $value === (string) (int) $value) { $retryTime = $value * 0.001; } } diff --git a/tests/EventSourceTest.php b/tests/EventSourceTest.php index acef4b5..1b58680 100644 --- a/tests/EventSourceTest.php +++ b/tests/EventSourceTest.php @@ -46,13 +46,17 @@ public function testConstructWithoutBrowserAndLoopAssignsBrowserAndLoopAutomatic $es = new EventSource('http://example.com'); $ref = new \ReflectionProperty($es, 'browser'); - $ref->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $ref->setAccessible(true); + } $browser = $ref->getValue($es); $this->assertInstanceOf('React\Http\Browser', $browser); $ref = new \ReflectionProperty($es, 'loop'); - $ref->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $ref->setAccessible(true); + } $loop = $ref->getValue($es); $this->assertInstanceOf('React\EventLoop\LoopInterface', $loop); @@ -557,7 +561,9 @@ public function testEmitMessageOnceWhenCallingCloseFromMessageHandlerFromEventSt $this->assertEquals('1', $message->lastEventId); $ref = new \ReflectionProperty($es, 'lastEventId'); - $ref->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $ref->setAccessible(true); + } $this->assertEquals('1', $ref->getValue($es)); } diff --git a/tests/MessageEventTest.php b/tests/MessageEventTest.php index a65f69a..9cc056a 100644 --- a/tests/MessageEventTest.php +++ b/tests/MessageEventTest.php @@ -160,7 +160,9 @@ public function retryTimeDataProvider() ['retry: ' . PHP_INT_MAX . '9', null], ['retry: 1.234', null], ['retry: now', null], + ['retry: 0.0', null], ['retry: -1', null], + ['retry: +1', null], ['retry: -1.234', null] ]; }