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 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": "*" diff --git a/src/CachedCurlRequest.php b/src/CachedCurlRequest.php index bc60b9c..1659531 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; @@ -133,9 +133,9 @@ private function getKeysFromOptions() { ); // Reuse the handle but clear the options - $this->options = array(); + $this->options = []; - return array( $key, $expiry ); + return [ $key, $expiry ]; } } 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 ); } 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 );