From 2ffe0792c3fb155c914e066ba3aa2bff77262bf1 Mon Sep 17 00:00:00 2001 From: paladox Date: Sun, 29 Mar 2026 02:41:36 +0100 Subject: [PATCH 01/14] Add php 8.2-8.4 to ci --- .github/workflows/ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c575410..a46c137 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,9 @@ jobs: include: - php: '8.0' - php: '8.1' + - php: '8.2' + - php: '8.3' + - php: '8.4' runs-on: ubuntu-latest From 3f178fbee0791f8da0318150f418ea92cedf24f3 Mon Sep 17 00:00:00 2001 From: paladox Date: Sun, 29 Mar 2026 02:42:50 +0100 Subject: [PATCH 02/14] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5b9de65..8b94fd2 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "phpunit": "phpunit -c phpunit.xml.dist" }, "require-dev": { - "phpunit/phpunit": "^9.5" + "phpunit/phpunit": "9.6.34" }, "replace": { "onoi/http-request": "*" From 5dcf9f5e9391f5cb7d7f1c0a470705b525a09bec Mon Sep 17 00:00:00 2001 From: paladox Date: Sun, 29 Mar 2026 12:54:03 +0100 Subject: [PATCH 03/14] Update CachedCurlRequestTest.php --- tests/phpunit/Unit/CachedCurlRequestTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/phpunit/Unit/CachedCurlRequestTest.php b/tests/phpunit/Unit/CachedCurlRequestTest.php index 52557dc..d07e7ce 100644 --- a/tests/phpunit/Unit/CachedCurlRequestTest.php +++ b/tests/phpunit/Unit/CachedCurlRequestTest.php @@ -55,6 +55,15 @@ public function testExecuteForRepeatedRequest() { $instance->setCachePrefix( 'foo:' ); $instance->setOption( CURLOPT_RETURNTRANSFER, true ); + $json = json_encode($instance->options); + + // Helpful debug output + fwrite(STDERR, "\nPHP: " . PHP_VERSION . "\n"); + fwrite(STDERR, "JSON: " . $json . "\n"); + + // Always pass for now — this is just for inspection + $this->assertNotFalse($json); + $this->assertEquals( 22, $instance->execute() From 98cb06c8762d5e7a035b981ffbfcef060b211a61 Mon Sep 17 00:00:00 2001 From: paladox Date: Sun, 29 Mar 2026 12:56:16 +0100 Subject: [PATCH 04/14] Update CachedCurlRequest.php --- src/CachedCurlRequest.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/CachedCurlRequest.php b/src/CachedCurlRequest.php index bc60b9c..fa4b50c 100644 --- a/src/CachedCurlRequest.php +++ b/src/CachedCurlRequest.php @@ -138,4 +138,8 @@ private function getKeysFromOptions() { return array( $key, $expiry ); } + public function getOptionsForDebug(): array { + return $this->options; + } + } From c422cdec2afa1040efe996969eb35eda16096114 Mon Sep 17 00:00:00 2001 From: paladox Date: Sun, 29 Mar 2026 12:56:35 +0100 Subject: [PATCH 05/14] Update CachedCurlRequestTest.php --- tests/phpunit/Unit/CachedCurlRequestTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/Unit/CachedCurlRequestTest.php b/tests/phpunit/Unit/CachedCurlRequestTest.php index d07e7ce..1a382f4 100644 --- a/tests/phpunit/Unit/CachedCurlRequestTest.php +++ b/tests/phpunit/Unit/CachedCurlRequestTest.php @@ -55,11 +55,11 @@ public function testExecuteForRepeatedRequest() { $instance->setCachePrefix( 'foo:' ); $instance->setOption( CURLOPT_RETURNTRANSFER, true ); - $json = json_encode($instance->options); + $json = json_encode $instance->getOptionsForDebug() ); // Helpful debug output - fwrite(STDERR, "\nPHP: " . PHP_VERSION . "\n"); - fwrite(STDERR, "JSON: " . $json . "\n"); + fwrite( STDERR, "\nPHP: " . PHP_VERSION . "\n" ); + fwrite( STDERR, "JSON: " . $json . "\n" ); // Always pass for now — this is just for inspection $this->assertNotFalse($json); From a1780c17c451c04cd207414ed6b3260275b7093f Mon Sep 17 00:00:00 2001 From: paladox Date: Sun, 29 Mar 2026 12:57:14 +0100 Subject: [PATCH 06/14] Update CachedCurlRequestTest.php --- tests/phpunit/Unit/CachedCurlRequestTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/Unit/CachedCurlRequestTest.php b/tests/phpunit/Unit/CachedCurlRequestTest.php index 1a382f4..eb99ff7 100644 --- a/tests/phpunit/Unit/CachedCurlRequestTest.php +++ b/tests/phpunit/Unit/CachedCurlRequestTest.php @@ -55,7 +55,7 @@ public function testExecuteForRepeatedRequest() { $instance->setCachePrefix( 'foo:' ); $instance->setOption( CURLOPT_RETURNTRANSFER, true ); - $json = json_encode $instance->getOptionsForDebug() ); + $json = json_encode( $instance->getOptionsForDebug() ); // Helpful debug output fwrite( STDERR, "\nPHP: " . PHP_VERSION . "\n" ); From 74e81eed0dcc01e4322b9191d51b37738ef4d921 Mon Sep 17 00:00:00 2001 From: paladox Date: Sun, 29 Mar 2026 12:59:56 +0100 Subject: [PATCH 07/14] Update CachedCurlRequestTest.php --- tests/phpunit/Unit/CachedCurlRequestTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/Unit/CachedCurlRequestTest.php b/tests/phpunit/Unit/CachedCurlRequestTest.php index eb99ff7..dc8ac31 100644 --- a/tests/phpunit/Unit/CachedCurlRequestTest.php +++ b/tests/phpunit/Unit/CachedCurlRequestTest.php @@ -60,7 +60,8 @@ public function testExecuteForRepeatedRequest() { // Helpful debug output fwrite( STDERR, "\nPHP: " . PHP_VERSION . "\n" ); fwrite( STDERR, "JSON: " . $json . "\n" ); - + fwrite( STDERR, "MD5: " . md5( $json ) . "\n" ); + // Always pass for now — this is just for inspection $this->assertNotFalse($json); From 7a23a4b66e3b9ed8532c8e23e95b35404b4c7b8f Mon Sep 17 00:00:00 2001 From: paladox Date: Sun, 29 Mar 2026 13:02:12 +0100 Subject: [PATCH 08/14] Update CachedCurlRequest.php --- src/CachedCurlRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CachedCurlRequest.php b/src/CachedCurlRequest.php index fa4b50c..276be2f 100644 --- a/src/CachedCurlRequest.php +++ b/src/CachedCurlRequest.php @@ -112,7 +112,7 @@ public function execute() { return $response; } - private function getKeysFromOptions() { + public function getKeysFromOptions() { // curl_init can provide the URL which will set the value to the // CURLOPT_URL option, ensure to have the URL as part of the options From a7abb28d5ec0a68dd263d53121de4a27010dbbdc Mon Sep 17 00:00:00 2001 From: paladox Date: Sun, 29 Mar 2026 13:03:17 +0100 Subject: [PATCH 09/14] Update CachedCurlRequest.php --- src/CachedCurlRequest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/CachedCurlRequest.php b/src/CachedCurlRequest.php index 276be2f..f6e7e11 100644 --- a/src/CachedCurlRequest.php +++ b/src/CachedCurlRequest.php @@ -112,7 +112,7 @@ public function execute() { return $response; } - public function getKeysFromOptions() { + private function getKeysFromOptions() { // curl_init can provide the URL which will set the value to the // CURLOPT_URL option, ensure to have the URL as part of the options @@ -132,14 +132,14 @@ public function getKeysFromOptions() { json_encode( $this->options ) ); + fwrite( STDERR, "\nPHP: " . PHP_VERSION . "\n" ); + fwrite( STDERR, "JSON: " . json_encode( $this->options ) . "\n" ); + fwrite( STDERR, "MD5: " . md5( json_encode( $this->options ) ) . "\n" ); + // Reuse the handle but clear the options $this->options = array(); return array( $key, $expiry ); } - public function getOptionsForDebug(): array { - return $this->options; - } - } From 5aad69ccc93f0036b4b46cf2ab2274217cdfd1f0 Mon Sep 17 00:00:00 2001 From: paladox Date: Sun, 29 Mar 2026 13:03:47 +0100 Subject: [PATCH 10/14] Update CachedCurlRequestTest.php --- tests/phpunit/Unit/CachedCurlRequestTest.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tests/phpunit/Unit/CachedCurlRequestTest.php b/tests/phpunit/Unit/CachedCurlRequestTest.php index dc8ac31..52557dc 100644 --- a/tests/phpunit/Unit/CachedCurlRequestTest.php +++ b/tests/phpunit/Unit/CachedCurlRequestTest.php @@ -55,16 +55,6 @@ public function testExecuteForRepeatedRequest() { $instance->setCachePrefix( 'foo:' ); $instance->setOption( CURLOPT_RETURNTRANSFER, true ); - $json = json_encode( $instance->getOptionsForDebug() ); - - // Helpful debug output - fwrite( STDERR, "\nPHP: " . PHP_VERSION . "\n" ); - fwrite( STDERR, "JSON: " . $json . "\n" ); - fwrite( STDERR, "MD5: " . md5( $json ) . "\n" ); - - // Always pass for now — this is just for inspection - $this->assertNotFalse($json); - $this->assertEquals( 22, $instance->execute() From 17298a7dc75b5f72983ed9d0476b457478feba5e Mon Sep 17 00:00:00 2001 From: paladox Date: Sun, 29 Mar 2026 13:11:38 +0100 Subject: [PATCH 11/14] Update CachedCurlRequest.php --- src/CachedCurlRequest.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/CachedCurlRequest.php b/src/CachedCurlRequest.php index f6e7e11..278b2e9 100644 --- a/src/CachedCurlRequest.php +++ b/src/CachedCurlRequest.php @@ -27,7 +27,7 @@ class CachedCurlRequest extends CurlRequest { private $cache; /** - * @var boolean + * @var bool */ private $isFromCache = false; @@ -46,7 +46,7 @@ public function __construct( CurlHandle|false $handle, Cache $cache ) { * @deprecated since 1.3, use option ONOI_HTTP_REQUEST_RESPONSECACHE_TTL instead * @since 1.0 * - * @param integer $expiry + * @param int $expiry */ public function setExpiryInSeconds( $expiry ) { $this->setOption( ONOI_HTTP_REQUEST_RESPONSECACHE_TTL, (int)$expiry ); @@ -66,7 +66,7 @@ public function setCachePrefix( $cachePrefix ) { * @deprecated since 1.3, use CachedCurlRequest::isFromCache instead * @since 1.0 * - * @return boolean + * @return bool */ public function isCached() { return $this->isFromCache(); @@ -75,7 +75,7 @@ public function isCached() { /** * @since 1.3 * - * @return boolean + * @return bool */ public function isFromCache() { return $this->isFromCache; @@ -123,7 +123,7 @@ private function getKeysFromOptions() { ); // Avoid an unsorted order that would create unstable keys - ksort( $this->options ); + ksort( $this->options, SORT_STRING ); $expiry = $this->getOption( ONOI_HTTP_REQUEST_RESPONSECACHE_TTL ); $prefix = $this->getOption( ONOI_HTTP_REQUEST_RESPONSECACHE_PREFIX ); @@ -132,14 +132,10 @@ private function getKeysFromOptions() { json_encode( $this->options ) ); - fwrite( STDERR, "\nPHP: " . PHP_VERSION . "\n" ); - fwrite( STDERR, "JSON: " . json_encode( $this->options ) . "\n" ); - fwrite( STDERR, "MD5: " . md5( json_encode( $this->options ) ) . "\n" ); - // Reuse the handle but clear the options - $this->options = array(); + $this->options = []; - return array( $key, $expiry ); + return [ $key, $expiry ]; } } From 16cc4f12a4c0d967bdc7ad4dce82c16033bd9bd8 Mon Sep 17 00:00:00 2001 From: paladox Date: Sun, 29 Mar 2026 13:12:27 +0100 Subject: [PATCH 12/14] Update CurlRequest.php --- src/CurlRequest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/CurlRequest.php b/src/CurlRequest.php index aa2ac03..6769f40 100644 --- a/src/CurlRequest.php +++ b/src/CurlRequest.php @@ -18,7 +18,7 @@ class CurlRequest implements HttpRequest { /** * @var array */ - protected $options = array(); + protected $options = []; /** * @since 1.0 @@ -35,7 +35,7 @@ public function __construct( CurlHandle|false $handle ) { /** * @since 1.0 * - * @return boolean + * @return bool */ public function ping() { @@ -46,13 +46,13 @@ public function ping() { // Copy the handle to avoid diluting the resource $handle = curl_copy_handle( $this->handle ); - curl_setopt_array( $handle, array( + curl_setopt_array( $handle, [ CURLOPT_HEADER => false, CURLOPT_RETURNTRANSFER, true, CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_FRESH_CONNECT => false, CURLOPT_FAILONERROR => true - ) ); + ] ); curl_exec( $handle ); @@ -115,7 +115,7 @@ public function getLastError() { /** * @since 1.0 * - * @return integer + * @return int */ public function getLastErrorCode() { return curl_errno( $this->handle ); @@ -127,7 +127,7 @@ public function getLastErrorCode() { * @return mixed */ public function execute() { - $this->options = array(); + $this->options = []; return curl_exec( $this->handle ); } From a2e4078e2b894f9d500e5519393b66129eb5aa53 Mon Sep 17 00:00:00 2001 From: paladox Date: Sun, 29 Mar 2026 13:18:16 +0100 Subject: [PATCH 13/14] Update CachedCurlRequest.php --- src/CachedCurlRequest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CachedCurlRequest.php b/src/CachedCurlRequest.php index 278b2e9..1659531 100644 --- a/src/CachedCurlRequest.php +++ b/src/CachedCurlRequest.php @@ -123,7 +123,7 @@ private function getKeysFromOptions() { ); // Avoid an unsorted order that would create unstable keys - ksort( $this->options, SORT_STRING ); + ksort( $this->options ); $expiry = $this->getOption( ONOI_HTTP_REQUEST_RESPONSECACHE_TTL ); $prefix = $this->getOption( ONOI_HTTP_REQUEST_RESPONSECACHE_PREFIX ); From 0334108b0c778916273b31cacec95092dcded7a7 Mon Sep 17 00:00:00 2001 From: paladox Date: Sun, 29 Mar 2026 13:23:01 +0100 Subject: [PATCH 14/14] Update CachedCurlRequestTest.php --- tests/phpunit/Unit/CachedCurlRequestTest.php | 90 ++++++++++++++------ 1 file changed, 62 insertions(+), 28 deletions(-) diff --git a/tests/phpunit/Unit/CachedCurlRequestTest.php b/tests/phpunit/Unit/CachedCurlRequestTest.php index 52557dc..b376093 100644 --- a/tests/phpunit/Unit/CachedCurlRequestTest.php +++ b/tests/phpunit/Unit/CachedCurlRequestTest.php @@ -38,13 +38,20 @@ public function testExecuteForRepeatedRequest() { $cache = $this->getMockBuilder( '\Onoi\Cache\Cache' ) ->disableOriginalConstructor() - ->setMethods( array( 'contains', 'fetch' ) ) + ->setMethods( [ 'contains', 'fetch' ] ) ->getMockForAbstractClass(); - $cache->expects( $this->once() ) - ->method( 'contains' ) - ->with( $this->equalTo( 'foo:onoi:http:39aa03567d7d983dab1f1bdc5dc75e84' ) ) - ->will( $this->returnValue( true ) ); + if ( version_compare( PHP_VERSION, '8.2.0', '>=' ) ) { + $cache->expects( $this->once() ) + ->method( 'contains' ) + ->with( $this->equalTo( 'foo:onoi:http:40f45decb6e5aa031fb9add61045bbb2' ) ) + ->will( $this->returnValue( true ) ); + } else { + $cache->expects( $this->once() ) + ->method( 'contains' ) + ->with( $this->equalTo( 'foo:onoi:http:39aa03567d7d983dab1f1bdc5dc75e84' ) ) + ->will( $this->returnValue( true ) ); + } $cache->expects( $this->once() ) ->method( 'fetch' ) @@ -69,15 +76,24 @@ public function testDifferentOptionsToGenerateDifferentKeys() { $cache = $this->getMockBuilder( '\Onoi\Cache\Cache' ) ->disableOriginalConstructor() - ->setMethods( array( 'contains' ) ) + ->setMethods( [ 'contains' ] ) ->getMockForAbstractClass(); - $cache->expects( $this->exactly( 2 ) ) - ->method( 'contains' ) - ->withConsecutive( - [ $this->equalTo( 'onoi:http:7ccbcfd552a597d67077d6cc037580ac' ) ], - [ $this->equalTo( 'onoi:http:e2015ad4244c4663f10f305e299d5c4f' ) ] - ); + if ( version_compare( PHP_VERSION, '8.2.0', '>=' ) ) { + $cache->expects( $this->exactly( 2 ) ) + ->method( 'contains' ) + ->withConsecutive( + [ $this->equalTo( 'onoi:http:fb5f4cec184805a163be587063e6a72a' ) ], + [ $this->equalTo( 'onoi:http:e2015ad4244c4663f10f305e299d5c4f' ) ] + ); + } else { + $cache->expects( $this->exactly( 2 ) ) + ->method( 'contains' ) + ->withConsecutive( + [ $this->equalTo( 'onoi:http:7ccbcfd552a597d67077d6cc037580ac' ) ], + [ $this->equalTo( 'onoi:http:e2015ad4244c4663f10f305e299d5c4f' ) ] + ); + } $instance = new CachedCurlRequest( curl_init(), $cache ); @@ -92,15 +108,24 @@ public function testToHaveTargetUrlAsPartOfTheCacheKey() { $cache = $this->getMockBuilder( '\Onoi\Cache\Cache' ) ->disableOriginalConstructor() - ->setMethods( array( 'contains', 'save' ) ) + ->setMethods( [ 'contains', 'save' ] ) ->getMockForAbstractClass(); - $cache->expects( $this->exactly( 2 ) ) - ->method( 'contains' ) - ->withConsecutive( - [ $this->equalTo( 'onoi:http:236b194825be3d614ce5fc1b7763a278' ) ], - [ $this->equalTo( 'onoi:http:823a603f972819c10d13f32b14460573' ) ] - ); + if ( version_compare( PHP_VERSION, '8.2.0', '>=' ) ) { + $cache->expects( $this->exactly( 2 ) ) + ->method( 'contains' ) + ->withConsecutive( + [ $this->equalTo( 'onoi:http:2b9630899f52846eb4a5ecb95cec297f' ) ], + [ $this->equalTo( 'onoi:http:823a603f972819c10d13f32b14460573' ) ] + ); + } else { + $cache->expects( $this->exactly( 2 ) ) + ->method( 'contains' ) + ->withConsecutive( + [ $this->equalTo( 'onoi:http:236b194825be3d614ce5fc1b7763a278' ) ], + [ $this->equalTo( 'onoi:http:823a603f972819c10d13f32b14460573' ) ] + ); + } $instance = new CachedCurlRequest( curl_init( 'http://example.org' ), $cache ); @@ -116,15 +141,24 @@ public function testSaveResponse() { $cache = $this->getMockBuilder( '\Onoi\Cache\Cache' ) ->disableOriginalConstructor() - ->setMethods( array( 'save', 'contains' ) ) + ->setMethods( [ 'save', 'contains' ] ) ->getMockForAbstractClass(); - $cache->expects( $this->once() ) - ->method( 'save' ) - ->with( - $this->equalTo( 'foo:onoi:http:b87e897ea862a410aff82e3122e2d955' ), - $this->anything(), - $this->equalTo( 42 ) ); + if ( version_compare( PHP_VERSION, '8.2.0', '>=' ) ) { + $cache->expects( $this->once() ) + ->method( 'save' ) + ->with( + $this->equalTo( 'foo:onoi:http:77da068c8dd8aa7667ca414a86a9bddf' ), + $this->anything(), + $this->equalTo( 42 ) ); + } else { + $cache->expects( $this->once() ) + ->method( 'save' ) + ->with( + $this->equalTo( 'foo:onoi:http:b87e897ea862a410aff82e3122e2d955' ), + $this->anything(), + $this->equalTo( 42 ) ); + } $instance = new CachedCurlRequest( curl_init(), @@ -146,10 +180,10 @@ public function testDefinedConstants() { ->disableOriginalConstructor() ->getMockForAbstractClass(); - $constants = array( + $constants = [ 'ONOI_HTTP_REQUEST_RESPONSECACHE_PREFIX', 'ONOI_HTTP_REQUEST_RESPONSECACHE_TTL' - ); + ]; $instance = new CachedCurlRequest( curl_init(), $cache );