From dd1446e56e38d3953b40ac06fd33b06e42cc271c Mon Sep 17 00:00:00 2001 From: David Maicher Date: Thu, 5 Nov 2020 15:50:13 +0100 Subject: [PATCH] allow php 8 (#880) * allow php 8 * run tests using PHP 8.0 * remove fixed phpstan version * allow phpunit 9 * fix invalid return type for magic "__set" method * fix __unset return type * try increasing phpstan memory limit * fix curl_init returning \CurlHandle instead of resource Co-authored-by: Markus Kalkbrenner --- .github/workflows/run-tests.yml | 5 ++--- composer.json | 4 ++-- src/Core/Client/Adapter/Curl.php | 2 +- src/Core/Query/AbstractDocument.php | 4 +--- src/Plugin/MinimumScoreFilter/Document.php | 4 +--- src/QueryType/Select/Result/Document.php | 5 +---- src/QueryType/Update/Query/Document.php | 13 ++----------- tests/Core/Client/Adapter/CurlTest.php | 6 +++++- 8 files changed, 15 insertions(+), 28 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 6fda61961..8a12a5980 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: - php: [7.2, 7.3, 7.4] + php: [7.2, 7.3, 7.4, 8.0] solr: [7, 8] mode: [cloud, server] @@ -63,12 +63,11 @@ jobs: - name: Install dependencies run: | - composer require phpstan/phpstan:0.12.25 composer update - name: Run tests run: | - vendor/bin/phpstan analyze src/ tests/ --level=1 + vendor/bin/phpstan analyze src/ tests/ --level=1 --memory-limit=1G vendor/bin/phpunit -c phpunit.xml --exclude-group skip_for_solr_${{ matrix.mode }} -v --coverage-clover build/logs/clover.xml - name: Execute examples diff --git a/composer.json b/composer.json index 88c09cd18..2e40cc9aa 100755 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ } ], "require": { - "php": "^7.2", + "php": "^7.2 || ^8.0", "ext-json": "*", "psr/event-dispatcher": "^1.0", "psr/http-client": "^1.0", @@ -27,7 +27,7 @@ "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "^0.12", "phpstan/phpstan-phpunit": "^0.12", - "phpunit/phpunit": "^8.0", + "phpunit/phpunit": "^8.5 || ^9.4", "roave/security-advisories": "dev-master", "symfony/event-dispatcher": "^4.3 || ^5.0" }, diff --git a/src/Core/Client/Adapter/Curl.php b/src/Core/Client/Adapter/Curl.php index 8ba1064af..18a61f7a0 100644 --- a/src/Core/Client/Adapter/Curl.php +++ b/src/Core/Client/Adapter/Curl.php @@ -73,7 +73,7 @@ public function getResponse($handle, $httpResponse): Response * * @throws InvalidArgumentException * - * @return resource + * @return resource|\CurlHandle */ public function createHandle($request, $endpoint) { diff --git a/src/Core/Query/AbstractDocument.php b/src/Core/Query/AbstractDocument.php index 4e5fb53f2..44aceae49 100644 --- a/src/Core/Query/AbstractDocument.php +++ b/src/Core/Query/AbstractDocument.php @@ -24,10 +24,8 @@ abstract class AbstractDocument implements DocumentInterface, \IteratorAggregate /** * @param mixed $name * @param mixed $value - * - * @return \Solarium\Core\Query\DocumentInterface */ - abstract public function __set($name, $value): DocumentInterface; + abstract public function __set($name, $value): void; /** * Get field value by name. diff --git a/src/Plugin/MinimumScoreFilter/Document.php b/src/Plugin/MinimumScoreFilter/Document.php index 5b3816844..a64b61315 100644 --- a/src/Plugin/MinimumScoreFilter/Document.php +++ b/src/Plugin/MinimumScoreFilter/Document.php @@ -93,10 +93,8 @@ public function __isset($name): bool * @param string $value * * @throws RuntimeException - * - * @return self */ - public function __set($name, $value): self + public function __set($name, $value): void { throw new RuntimeException('A readonly document cannot be altered'); } diff --git a/src/QueryType/Select/Result/Document.php b/src/QueryType/Select/Result/Document.php index b968f4249..cecc55c56 100644 --- a/src/QueryType/Select/Result/Document.php +++ b/src/QueryType/Select/Result/Document.php @@ -10,7 +10,6 @@ namespace Solarium\QueryType\Select\Result; use Solarium\Core\Query\AbstractDocument; -use Solarium\Core\Query\DocumentInterface; use Solarium\Exception\RuntimeException; /** @@ -48,10 +47,8 @@ public function __construct(array $fields) * @param string $value * * @throws RuntimeException - * - * @return DocumentInterface */ - public function __set($name, $value): DocumentInterface + public function __set($name, $value): void { throw new RuntimeException('A readonly document cannot be altered'); } diff --git a/src/QueryType/Update/Query/Document.php b/src/QueryType/Update/Query/Document.php index 5b43d6cd2..91d1fa470 100644 --- a/src/QueryType/Update/Query/Document.php +++ b/src/QueryType/Update/Query/Document.php @@ -10,7 +10,6 @@ namespace Solarium\QueryType\Update\Query; use Solarium\Core\Query\AbstractDocument; -use Solarium\Core\Query\DocumentInterface; use Solarium\Core\Query\Helper; use Solarium\Exception\RuntimeException; @@ -175,14 +174,10 @@ public function __construct(array $fields = [], array $boosts = [], array $modif * * @param string $name * @param mixed $value - * - * @return self */ - public function __set($name, $value): DocumentInterface + public function __set($name, $value): void { $this->setField($name, $value); - - return $this; } /** @@ -191,14 +186,10 @@ public function __set($name, $value): DocumentInterface * Magic method for removing fields by un-setting object properties * * @param string $name - * - * @return self */ - public function __unset($name): self + public function __unset($name): void { $this->removeField($name); - - return $this; } /** diff --git a/tests/Core/Client/Adapter/CurlTest.php b/tests/Core/Client/Adapter/CurlTest.php index f30455ca0..15605c929 100644 --- a/tests/Core/Client/Adapter/CurlTest.php +++ b/tests/Core/Client/Adapter/CurlTest.php @@ -78,7 +78,11 @@ public function testCanCreateHandleForDeleteRequest() $curlAdapter = new Curl(); $handler = $curlAdapter->createHandle($request, $endpoint); - $this->assertIsResource($handler); + if (class_exists(\CurlHandle::class)) { + $this->assertInstanceOf(\CurlHandle::class, $handler); + } else { + $this->assertIsResource($handler); + } curl_close($handler); } }