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 73f47542d..0ec1405f8 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 @@ -17,23 +34,20 @@ jobs: strategy: matrix: os: - - ubuntu-18.04 + - ubuntu-latest php: - - "5.4" - - "5.5" - - "5.6" - - "7.0" - - "7.1" - - "7.2" - - "7.3" - - "7.4" + - 7.4 + - 8.0 + - 8.1 + - 8.2 + - 8.3 steps: - - name: Checkout - uses: actions/checkout@v2.3.4 + - name: Checkout. + uses: actions/checkout@v3 - - name: Install PHP + - name: Install PHP. uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} @@ -42,36 +56,32 @@ jobs: coverage: pcov tools: composer:v2 - - name: Update composer + - name: Update composer. run: composer self-update - - name: Install dependencies with composer php < 8.0 - if: matrix.php != '8.0' + - name: Install dependencies with composer. run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - name: Install dependencies with composer php 8.0 - if: matrix.php == '8.0' - run: composer update --ignore-platform-reqs --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi - - - name: Setup source database + - name: Setup source database. run: | sudo /etc/init.d/mysql start mysql -uroot -proot -e 'CREATE DATABASE `yiitest`;' mysql -D yiitest -uroot -proot < tests/data/source.sql - - name: Install sphinx + - name: Install sphinx. run: cd tests/data/actions && sh sphinx-setup.sh - - name: Run tests with phpunit - if: matrix.php != '7.4' + - name: Run tests with phpunit. + if: matrix.php != '8.1' run: vendor/bin/phpunit --colors=always - - name: Run tests with phpunit - if: matrix.php == '7.4' - run: vendor/bin/phpunit --coverage-clover=clover.xml --colors=always + - name: Run tests with phpunit and generate coverage. + if: matrix.php == '8.1' + run: vendor/bin/phpunit --coverage-clover=coverage.xml --colors=always - - name: Upload code coverage scrutinizer - if: matrix.php == '7.4' - run: | - wget https://scrutinizer-ci.com/ocular.phar - php ocular.phar code-coverage:upload --format=php-clover coverage.clover + - 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/README.md b/README.md index c63740213..dfed424ea 100644 --- a/README.md +++ b/README.md @@ -16,15 +16,16 @@ Documentation is at [docs/guide/README.md](docs/guide/README.md). [![Latest Stable Version](https://poser.pugx.org/yiisoft/yii2-sphinx/v/stable.png)](https://packagist.org/packages/yiisoft/yii2-sphinx) [![Total Downloads](https://poser.pugx.org/yiisoft/yii2-sphinx/downloads.png)](https://packagist.org/packages/yiisoft/yii2-sphinx) [![Build status](https://github.com/yiisoft/yii2-sphinx/workflows/build/badge.svg)](https://github.com/yiisoft/yii2-sphinx/actions?query=workflow%3Abuild) +[![codecov](https://codecov.io/gh/yiisoft/yii2-sphinx/graph/badge.svg?token=eEgiSUaKxc)](https://codecov.io/gh/yiisoft/yii2-sphinx) Requirements ------------ -At least Sphinx version 2.0 is required. However, in order to use all extension features, Sphinx version 2.2.3 or +- PHP 7.3 or higher. +- At least Sphinx version 2.0 is required. However, in order to use all extension features, Sphinx version 2.2.3 or higher is required. - Installation ------------ diff --git a/composer.json b/composer.json index 447f29a8e..a26eeb141 100644 --- a/composer.json +++ b/composer.json @@ -18,12 +18,13 @@ } ], "require": { - "yiisoft/yii2": "~2.0.13", + "php": ">=7.3", "ext-pdo": "*", - "ext-pdo_mysql": "*" + "ext-pdo_mysql": "*", + "yiisoft/yii2": "~2.0.13" }, "require-dev": { - "phpunit/phpunit": "4.8.27|~5.7.21|^6.2" + "phpunit/phpunit": "^9.6" }, "repositories": [ { @@ -38,5 +39,10 @@ "branch-alias": { "dev-master": "2.0.x-dev" } + }, + "config": { + "allow-plugins": { + "yiisoft/yii2-composer": true + } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b977e1d9c..438a71f33 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,13 +1,27 @@ - - - - ./tests - - + + + + + + + + + ./tests + + + + + + ./src + + diff --git a/tests/ActiveDataProviderTest.php b/tests/ActiveDataProviderTest.php index 75c4efac8..9a0c7cec9 100644 --- a/tests/ActiveDataProviderTest.php +++ b/tests/ActiveDataProviderTest.php @@ -14,7 +14,7 @@ */ class ActiveDataProviderTest extends TestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); ActiveRecord::$db = $this->getConnection(); diff --git a/tests/ActiveFixtureTest.php b/tests/ActiveFixtureTest.php index db88cc148..10ed7e310 100644 --- a/tests/ActiveFixtureTest.php +++ b/tests/ActiveFixtureTest.php @@ -11,7 +11,7 @@ class ActiveFixtureTest extends TestCase { - public function setUp() + protected function setUp(): void { parent::setUp(); \Yii::$app->set('sphinx', $this->getConnection()); diff --git a/tests/ActiveQueryTest.php b/tests/ActiveQueryTest.php index ceefe821d..350658d32 100644 --- a/tests/ActiveQueryTest.php +++ b/tests/ActiveQueryTest.php @@ -10,7 +10,7 @@ */ class ActiveQueryTest extends TestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); ActiveRecord::$db = $this->getConnection(); @@ -31,10 +31,10 @@ public function testFacet() $this->assertTrue($results['hits'][0] instanceof ArticleIndex, 'Unable to populate results as AR object'); } - public function testIndexBy() + public function testIndexBy() { $results = ArticleIndex::find()->indexBy('id')->all(); - $result = reset($results); + $result = reset($results); $this->assertTrue($result->id == key($results), 'Unable to index results by column'); } } diff --git a/tests/ActiveRecordTest.php b/tests/ActiveRecordTest.php index a6075f6a2..6dac96a1c 100644 --- a/tests/ActiveRecordTest.php +++ b/tests/ActiveRecordTest.php @@ -12,13 +12,13 @@ */ class ActiveRecordTest extends TestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); ActiveRecord::$db = $this->getConnection(); } - protected function tearDown() + protected function tearDown(): void { $this->truncateIndex('yii2_test_rt_index'); parent::tearDown(); @@ -262,11 +262,11 @@ public function testCallSnippets() $snippet = ArticleIndex::callSnippets($source, $query); $this->assertNotEmpty($snippet, 'Unable to call snippets!'); - $this->assertContains('' . $query . '', $snippet, 'Query not present in the snippet!'); + $this->assertStringContainsString('' . $query . '', $snippet, 'Query not present in the snippet!'); $rows = ArticleIndex::callSnippets([$source], $query); $this->assertNotEmpty($rows, 'Unable to call snippets!'); - $this->assertContains('' . $query . '', $rows[0], 'Query not present in the snippet!'); + $this->assertStringContainsString('' . $query . '', $rows[0], 'Query not present in the snippet!'); } public function testCallKeywords() @@ -371,4 +371,4 @@ public function testEmulateExecution() ->search(); $this->assertSame(['hits' => [], 'facets' => [], 'meta' => []], $rows); } -} \ No newline at end of file +} diff --git a/tests/ActiveRelationTest.php b/tests/ActiveRelationTest.php index 11b89d41d..03b2ca4e2 100644 --- a/tests/ActiveRelationTest.php +++ b/tests/ActiveRelationTest.php @@ -12,7 +12,7 @@ */ class ActiveRelationTest extends TestCase { - protected function setUp() + protected function setUp(): void { parent::setUp(); ActiveRecord::$db = $this->getConnection(); diff --git a/tests/BatchQueryResultTest.php b/tests/BatchQueryResultTest.php index a637ce841..443648ebf 100644 --- a/tests/BatchQueryResultTest.php +++ b/tests/BatchQueryResultTest.php @@ -10,7 +10,7 @@ class BatchQueryResultTest extends TestCase { - public function setUp() + protected function setUp(): void { parent::setUp(); ActiveRecord::$db = $this->getConnection(); @@ -154,4 +154,4 @@ public function testActiveQuery() $this->assertCount(2, $allModels[1]->tags); $this->assertCount(0, $allModels[2]->tags); } -} \ No newline at end of file +} diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 7b892e33e..aa2f4e058 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -9,7 +9,7 @@ */ class CommandTest extends TestCase { - protected function tearDown() + protected function tearDown(): void { $this->truncateIndex('yii2_test_rt_index'); parent::tearDown(); @@ -373,7 +373,7 @@ public function testCallSnippets() $rows = $db->createCommand()->callSnippets('yii2_test_item_index', $source, $query)->queryColumn(); $this->assertNotEmpty($rows, 'Unable to call snippets!'); - $this->assertContains('' . $query . '', $rows[0], 'Query not present in the snippet!'); + $this->assertStringContainsString('' . $query . '', $rows[0], 'Query not present in the snippet!'); $rows = $db->createCommand()->callSnippets('yii2_test_item_index', [$source], $query)->queryColumn(); $this->assertNotEmpty($rows, 'Unable to call snippets for array source!'); @@ -384,7 +384,11 @@ public function testCallSnippets() 'limit' => 20, ]; $snippet = $db->createCommand()->callSnippets('yii2_test_item_index', $source, $query, $options)->queryScalar(); - $this->assertContains($options['before_match'] . $query . $options['after_match'], $snippet, 'Unable to apply options!'); + $this->assertStringContainsString( + $options['before_match'] . $query . $options['after_match'], + $snippet, + 'Unable to apply options!', + ); } /** diff --git a/tests/ExternalActiveRelationTest.php b/tests/ExternalActiveRelationTest.php index d56b61f63..1793d2c13 100644 --- a/tests/ExternalActiveRelationTest.php +++ b/tests/ExternalActiveRelationTest.php @@ -16,7 +16,7 @@ class ExternalActiveRelationTest extends TestCase /** * {@inheritdoc} */ - protected function setUp() + protected function setUp(): void { parent::setUp(); ActiveRecord::$db = $this->getConnection(); diff --git a/tests/QueryTest.php b/tests/QueryTest.php index 2ff9b16dc..1786d1cfe 100644 --- a/tests/QueryTest.php +++ b/tests/QueryTest.php @@ -18,8 +18,8 @@ public function testSelect() $query = new Query(); $query->select('*'); $this->assertEquals(['*' => '*'], $query->select); - $this->assertNull($query->distinct); - $this->assertEquals(null, $query->selectOption); + $this->assertFalse($query->distinct); + $this->assertNull($query->selectOption); $query = new Query(); $query->select('id, name', 'something')->distinct(true); @@ -43,7 +43,7 @@ public function testMatch() $this->assertEquals($match, $query->match); $command = $query->createCommand($this->getConnection(false)); - $this->assertContains('MATCH(', $command->getSql(), 'No MATCH operator present!'); + $this->assertStringContainsString('MATCH(', $command->getSql(), 'No MATCH operator present!'); $this->assertContains($match, $command->params, 'No match query among params!'); } @@ -73,7 +73,7 @@ public function testWhereExpression() $query->where($expression); $command = $query->createCommand($this->getConnection(false)); - $this->assertContains($expression->expression, $command->getSql()); + $this->assertStringContainsString($expression->expression, $command->getSql()); $this->assertEquals($expression->params, $command->params); } @@ -271,8 +271,11 @@ public function testSnippet() ->all($connection); $this->assertNotEmpty($rows); foreach ($rows as $row) { - $this->assertContains($snippetPrefix, $row['snippet'], 'Snippet source not present!'); - $this->assertContains($snippetOptions['before_match'] . $match, $row['snippet'] . $snippetOptions['after_match'], 'Options not applied!'); + $this->assertStringContainsString($snippetPrefix, $row['snippet'], 'Snippet source not present!'); + $this->assertStringContainsString( + $snippetOptions['before_match'] . $match, $row['snippet'] . $snippetOptions['after_match'], + 'Options not applied!', + ); } // @see https://github.com/yiisoft/yii2-sphinx/issues/61 @@ -284,8 +287,11 @@ public function testSnippet() ->all($connection); $this->assertNotEmpty($rows); foreach ($rows as $row) { - $this->assertContains($snippetPrefix, $row['snippet'], 'Snippet source not present!'); - $this->assertContains($snippetOptions['before_match'] . $match, $row['snippet'] . $snippetOptions['after_match'], 'Options not applied!'); + $this->assertStringContainsString($snippetPrefix, $row['snippet'], 'Snippet source not present!'); + $this->assertStringContainsString( + $snippetOptions['before_match'] . $match, $row['snippet'] . $snippetOptions['after_match'], + 'Options not applied!', + ); } // @see https://github.com/yiisoft/yii2-sphinx/pull/93 diff --git a/tests/TestCase.php b/tests/TestCase.php index ec1972e9c..b474e5333 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -38,13 +38,13 @@ class TestCase extends \PHPUnit\Framework\TestCase */ protected $db; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->sphinxConfig = self::getParam('sphinx'); $this->dbConfig = self::getParam('db'); - + $this->assertTrue(extension_loaded('pdo') && extension_loaded('pdo_mysql'), 'pdo and pdo_mysql extension are required.'); // check whether sphinx is running @@ -57,7 +57,7 @@ protected function setUp() $this->mockApplication(); } - protected function tearDown() + protected function tearDown(): void { if ($this->sphinx) { $this->sphinx->close(); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 9368de923..87ffde790 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -13,5 +13,3 @@ Yii::setAlias('@yiiunit/extensions/sphinx', __DIR__); Yii::setAlias('@yii/sphinx', dirname(__DIR__) . '/src'); - -require_once(__DIR__ . '/compatibility.php'); \ No newline at end of file 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); - } - } - } -} diff --git a/tests/data/actions/sphinx-setup.sh b/tests/data/actions/sphinx-setup.sh index 4e67fdb42..aa3508ab5 100644 --- a/tests/data/actions/sphinx-setup.sh +++ b/tests/data/actions/sphinx-setup.sh @@ -2,6 +2,14 @@ SCRIPT=$(readlink -f "$0") CWD=$(dirname "$SCRIPT") +# install mysql client library +echo 'deb http://security.ubuntu.com/ubuntu xenial-security main' | sudo tee /etc/apt/sources.list.d/xenial-security.list +sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 40976EAF437D05B5 +sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32 +sudo apt update +sudo apt install libmysqlclient20 +sudo apt-get install libodbc1 + # install sphinx from https://sphinxsearch.com/downloads/release/ wget http://sphinxsearch.com/files/sphinxsearch_2.2.11-release-1~xenial_amd64.deb sudo dpkg -i sphinxsearch_2.2.11-release-1~xenial_amd64.deb diff --git a/tests/data/fixture/MySphinxTestCase.php b/tests/data/fixture/MySphinxTestCase.php index 9efccd01e..87040bac2 100644 --- a/tests/data/fixture/MySphinxTestCase.php +++ b/tests/data/fixture/MySphinxTestCase.php @@ -5,17 +5,17 @@ use yii\test\FixtureTrait; use yiiunit\extensions\sphinx\data\fixture\RtIndexFixture; -class MySphinxTestCase +class MySphinxTestCase extends \yiiunit\extensions\sphinx\TestCase { use FixtureTrait; - public function setUp() + protected function setUp(): void { $this->unloadFixtures(); $this->loadFixtures(); } - public function tearDown() + protected function tearDown(): void { } diff --git a/tests/data/travis/README.md b/tests/data/travis/README.md deleted file mode 100644 index 8cfcfe2c8..000000000 --- a/tests/data/travis/README.md +++ /dev/null @@ -1,8 +0,0 @@ -This directory contains scripts for automated test runs via the [Travis CI](https://travis-ci.com) build service. They are used for the preparation of worker instances by setting up needed extensions and configuring database access. - -These scripts might be used to configure your own system for test runs. But since their primary purpose remains to support Travis in running the test cases, you would be best advised to stick to the setup notes in the tests themselves. - -The scripts are: - - - [`sphinx-setup.sh`](sphinx-setup.sh) - Prepares the [Sphinx](https://sphinxsearch.com/) server instances by installing the server and attaching it to MySQL diff --git a/tests/data/travis/sphinx-setup.sh b/tests/data/travis/sphinx-setup.sh deleted file mode 100755 index 970247af8..000000000 --- a/tests/data/travis/sphinx-setup.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh -e -SCRIPT=$(readlink -f "$0") -CWD=$(dirname "$SCRIPT") - -# install sphinx from https://sphinxsearch.com/downloads/release/ -wget http://sphinxsearch.com/files/sphinxsearch_2.2.11-release-1~trusty_amd64.deb -sudo dpkg -i sphinxsearch_2.2.11-release-1~trusty_amd64.deb - -# make dir that is used in sphinx config -mkdir -p sphinx -sed -i s\~SPHINX_BASE_DIR~$PWD/sphinx~g $CWD/../sphinx.conf - -# Setup source database -mysql -D yiitest -u travis < $CWD/../source.sql - -# setup test Sphinx indexes: -indexer --config $CWD/../sphinx.conf --all - -# run searchd: -searchd --config $CWD/../sphinx.conf