From 031ed8cde3d74a7798cdd8e8a152a302c7571e04 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Thu, 28 Sep 2023 08:44:12 -0300 Subject: [PATCH 1/6] Raise min version to `PHP 7.3`, check compatibility `PHP 8.3`. --- .github/workflows/build.yml | 29 ++++++++++++++++++++++------ composer.json | 6 +++--- tests/ActiveDataProviderTest.php | 2 +- tests/ActiveQueryTest.php | 4 ++-- tests/ActiveRecordTest.php | 6 +++--- tests/ActiveRecordTestTrait.php | 5 +++-- tests/CommandTest.php | 2 +- tests/ConnectionTest.php | 2 +- tests/ElasticsearchTargetTest.php | 4 ++-- tests/QueryBuilderTest.php | 2 +- tests/QueryTest.php | 3 ++- tests/TestCase.php | 10 ++-------- tests/compatibility.php | 32 ------------------------------- 13 files changed, 44 insertions(+), 63 deletions(-) delete mode 100644 tests/compatibility.php diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b5817fda3..324196aef 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,6 +1,23 @@ on: - - pull_request - - push + pull_request: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'psalm.xml' + + push: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'psalm.xml' name: build @@ -16,12 +33,12 @@ jobs: strategy: matrix: php-version: - - 5.6 - - 7.0 - - 7.1 - - 7.2 - 7.3 - 7.4 + - 8.0 + - 8.1 + - 8.2 + - 8.3 es-version: - 8.1.3 diff --git a/composer.json b/composer.json index 1b15a6f17..789915797 100644 --- a/composer.json +++ b/composer.json @@ -18,14 +18,14 @@ } ], "require": { - "yiisoft/yii2": "~2.0.14", + "php": ">=7.3", "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", - "paragonie/random_compat": ">=1" + "yiisoft/yii2": "~2.0.14" }, "require-dev": { - "phpunit/phpunit": "4.8.27|~5.7.21|^6.2" + "phpunit/phpunit": "^9.6" }, "autoload": { "psr-4": { "yii\\elasticsearch\\": "" } diff --git a/tests/ActiveDataProviderTest.php b/tests/ActiveDataProviderTest.php index 6b6bad943..100dffbcd 100644 --- a/tests/ActiveDataProviderTest.php +++ b/tests/ActiveDataProviderTest.php @@ -10,7 +10,7 @@ class ActiveDataProviderTest extends TestCase { - public function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/tests/ActiveQueryTest.php b/tests/ActiveQueryTest.php index 9d66b4a71..46f114b89 100644 --- a/tests/ActiveQueryTest.php +++ b/tests/ActiveQueryTest.php @@ -9,7 +9,7 @@ */ class ActiveQueryTest extends TestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -42,4 +42,4 @@ public function testColumn() $result = $activeQuery->scalar('name', $this->getConnection()); $this->assertEquals('item1', $result); } -} \ No newline at end of file +} diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php index b6fffb8eb..498065474 100644 --- a/tests/ActiveRecordTest.php +++ b/tests/ActiveRecordTest.php @@ -43,7 +43,7 @@ public function getOrderItemClass() return OrderItem::className(); } - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -163,7 +163,7 @@ public function testSearch() $this->assertTrue($customer instanceof Customer); $this->assertEquals(2, $customer->_id); } - + public function testSuggestion() { $result = Customer::find()->addSuggester('customer_name', [ @@ -175,7 +175,7 @@ public function testSuggestion() $this->assertCount(3, $result['suggest']['customer_name'][0]['options']); } - + public function testGetDb() { $this->mockApplication(['components' => ['elasticsearch' => Connection::className()]]); diff --git a/tests/ActiveRecordTestTrait.php b/tests/ActiveRecordTestTrait.php index 1cc153031..deb198181 100644 --- a/tests/ActiveRecordTestTrait.php +++ b/tests/ActiveRecordTestTrait.php @@ -1141,13 +1141,14 @@ public function testViaWithCallable() $cheapItems = $order->cheapItemsUsingViaWithCallable; $this->assertCount(2, $expensiveItems); + $expensiveItemIds = [ $expensiveItems[0]->_id, $expensiveItems[1]->_id, ]; - $this->assertContains(4, $expensiveItemIds); - $this->assertContains(5, $expensiveItemIds); + $this->assertContains('4', $expensiveItemIds); + $this->assertContains('5', $expensiveItemIds); $this->assertCount(1, $cheapItems); $this->assertEquals(3, $cheapItems[0]->_id); } diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 231191a06..d57a89993 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -13,7 +13,7 @@ class CommandTest extends TestCase /** @var Command */ private $command; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->command = $this->getConnection()->createCommand(); diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index 0005d9ba1..aafe7cc49 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -14,7 +14,7 @@ class ConnectionTest extends TestCase */ private $connection; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->connection = $this->getConnection(); diff --git a/tests/ElasticsearchTargetTest.php b/tests/ElasticsearchTargetTest.php index 766e5bf8b..cf30b4657 100644 --- a/tests/ElasticsearchTargetTest.php +++ b/tests/ElasticsearchTargetTest.php @@ -36,7 +36,7 @@ public function testExport() $this->assertArrayHasKey('category', $source); } - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -61,7 +61,7 @@ protected function setUp() ]); } - protected function tearDown() + protected function tearDown(): void { $command = $this->getConnection()->createCommand(); $command->deleteIndex($this->index); diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index f72a728ad..34f0498ff 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -15,7 +15,7 @@ class QueryBuilderTest extends TestCase */ private $version; - public function setUp() + protected function setUp(): void { parent::setUp(); $command = $this->getConnection()->createCommand(); diff --git a/tests/QueryTest.php b/tests/QueryTest.php index c2751332d..f5d05d5c5 100644 --- a/tests/QueryTest.php +++ b/tests/QueryTest.php @@ -9,7 +9,7 @@ */ class QueryTest extends TestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -457,6 +457,7 @@ public function testRuntimeMappings() // Check that Elasticsearch is version 7.11.0 or later before running this test $elasticsearchInfo = $this->getConnection()->get('/'); if(!version_compare($elasticsearchInfo['version']['number'], '7.11.0', '>=')) { + $this->expectNotToPerformAssertions(); return; } diff --git a/tests/TestCase.php b/tests/TestCase.php index f7a821d6c..19df6ed0e 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -7,12 +7,6 @@ use yii\helpers\ArrayHelper; use Yii; -// backward compatibility -if (!class_exists('\PHPUnit\Framework\TestCase')) { - class_alias('\PHPUnit_Framework_TestCase', '\PHPUnit\Framework\TestCase'); -} - - /** * This is the base class for all yii framework unit tests. */ @@ -40,7 +34,7 @@ public static function getParam($name, $default = null) * Clean up after test. * By default the application created with [[mockApplication]] will be destroyed. */ - protected function tearDown() + protected function tearDown(): void { parent::tearDown(); $this->destroyApplication(); @@ -86,7 +80,7 @@ protected function destroyApplication() Yii::$container = new Container(); } - protected function setUp() + protected function setUp(): void { $this->mockApplication(); diff --git a/tests/compatibility.php b/tests/compatibility.php deleted file mode 100644 index f7fd3f29d..000000000 --- a/tests/compatibility.php +++ /dev/null @@ -1,32 +0,0 @@ -setExpectedException($exception); - } - - /** - * @param string $message - */ - public function expectExceptionMessage($message) - { - $this->setExpectedException($this->getExpectedException(), $message); - } - } - } -} From d6d9a350dfa41f60c16d731aba3d407266341800 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Fri, 29 Sep 2023 13:24:20 -0300 Subject: [PATCH 2/6] Fix minor corrections. --- .editorconfig | 3 ++ .github/workflows/build.yml | 66 ++++++++++++++++++++++--------------- phpunit.xml.dist | 37 ++++++++++++++------- 3 files changed, 68 insertions(+), 38 deletions(-) diff --git a/.editorconfig b/.editorconfig index 257221d23..5e9a93ea5 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,3 +12,6 @@ trim_trailing_whitespace = true [*.md] trim_trailing_whitespace = false + +[*.yml] +indent_size = 2 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 324196aef..0ab62cb18 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,38 +1,38 @@ on: - pull_request: - paths-ignore: - - 'docs/**' - - 'README.md' - - 'CHANGELOG.md' - - '.gitignore' - - '.gitattributes' - - 'infection.json.dist' - - 'psalm.xml' - - push: - paths-ignore: - - 'docs/**' - - 'README.md' - - 'CHANGELOG.md' - - '.gitignore' - - '.gitattributes' - - 'infection.json.dist' - - 'psalm.xml' + pull_request: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'psalm.xml' + + push: + paths-ignore: + - 'docs/**' + - 'README.md' + - 'CHANGELOG.md' + - '.gitignore' + - '.gitattributes' + - 'infection.json.dist' + - 'psalm.xml' name: build jobs: tests: - name: PHP ${{ matrix.php-version }} / ES ${{ matrix.es-version }} + name: PHP ${{ matrix.php }} / ES ${{ matrix.es }} + env: extensions: curl, mbstring, dom, intl - key: cache-v1 runs-on: ubuntu-latest strategy: matrix: - php-version: + php: - 7.3 - 7.4 - 8.0 @@ -40,7 +40,7 @@ jobs: - 8.2 - 8.3 - es-version: + es: - 8.1.3 - 7.14.0 - 7.7.0 @@ -49,13 +49,13 @@ jobs: steps: - name: Service elastisearch 8.1.3. - if: matrix.es-version == '8.1.3' + if: matrix.es == '8.1.3' run: | docker network create somenetwork docker run -d --name elasticsearch --net somenetwork -p 9200:9200 -e "http.publish_host=127.0.0.1" -e "transport.host=127.0.0.1" -e "indices.id_field_data.enabled=true" -e "xpack.security.enabled=false" elasticsearch:${{ matrix.es-version }} - name: Service elastisearch < 8.1.3. - if: matrix.es-version != '8.1.3' + if: matrix.es != '8.1.3' run: | docker network create somenetwork docker run -d --name elasticsearch --net somenetwork -p 9200:9200 -e "http.publish_host=127.0.0.1" -e "transport.host=127.0.0.1" elasticsearch:${{ matrix.es-version }} @@ -66,7 +66,7 @@ jobs: - name: Install PHP with extensions. uses: shivammathur/setup-php@v2 with: - php-version: ${{ matrix.php-version }} + php-version: ${{ matrix.php }} extensions: ${{ env.extensions }} ini-values: date.timezone='UTC' @@ -77,4 +77,16 @@ jobs: run: wget --retry-connrefused --waitretry=3 --timeout=30 -t 10 -O /dev/null http://127.0.0.1:9200 - name: Run tests with phpunit. - run: ES_VERSION=${{ matrix.es-version }} vendor/bin/phpunit + if: matrix.php != '8.1' + run: ES_VERSION=${{ matrix.es }} vendor/bin/phpunit --colors=always + + - name: Run tests with phpunit and generate coverage. + if: matrix.php == '8.1' + run: ES_VERSION=${{ matrix.es }} vendor/bin/phpunit --coverage-clover=coverage.xml --colors=always + + - name: Upload coverage to Codecov. + if: matrix.php == '8.1' + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + file: ./coverage.xml diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 3a3db9fac..bda5353e6 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,13 +1,28 @@ - - - - ./tests - - + + + + + + + + + ./tests + + + + + + ./src + + + From f3352ed68cbbf1c97334d057bb5e8f93327f7473 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Fri, 29 Sep 2023 13:26:32 -0300 Subject: [PATCH 3/6] fix error typo. --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0ab62cb18..746c99dc3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -58,7 +58,7 @@ jobs: if: matrix.es != '8.1.3' run: | docker network create somenetwork - docker run -d --name elasticsearch --net somenetwork -p 9200:9200 -e "http.publish_host=127.0.0.1" -e "transport.host=127.0.0.1" elasticsearch:${{ matrix.es-version }} + docker run -d --name elasticsearch --net somenetwork -p 9200:9200 -e "http.publish_host=127.0.0.1" -e "transport.host=127.0.0.1" elasticsearch:${{ matrix.es }} - name: Checkout. uses: actions/checkout@v3 From b1f3ef5a1f6877b10d5ca96eedf74725750da727 Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Fri, 29 Sep 2023 13:27:31 -0300 Subject: [PATCH 4/6] Fix error typo. --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 746c99dc3..8918cc6c0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -52,7 +52,7 @@ jobs: if: matrix.es == '8.1.3' run: | docker network create somenetwork - docker run -d --name elasticsearch --net somenetwork -p 9200:9200 -e "http.publish_host=127.0.0.1" -e "transport.host=127.0.0.1" -e "indices.id_field_data.enabled=true" -e "xpack.security.enabled=false" elasticsearch:${{ matrix.es-version }} + docker run -d --name elasticsearch --net somenetwork -p 9200:9200 -e "http.publish_host=127.0.0.1" -e "transport.host=127.0.0.1" -e "indices.id_field_data.enabled=true" -e "xpack.security.enabled=false" elasticsearch:${{ matrix.es }} - name: Service elastisearch < 8.1.3. if: matrix.es != '8.1.3' From 40094e9445b60571eaf5ec36a0a60cac9f4c059c Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Fri, 29 Sep 2023 13:44:49 -0300 Subject: [PATCH 5/6] Move files to `src`. --- composer.json | 2 +- ActiveDataProvider.php => src/ActiveDataProvider.php | 0 ActiveFixture.php => src/ActiveFixture.php | 0 ActiveQuery.php => src/ActiveQuery.php | 0 ActiveRecord.php => src/ActiveRecord.php | 0 BatchQueryResult.php => src/BatchQueryResult.php | 0 BulkCommand.php => src/BulkCommand.php | 0 Command.php => src/Command.php | 0 Connection.php => src/Connection.php | 0 DebugAction.php => src/DebugAction.php | 0 DebugPanel.php => src/DebugPanel.php | 0 ElasticsearchTarget.php => src/ElasticsearchTarget.php | 0 Exception.php => src/Exception.php | 0 Query.php => src/Query.php | 0 QueryBuilder.php => src/QueryBuilder.php | 0 15 files changed, 1 insertion(+), 1 deletion(-) rename ActiveDataProvider.php => src/ActiveDataProvider.php (100%) rename ActiveFixture.php => src/ActiveFixture.php (100%) rename ActiveQuery.php => src/ActiveQuery.php (100%) rename ActiveRecord.php => src/ActiveRecord.php (100%) rename BatchQueryResult.php => src/BatchQueryResult.php (100%) rename BulkCommand.php => src/BulkCommand.php (100%) rename Command.php => src/Command.php (100%) rename Connection.php => src/Connection.php (100%) rename DebugAction.php => src/DebugAction.php (100%) rename DebugPanel.php => src/DebugPanel.php (100%) rename ElasticsearchTarget.php => src/ElasticsearchTarget.php (100%) rename Exception.php => src/Exception.php (100%) rename Query.php => src/Query.php (100%) rename QueryBuilder.php => src/QueryBuilder.php (100%) diff --git a/composer.json b/composer.json index 789915797..2da5aee7a 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "phpunit/phpunit": "^9.6" }, "autoload": { - "psr-4": { "yii\\elasticsearch\\": "" } + "psr-4": { "yii\\elasticsearch\\": "src" } }, "config": { "allow-plugins": { diff --git a/ActiveDataProvider.php b/src/ActiveDataProvider.php similarity index 100% rename from ActiveDataProvider.php rename to src/ActiveDataProvider.php diff --git a/ActiveFixture.php b/src/ActiveFixture.php similarity index 100% rename from ActiveFixture.php rename to src/ActiveFixture.php diff --git a/ActiveQuery.php b/src/ActiveQuery.php similarity index 100% rename from ActiveQuery.php rename to src/ActiveQuery.php diff --git a/ActiveRecord.php b/src/ActiveRecord.php similarity index 100% rename from ActiveRecord.php rename to src/ActiveRecord.php diff --git a/BatchQueryResult.php b/src/BatchQueryResult.php similarity index 100% rename from BatchQueryResult.php rename to src/BatchQueryResult.php diff --git a/BulkCommand.php b/src/BulkCommand.php similarity index 100% rename from BulkCommand.php rename to src/BulkCommand.php diff --git a/Command.php b/src/Command.php similarity index 100% rename from Command.php rename to src/Command.php diff --git a/Connection.php b/src/Connection.php similarity index 100% rename from Connection.php rename to src/Connection.php diff --git a/DebugAction.php b/src/DebugAction.php similarity index 100% rename from DebugAction.php rename to src/DebugAction.php diff --git a/DebugPanel.php b/src/DebugPanel.php similarity index 100% rename from DebugPanel.php rename to src/DebugPanel.php diff --git a/ElasticsearchTarget.php b/src/ElasticsearchTarget.php similarity index 100% rename from ElasticsearchTarget.php rename to src/ElasticsearchTarget.php diff --git a/Exception.php b/src/Exception.php similarity index 100% rename from Exception.php rename to src/Exception.php diff --git a/Query.php b/src/Query.php similarity index 100% rename from Query.php rename to src/Query.php diff --git a/QueryBuilder.php b/src/QueryBuilder.php similarity index 100% rename from QueryBuilder.php rename to src/QueryBuilder.php From 2333f8907d0c22c30baf72f836524b06abd2ff5b Mon Sep 17 00:00:00 2001 From: Wilmer Arambula Date: Fri, 29 Sep 2023 13:48:32 -0300 Subject: [PATCH 6/6] Update `README.md`. --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 75cbce045..ffc46209e 100644 --- a/README.md +++ b/README.md @@ -17,10 +17,13 @@ Documentation is at [docs/guide/README.md](docs/guide/README.md). [![Latest Stable Version](https://poser.pugx.org/yiisoft/yii2-elasticsearch/v/stable.png)](https://packagist.org/packages/yiisoft/yii2-elasticsearch) [![Total Downloads](https://poser.pugx.org/yiisoft/yii2-elasticsearch/downloads.png)](https://packagist.org/packages/yiisoft/yii2-elasticsearch) [![Build Status](https://travis-ci.com/yiisoft/yii2-elasticsearch.svg?branch=master)](https://travis-ci.com/yiisoft/yii2-elasticsearch) +[![codecov](https://codecov.io/gh/yiisoft/yii2-elasticsearch/graph/badge.svg?token=oi71bPc1SU)](https://codecov.io/gh/yiisoft/yii2-elasticsearch) Requirements ------------ +- PHP 7.3 or higher. + Depending on the version of Elasticsearch you are using you need a different version of this extension. - For Elasticsearch 1.6.0 to 1.7.6 use extension version 2.0.x