From eb3ac7bc63f733f2de0a40f8ee1fd03c5b4076b3 Mon Sep 17 00:00:00 2001 From: Jeroen Date: Wed, 25 Dec 2024 22:04:51 +0100 Subject: [PATCH] update deps, fix deprecations --- .github/workflows/ci.yml | 2 +- .github/workflows/review.yml | 2 +- .gitignore | 1 + changelog.md | 1 + composer.json | 12 +++---- phpunit.xml | 12 +++---- src/Domain/Syntax/RegExp.php | 4 +-- tests/{Unit => Support}/ClientExpectation.php | 3 +- .../{Unit => Support}/FakeElasticResponse.php | 2 +- tests/Support/QueryTypeProvider.php | 6 ++-- tests/Support/SyntaxProvider.php | 6 ++-- .../QueryProperties/SourceFilterTest.php | 2 +- .../QueryProperties/TrackTotalHitsTest.php | 2 +- tests/Unit/Domain/Syntax/SortOrderTest.php | 18 +++++----- tests/Unit/ElasticClientBuilderTest.php | 2 +- tests/Unit/ElasticClientFactoryTest.php | 2 +- tests/Unit/FinderTest.php | 4 ++- ...lasticIndexConfigurationRepositoryTest.php | 16 +++++---- .../IndexAliasConfigurationTest.php | 2 +- .../Bulk/BulkUpdateOperationTest.php | 2 +- tests/Unit/ScoutSearchCommandBuilderTest.php | 34 +++++++++---------- 21 files changed, 70 insertions(+), 65 deletions(-) rename tests/{Unit => Support}/ClientExpectation.php (89%) rename tests/{Unit => Support}/FakeElasticResponse.php (92%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eaa6a013..ee6ef869 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: strategy: matrix: - php: [8.0, 8.1, 8.2, 8.3] + php: [8.2, 8.3, 8.4] experimental: [ false ] include: - php: 8.4 diff --git a/.github/workflows/review.yml b/.github/workflows/review.yml index 13eaff32..5c7a7d13 100644 --- a/.github/workflows/review.yml +++ b/.github/workflows/review.yml @@ -10,7 +10,7 @@ jobs: strategy: matrix: - php: [8.1, 8.2, 8.3] + php: [8.2, 8.3, 8.4] name: Mutation Testing Code Review Annotations ${{ matrix.php }} diff --git a/.gitignore b/.gitignore index ca3b3805..efdf54e9 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ /node_modules /report .phpunit.result.cache +.phpunit.cache composer.lock infection.log diff --git a/changelog.md b/changelog.md index 8b32c88c..97dbdbea 100644 --- a/changelog.md +++ b/changelog.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - ElasticSearch 7 support: the elastic 8 client is not backwards compatible. See 'changed' for the breaking changes. - Support for Laravel 9 and below to make package maintenance easier. +- Support for PHP 8.0 and 8.1, as required by Laravel. ### Changed diff --git a/composer.json b/composer.json index b844d049..1818c9f1 100755 --- a/composer.json +++ b/composer.json @@ -12,17 +12,17 @@ "homepage": "https://jeroen-g.github.io/Explorer/", "keywords": ["Laravel", "Scout", "Elasticsearch", "Elastic", "search", "Explorer"], "require": { - "php": "^8.0", + "php": "^8.2", "elasticsearch/elasticsearch": "^8.0", - "illuminate/support": "^9.0||^10.0||^11.0", - "laravel/scout": "^9.0||^10.0||^11.0", + "illuminate/support": "^11.0", + "laravel/scout": "^10.0", "webmozart/assert": "^1.10", - "psr/log": "^1|^2|^3" + "psr/log": "^3" }, "require-dev": { - "phpunit/phpunit": "~9.0", + "phpunit/phpunit": "^10.0", "mockery/mockery": "^1.5", - "infection/infection": "^0.26", + "infection/infection": "^0.29", "symplify/easy-coding-standard": "^9.0", "nunomaduro/larastan": "^2.5", "phpstan/phpstan-mockery": "^1.1", diff --git a/phpunit.xml b/phpunit.xml index 13cd1800..7f922610 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,13 +1,13 @@ - - - - src/ - - + ./tests/Unit + + + src/ + + diff --git a/src/Domain/Syntax/RegExp.php b/src/Domain/Syntax/RegExp.php index db9e4e27..8d2e16d8 100644 --- a/src/Domain/Syntax/RegExp.php +++ b/src/Domain/Syntax/RegExp.php @@ -7,14 +7,14 @@ class RegExp implements SyntaxInterface { private string $field; - + private ?string $value; private string $flags; private bool $insensitive; - public function __construct(string $field, string $value = null, string $flags = 'ALL', bool $insensitive = false) + public function __construct(string $field, ?string $value = null, string $flags = 'ALL', bool $insensitive = false) { $this->field = $field; $this->value = $value; diff --git a/tests/Unit/ClientExpectation.php b/tests/Support/ClientExpectation.php similarity index 89% rename from tests/Unit/ClientExpectation.php rename to tests/Support/ClientExpectation.php index 1cfdd5a6..67069334 100644 --- a/tests/Unit/ClientExpectation.php +++ b/tests/Support/ClientExpectation.php @@ -1,10 +1,9 @@ [$item], $this->getQueryTypes()); + return array_map(fn ($item) => [$item], self::getQueryTypes()); } } diff --git a/tests/Support/SyntaxProvider.php b/tests/Support/SyntaxProvider.php index a70e6a63..94cefdad 100644 --- a/tests/Support/SyntaxProvider.php +++ b/tests/Support/SyntaxProvider.php @@ -10,12 +10,12 @@ trait SyntaxProvider { - public function syntaxProvider(): array + public static function syntaxProvider(): array { - return array_map(fn ($item) => [$item], $this->getSyntaxClasses()); + return array_map(fn ($item) => [$item], self::getSyntaxClasses()); } - public function getSyntaxClasses(): array + public static function getSyntaxClasses(): array { return [ Matching::class, diff --git a/tests/Unit/Domain/Query/QueryProperties/SourceFilterTest.php b/tests/Unit/Domain/Query/QueryProperties/SourceFilterTest.php index b1166992..328f8a5b 100644 --- a/tests/Unit/Domain/Query/QueryProperties/SourceFilterTest.php +++ b/tests/Unit/Domain/Query/QueryProperties/SourceFilterTest.php @@ -21,7 +21,7 @@ public function test_it_builds_empty_array(): void Assert::assertSame([], SourceFilter::empty()->build()); } - public function provideSourceFilterValues(): iterable + public static function provideSourceFilterValues(): iterable { yield 'include 2 fields' => [ [ 'include' => ['a', 'b'] ], diff --git a/tests/Unit/Domain/Query/QueryProperties/TrackTotalHitsTest.php b/tests/Unit/Domain/Query/QueryProperties/TrackTotalHitsTest.php index 15eaec6d..4b52c009 100644 --- a/tests/Unit/Domain/Query/QueryProperties/TrackTotalHitsTest.php +++ b/tests/Unit/Domain/Query/QueryProperties/TrackTotalHitsTest.php @@ -26,7 +26,7 @@ public function test_it_tracks_none(): void Assert::assertSame([ 'track_total_hits' => false ], TrackTotalHits::none()->build()); } - public function provideTrackTotalHitCounts(): iterable + public static function provideTrackTotalHitCounts(): iterable { yield 'count 100' => [100]; yield 'count -100' => [-100]; diff --git a/tests/Unit/Domain/Syntax/SortOrderTest.php b/tests/Unit/Domain/Syntax/SortOrderTest.php index 95ae4b59..b043e901 100644 --- a/tests/Unit/Domain/Syntax/SortOrderTest.php +++ b/tests/Unit/Domain/Syntax/SortOrderTest.php @@ -7,17 +7,17 @@ use PHPUnit\Framework\TestCase; final class SortOrderTest extends TestCase -{ +{ public function test_it_uses_default_missing_when_creating_sort_order(): void { $sort = SortOrder::for(SortOrder::DESCENDING); - + Assert::assertSame([ 'missing' => SortOrder::MISSING_LAST, 'order' => SortOrder::DESCENDING ], $sort->build()); } - + /** * @dataProvider provideSortOrderStrings */ @@ -26,7 +26,7 @@ public function test_sort_order_can_be_created_from_sort_string(string $expected $subject = SortOrder::fromString($sortString); Assert::assertSame($expectedResult, $subject->build()); } - + /** * @dataProvider provideMissingSortOrderStrings */ @@ -35,18 +35,18 @@ public function test_sort_order_can_be_created_from_sort_string_and_missing(arra $subject = SortOrder::for($sortString, $missing); Assert::assertSame($expectedResult, $subject->build()); } - - public function provideSortOrderStrings(): iterable + + public static function provideSortOrderStrings(): iterable { yield 'asc' => ['asc', 'asc']; yield 'desc' => ['desc', 'desc']; } - - public function provideMissingSortOrderStrings(): iterable + + public static function provideMissingSortOrderStrings(): iterable { yield 'asc order with _last missing' => [['missing' => '_last', 'order' => 'asc'], 'asc', '_last']; yield 'desc order with _last missing' => [['missing' => '_last', 'order' => 'desc'], 'desc', '_last']; yield 'asc order with _first missing' => [['missing' => '_first', 'order' => 'asc'], 'asc', '_first']; yield 'desc order with _first missing' => [['missing' => '_first', 'order' => 'desc'], 'desc', '_first']; - } + } } diff --git a/tests/Unit/ElasticClientBuilderTest.php b/tests/Unit/ElasticClientBuilderTest.php index fe62a791..0b11f9d1 100644 --- a/tests/Unit/ElasticClientBuilderTest.php +++ b/tests/Unit/ElasticClientBuilderTest.php @@ -34,7 +34,7 @@ public function test_it_creates_client_with_config(array $config, ClientBuilder self::assertEquals($expectedBuilder, $resultBuilder); } - public function provideClientConfigs(): ?\Generator + public static function provideClientConfigs(): ?\Generator { yield 'simple host' => [ [ diff --git a/tests/Unit/ElasticClientFactoryTest.php b/tests/Unit/ElasticClientFactoryTest.php index 93cc7fa4..3ac52341 100644 --- a/tests/Unit/ElasticClientFactoryTest.php +++ b/tests/Unit/ElasticClientFactoryTest.php @@ -4,13 +4,13 @@ namespace JeroenG\Explorer\Tests\Unit; -use Elastic\Elasticsearch\ClientInterface; use JeroenG\Explorer\Application\SearchCommand; use JeroenG\Explorer\Domain\Query\Query; use JeroenG\Explorer\Domain\Syntax\Compound\BoolQuery; use JeroenG\Explorer\Infrastructure\Elastic\ElasticClientFactory; use JeroenG\Explorer\Infrastructure\Elastic\FakeResponse; use JeroenG\Explorer\Infrastructure\Elastic\Finder; +use JeroenG\Explorer\Tests\Support\ClientExpectation; use Mockery; use Mockery\Adapter\Phpunit\MockeryTestCase; diff --git a/tests/Unit/FinderTest.php b/tests/Unit/FinderTest.php index 9c41f690..3f138636 100644 --- a/tests/Unit/FinderTest.php +++ b/tests/Unit/FinderTest.php @@ -8,6 +8,7 @@ use JeroenG\Explorer\Application\AggregationResult; use JeroenG\Explorer\Application\SearchCommand; use JeroenG\Explorer\Domain\Aggregations\MaxAggregation; +use JeroenG\Explorer\Domain\Aggregations\NestedAggregation; use JeroenG\Explorer\Domain\Aggregations\NestedFilteredAggregation; use JeroenG\Explorer\Domain\Aggregations\TermsAggregation; use JeroenG\Explorer\Domain\Query\Query; @@ -17,8 +18,9 @@ use JeroenG\Explorer\Domain\Syntax\Term; use JeroenG\Explorer\Infrastructure\Elastic\Finder; use JeroenG\Explorer\Infrastructure\Scout\ScoutSearchCommandBuilder; +use JeroenG\Explorer\Tests\Support\ClientExpectation; +use JeroenG\Explorer\Tests\Support\FakeElasticResponse; use Mockery\Adapter\Phpunit\MockeryTestCase; -use JeroenG\Explorer\Domain\Aggregations\NestedAggregation; class FinderTest extends MockeryTestCase { diff --git a/tests/Unit/IndexManagement/ElasticIndexConfigurationRepositoryTest.php b/tests/Unit/IndexManagement/ElasticIndexConfigurationRepositoryTest.php index f0cb6136..1ccc572e 100644 --- a/tests/Unit/IndexManagement/ElasticIndexConfigurationRepositoryTest.php +++ b/tests/Unit/IndexManagement/ElasticIndexConfigurationRepositoryTest.php @@ -13,6 +13,8 @@ use JeroenG\Explorer\Tests\Support\Models\TestModelWithoutSettings; use JeroenG\Explorer\Tests\Support\Models\TestModelWithSettings; use Mockery\Adapter\Phpunit\MockeryTestCase; +use RuntimeException; +use StdClass; final class ElasticIndexConfigurationRepositoryTest extends MockeryTestCase { @@ -105,14 +107,14 @@ public function test_it_can_create_the_configuration_from_a_class_without_settin public function test_it_throws_on_invalid_model(): void { - $indices = [ - self::class - ]; + $indices = [get_class(new StdClass())]; $repository = new ElasticIndexConfigurationRepository($indices); - $this->expectException(\RuntimeException::class); - $this->expectExceptionMessage(sprintf('Unable to create index %s, ensure it implements Explored', self::class)); + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage( + sprintf('Unable to create index %s, ensure it implements Explored', get_class(new StdClass())) + ); iterator_to_array($repository->getConfigurations())[0] ?? null; } @@ -121,12 +123,12 @@ public function test_it_errors_on_invalid_indices($indices, string $error): void { $repository = new ElasticIndexConfigurationRepository($indices); - $this->expectException(\RuntimeException::class); + $this->expectException(RuntimeException::class); $this->expectExceptionMessage($error); iterator_to_array($repository->getConfigurations()); } - public function invalidIndices(): iterable + public static function invalidIndices(): iterable { yield [ [false], diff --git a/tests/Unit/IndexManagement/IndexAliasConfigurationTest.php b/tests/Unit/IndexManagement/IndexAliasConfigurationTest.php index 046503dc..004d239e 100644 --- a/tests/Unit/IndexManagement/IndexAliasConfigurationTest.php +++ b/tests/Unit/IndexManagement/IndexAliasConfigurationTest.php @@ -34,7 +34,7 @@ public function test_it_can_get_the_different_aliases(string $alias, string $met self::assertSame("shipIt-$alias", $config->$method()); } - public function aliasProvider(): \Generator + public static function aliasProvider(): \Generator { yield ['history', 'getHistoryAliasName']; yield ['write', 'getWriteAliasName']; diff --git a/tests/Unit/Operations/Bulk/BulkUpdateOperationTest.php b/tests/Unit/Operations/Bulk/BulkUpdateOperationTest.php index aff04117..d5133870 100644 --- a/tests/Unit/Operations/Bulk/BulkUpdateOperationTest.php +++ b/tests/Unit/Operations/Bulk/BulkUpdateOperationTest.php @@ -57,7 +57,7 @@ public function test_it_builds_from_sources($input): void ], $operation->build()); } - public function iterableInputDataProvider(): \Generator + public static function iterableInputDataProvider(): \Generator { yield 'collection' => [collect([new TestModelWithoutSettings()])]; yield 'array' => [[new TestModelWithoutSettings()]]; diff --git a/tests/Unit/ScoutSearchCommandBuilderTest.php b/tests/Unit/ScoutSearchCommandBuilderTest.php index 49358416..309f1506 100644 --- a/tests/Unit/ScoutSearchCommandBuilderTest.php +++ b/tests/Unit/ScoutSearchCommandBuilderTest.php @@ -102,7 +102,7 @@ public function test_it_works_with_setters_and_getters(string $method, mixed $ex self::assertSame($expected, $command->$getter()); } - public function buildCommandProvider(): array + public static function buildCommandProvider(): array { return [ ['Must', [new Term('field', 'value')]], @@ -140,44 +140,44 @@ public function test_it_can_set_the_sort_order(): void $command->setSort([new Sort('id', 'invalid')]); } - + public function test_it_can_set_the_sort_order_as_array(): void { $command = new ScoutSearchCommandBuilder(); - + self::assertFalse($command->hasSort()); - + $command->setSort([new Sort('id')]); - + self::assertTrue($command->hasSort()); self::assertSame([['id' => 'asc']], $command->getSort()); - + $command->setSort([]); - + self::assertFalse($command->hasSort()); self::assertSame([], $command->getSort()); - + $command->setSort([new Sort('id', SortOrder::for('desc'))]); - + self::assertTrue($command->hasSort()); self::assertSame([['id' => ['missing' => '_last', 'order' => 'desc']]], $command->getSort()); - + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Expected one of: "asc", "desc". Got: "invalid"'); - + $command->setSort([new Sort('id', SortOrder::for('invalid'))]); } - + public function test_it_throws_exception_when_missing_is_invalid(): void { $command = new ScoutSearchCommandBuilder(); - + $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('Expected one of: "_first", "_last". Got: "invalid"'); - + $command->setSort([new Sort('id', SortOrder::for('desc', 'invalid'))]); } - + public function test_it_only_accepts_sort_classes(): void { $command = new ScoutSearchCommandBuilder(); @@ -289,7 +289,7 @@ public function test_it_respects_minimum_should_match_on_custom_compound(): void ]; self::assertEquals($expectedQuery, $query); - } + } public function test_it_has_bool_query_as_default_compound(): void { @@ -443,7 +443,7 @@ public function test_it_wraps_a_compound_using_minimum_should_match(): void ]; self::assertEquals($expectedQuery, $query); - } + } public function test_it_wraps_scout_builder_query_properties(): void {