diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index b7bce71255..cd4f52362b 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -2,7 +2,7 @@ name: 'Continuous integration' on: ['push', 'pull_request'] jobs: cs: - runs-on: 'ubuntu-latest' + runs-on: 'ubuntu-20.04' name: 'Coding style' steps: - name: 'Checkout' @@ -21,3 +21,53 @@ jobs: - name: 'Check composer.json' run: 'composer-normalize --diff --dry-run --indent-size=4 --indent-style=space --no-update-lock' + + phpunit: + runs-on: 'ubuntu-20.04' + name: 'PHPUnit (PHP ${{ matrix.php }}, ES ${{ matrix.elasticsearch }})' + timeout-minutes: 5 + strategy: + matrix: + include: + - php: '7.2' + elasticsearch: '7.1.1' + - php: '7.2' + elasticsearch: '7.2.1' + - php: '7.3' + elasticsearch: '7.3.2' + - php: '7.4' + elasticsearch: '7.3.2' + - php: '8.0' + elasticsearch: '7.3.2' + composer_flags: '--ignore-platform-reqs' + fail-fast: false + steps: + - name: 'Checkout' + uses: 'actions/checkout@v2' + + - name: 'Setup PHP' + uses: 'shivammathur/setup-php@v2' + with: + php-version: '${{ matrix.php }}' + coverage: 'none' + tools: 'pecl, composer:v2' + extensions: 'curl, json, mbstring, openssl' + + - name: 'Get composer cache directory' + id: 'composer_cache' + run: 'echo "::set-output name=dir::$(composer config cache-files-dir)"' + + - name: 'Cache dependencies' + uses: 'actions/cache@v2' + with: + path: '${{ steps.composer_cache.outputs.dir }}' + key: '${{ runner.os }}-composer-php${{ matrix.php }}-${{ hashFiles(''**/composer.json'') }}' + restore-keys: | + ${{ runner.os }}-composer-php${{ matrix.php }}- + ${{ runner.os }}-composer- + + - name: 'Update dependencies' + run: 'composer update --prefer-dist --no-interaction --no-progress --ansi ${{ matrix.composer_flags }}' + + - name: 'Run tests' + run: 'vendor/bin/phpunit --group unit' diff --git a/CHANGELOG.md b/CHANGELOG.md index 606d96c643..ad47995bd8 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Used new settings endpoints classes [#1852](https://github.com/ruflin/Elastica/pull/1852) * Allow float values for connection timeout and connection connect-timeout, providing ms precision for those. Previous precision was second. [#1868](https://github.com/ruflin/Elastica/pull/1868) * Run coding styles check on github action [#1878](https://github.com/ruflin/Elastica/pull/1878) +* Run unit tests on github action [#1882](https://github.com/ruflin/Elastica/pull/1882) ### Deprecated * Deprecated `Elastica\Aggregation\Range::setKeyedResponse()`, use `setKeyed()` instead [#1848](https://github.com/ruflin/Elastica/pull/1848) * Deprecated `Elastica\Exception\ResponseException::getElasticsearchException()`, use `getResponse()::getFullError()` instead [#1829](https://github.com/ruflin/Elastica/pull/1829) diff --git a/tests/Aggregation/TermsTest.php b/tests/Aggregation/TermsTest.php index 6c1126bd0c..502343efbe 100644 --- a/tests/Aggregation/TermsTest.php +++ b/tests/Aggregation/TermsTest.php @@ -9,8 +9,6 @@ use Elastica\Query; /** - * @group functional - * * @internal */ class TermsTest extends BaseAggregationTest @@ -73,6 +71,9 @@ public function testExcludeExactMatch(): void $this->assertSame(['first', 'second'], $agg->getParam('exclude')); } + /** + * @group functional + */ public function testTermsAggregation(): void { $agg = new Terms('terms'); @@ -86,6 +87,9 @@ public function testTermsAggregation(): void $this->assertEquals('blue', $results['buckets'][0]['key']); } + /** + * @group functional + */ public function testTermsSetOrder(): void { $agg = new Terms('terms'); @@ -99,6 +103,9 @@ public function testTermsSetOrder(): void $this->assertEquals('blue', $results['buckets'][2]['key']); } + /** + * @group functional + */ public function testTermsSetOrders(): void { $agg = new Terms('terms'); diff --git a/tests/Base.php b/tests/Base.php index df144a77f4..a9ad2c0e48 100644 --- a/tests/Base.php +++ b/tests/Base.php @@ -186,20 +186,20 @@ protected function _isUnitGroup() { $groups = TestUtil::getGroups(\get_class($this), $this->getName(false)); - return \in_array('unit', $groups); + return \in_array('unit', $groups, true); } protected function _isFunctionalGroup() { $groups = TestUtil::getGroups(\get_class($this), $this->getName(false)); - return \in_array('functional', $groups); + return \in_array('functional', $groups, true); } protected function _isBenchmarkGroup() { $groups = TestUtil::getGroups(\get_class($this), $this->getName(false)); - return \in_array('benchmark', $groups); + return \in_array('benchmark', $groups, true); } } diff --git a/tests/BasePipeline.php b/tests/BasePipeline.php index beac80f36c..6d0b10c2dc 100644 --- a/tests/BasePipeline.php +++ b/tests/BasePipeline.php @@ -12,7 +12,10 @@ class BasePipeline extends BaseTest { protected function tearDown(): void { - $this->_createPipeline()->deletePipeline('*'); + if ($this->_isFunctionalGroup()) { + $this->_createPipeline()->deletePipeline('*'); + } + parent::tearDown(); } diff --git a/tests/IndexTest.php b/tests/IndexTest.php index ca72d974fc..7a2380cae4 100644 --- a/tests/IndexTest.php +++ b/tests/IndexTest.php @@ -2,6 +2,7 @@ namespace Elastica\Test; +use Elastica\Client; use Elastica\Document; use Elastica\Exception\InvalidException; use Elastica\Exception\ResponseException; @@ -18,14 +19,15 @@ use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; /** - * @group functional - * * @internal */ class IndexTest extends BaseTest { use ExpectDeprecationTrait; + /** + * @group functional + */ public function testMapping(): void { $index = $this->_createIndex(); @@ -51,6 +53,9 @@ public function testMapping(): void $this->assertEquals('integer', $storedMapping['properties']['test']['type']); } + /** + * @group functional + */ public function testGetMappingAlias(): void { $index = $this->_createIndex(); @@ -77,6 +82,9 @@ public function testGetMappingAlias(): void $this->assertEquals($mapping1, $mapping2); } + /** + * @group functional + */ public function testAddRemoveAlias(): void { $this->expectException(ResponseException::class); @@ -115,6 +123,9 @@ public function testAddRemoveAlias(): void $client->getIndex($aliasName)->search('ruflin'); } + /** + * @group functional + */ public function testCount(): void { $index = $this->_createIndex(); @@ -138,6 +149,9 @@ public function testCount(): void $this->assertEquals(1, $index->count($query)); } + /** + * @group functional + */ public function testCountGet(): void { $index = $this->_createIndex(); @@ -161,6 +175,9 @@ public function testCountGet(): void $this->assertEquals(1, $index->count($query, Request::GET)); } + /** + * @group functional + */ public function testDeleteByQueryWithQueryString(): void { $index = $this->_createIndex(); @@ -190,6 +207,9 @@ public function testDeleteByQueryWithQueryString(): void $this->assertEquals(0, $response->count()); } + /** + * @group functional + */ public function testDeleteByQueryWithQuery(): void { $index = $this->_createIndex(); @@ -219,6 +239,9 @@ public function testDeleteByQueryWithQuery(): void $this->assertEquals(0, $response->count()); } + /** + * @group functional + */ public function testDeleteByQueryWithArrayQuery(): void { $index = $this->_createIndex(); @@ -248,6 +271,9 @@ public function testDeleteByQueryWithArrayQuery(): void $this->assertEquals(0, $response->count()); } + /** + * @group functional + */ public function testDeleteByQueryWithQueryAndOptions(): void { $index = $this->_createIndex(null, true, 2); @@ -304,6 +330,9 @@ public function testDeleteByQueryWithQueryAndOptions(): void $this->assertEquals(0, $response->count()); } + /** + * @group functional + */ public function testUpdateByQueryWithQueryString(): void { $index = $this->_createIndex(); @@ -336,6 +365,9 @@ public function testUpdateByQueryWithQueryString(): void $this->assertEquals(0, $response->count()); } + /** + * @group functional + */ public function testUpdateByQueryAll(): void { $index = $this->_createIndex(); @@ -368,6 +400,9 @@ public function testUpdateByQueryAll(): void $this->assertEquals(0, $response->count()); } + /** + * @group functional + */ public function testDeleteIndexDeleteAlias(): void { $indexName = 'test'; @@ -393,6 +428,9 @@ public function testDeleteIndexDeleteAlias(): void $this->assertFalse($status->aliasExists($aliasName)); } + /** + * @group functional + */ public function testAddAliasTwoIndices(): void { $indexName1 = 'test1'; @@ -418,6 +456,9 @@ public function testAddAliasTwoIndices(): void $this->assertTrue($index1->hasAlias($aliasName)); } + /** + * @group functional + */ public function testReplaceAlias(): void { $indexName1 = 'test1'; @@ -440,6 +481,9 @@ public function testReplaceAlias(): void $this->assertTrue($index1->hasAlias($aliasName)); } + /** + * @group functional + */ public function testAddDocumentVersion(): void { $client = $this->_getClient(); @@ -460,6 +504,9 @@ public function testAddDocumentVersion(): void $this->assertEquals(2, $data['_version']); } + /** + * @group functional + */ public function testClearCache(): void { $index = $this->_createIndex(); @@ -467,6 +514,9 @@ public function testClearCache(): void $this->assertFalse($response->hasError()); } + /** + * @group functional + */ public function testFlush(): void { $index = $this->_createIndex(); @@ -474,6 +524,9 @@ public function testFlush(): void $this->assertFalse($response->hasError()); } + /** + * @group functional + */ public function testExists(): void { $index = $this->_createIndex(); @@ -491,6 +544,8 @@ public function testExists(): void * Tests if deleting an index that does not exist in Elasticsearch, * correctly returns a boolean true from the hasError() method of * the \Elastica\Response object + * + * @group functional */ public function testDeleteMissingIndexHasError(): void { @@ -510,6 +565,8 @@ public function testDeleteMissingIndexHasError(): void /** * Tests to see if the test type mapping exists when calling $index->getMapping(). + * + * @group functional */ public function testIndexGetMapping(): void { @@ -532,6 +589,9 @@ public function testIndexGetMapping(): void $this->assertEquals('integer', $indexMappings['properties']['test']['type']); } + /** + * @group functional + */ public function testEmptyIndexGetMapping(): void { $indexMappings = $this->_createIndex()->getMapping(); @@ -541,6 +601,8 @@ public function testEmptyIndexGetMapping(): void /** * Test to see if search Default Limit works. + * + * @group functional */ public function testLimitDefaultIndex(): void { @@ -626,17 +688,19 @@ public function testCreateWithInvalidOption(): void $this->expectException(InvalidException::class); $this->expectExceptionMessageMatches('/"testing_invalid_option" is not a valid option\. Allowed options are ((("[a-z_]+")(, )?)+)\./'); - $client = $this->_getClient(); - $indexName = 'test'; - $index = $client->getIndex($indexName); + $client = $this->createMock(Client::class); + $index = new Index($client, 'test'); $opts = ['testing_invalid_option' => true]; $index->create([], $opts); } + /** + * @group unit + */ public function testCreateSearch(): void { - $client = $this->_getClient(); + $client = $this->createMock(Client::class); $index = new Index($client, 'test'); $query = new QueryString('test'); @@ -659,6 +723,9 @@ public function testCreateSearch(): void $this->assertTrue($search->hasIndex($index)); } + /** + * @group functional + */ public function testSearch(): void { $index = $this->_createIndex(); @@ -686,6 +753,9 @@ public function testSearch(): void $this->assertEquals(3, $count); } + /** + * @group functional + */ public function testSearchGet(): void { $index = $this->_createIndex(); @@ -701,6 +771,9 @@ public function testSearchGet(): void $this->assertEquals(1, $count); } + /** + * @group functional + */ public function testForcemerge(): void { $index = $this->_createIndex('testforcemerge_indextest', false, 3); @@ -728,6 +801,9 @@ public function testForcemerge(): void $this->assertEquals(0, $stats['_all']['primaries']['docs']['deleted']); } + /** + * @group functional + */ public function testAnalyze(): void { $index = $this->_createIndex(); @@ -747,6 +823,9 @@ public function testAnalyze(): void $this->assertEquals($tokens, $returnedTokens); } + /** + * @group functional + */ public function testRequestEndpoint(): void { $index = $this->_createIndex(); @@ -769,6 +848,9 @@ public function testRequestEndpoint(): void $this->assertEquals($tokens, $returnedTokens); } + /** + * @group functional + */ public function testAnalyzeExplain(): void { $index = $this->_createIndex(); @@ -778,6 +860,9 @@ public function testAnalyzeExplain(): void $this->assertArrayHasKey('custom_analyzer', $data); } + /** + * @group functional + */ public function testGetEmptyAliases(): void { $indexName = 'test-getaliases'; diff --git a/tests/PipelineTest.php b/tests/PipelineTest.php index b6488f78e1..16fb3208a4 100644 --- a/tests/PipelineTest.php +++ b/tests/PipelineTest.php @@ -3,6 +3,7 @@ namespace Elastica\Test; use Elastica\Bulk; +use Elastica\Client; use Elastica\Document; use Elastica\Exception\ResponseException; use Elastica\Pipeline; @@ -24,7 +25,8 @@ public function testProcessor(): void $rename = new Rename('foo', 'target.field'); $set = new Set('field4', 324); - $processors = new Pipeline($this->_getClient()); + $client = $this->createMock(Client::class); + $processors = new Pipeline($client); $processors->setDescription('this is a new pipeline'); $processors->addProcessor($trim); $processors->addProcessor($rename); diff --git a/tests/Processor/AttachmentTest.php b/tests/Processor/AttachmentTest.php index 47cca66a4e..26a800441d 100644 --- a/tests/Processor/AttachmentTest.php +++ b/tests/Processor/AttachmentTest.php @@ -9,8 +9,6 @@ use Elastica\Test\BasePipeline as BasePipelineTest; /** - * @group functional - * * @internal */ class AttachmentTest extends BasePipelineTest @@ -55,6 +53,9 @@ public function testAttachmentWithNonDefaultOptions(): void $this->assertEquals($expected, $processor->toArray()); } + /** + * @group functional + */ public function testAttachmentAddPdf(): void { $attachment = new Attachment('data'); @@ -94,6 +95,9 @@ public function testAttachmentAddPdf(): void $this->assertEquals(0, $resultSet->count()); } + /** + * @group functional + */ public function testAttachmentAddPdfFileContent(): void { $attachment = new Attachment('data'); @@ -136,6 +140,9 @@ public function testAttachmentAddPdfFileContent(): void $this->assertEquals(0, $resultSet->count()); } + /** + * @group functional + */ public function testAddWordxFile(): void { $attachment = new Attachment('data'); @@ -176,6 +183,9 @@ public function testAddWordxFile(): void $this->assertEquals(0, $resultSet->count()); } + /** + * @group functional + */ public function testExcludeFileSource(): void { $attachment = new Attachment('data'); diff --git a/tests/Query/ParentIdTest.php b/tests/Query/ParentIdTest.php index 51eb9a661d..70caf8abfb 100644 --- a/tests/Query/ParentIdTest.php +++ b/tests/Query/ParentIdTest.php @@ -124,7 +124,7 @@ public function testParentId(): void } /** - * @group unit + * @group functional */ public function testQueryBuilderParentId(): void { diff --git a/tests/Query/PercolateTest.php b/tests/Query/PercolateTest.php index fb621d77cd..e8587930b3 100644 --- a/tests/Query/PercolateTest.php +++ b/tests/Query/PercolateTest.php @@ -2,7 +2,9 @@ namespace Elastica\Test\Query; +use Elastica\Client; use Elastica\Document; +use Elastica\Index; use Elastica\Mapping; use Elastica\Query\Percolate; use Elastica\Test\Base as BaseTest; @@ -131,7 +133,8 @@ public function testSetDocument(): void */ public function testSetDocumentIndex(): void { - $index = $this->_createIndex('indexone'); + $client = $this->createMock(Client::class); + $index = new Index($client, 'indexone'); $query = new Percolate(); $query->setDocumentIndex($index->getName()); diff --git a/tests/Query/TermsTest.php b/tests/Query/TermsTest.php index 7d6ae773bd..2d1ee57032 100644 --- a/tests/Query/TermsTest.php +++ b/tests/Query/TermsTest.php @@ -9,10 +9,12 @@ /** * @internal - * @group unit */ class TermsTest extends BaseTest { + /** + * @group unit + */ public function testSetTermsLookup(): void { $terms = [ @@ -28,6 +30,9 @@ public function testSetTermsLookup(): void $this->assertEquals($terms, $data['terms']['name']); } + /** + * @group unit + */ public function testInvalidParams(): void { $query = new Terms('field', ['aaa', 'bbb']); @@ -37,6 +42,9 @@ public function testInvalidParams(): void $query->toArray(); } + /** + * @group unit + */ public function testEmptyField(): void { $this->expectException(InvalidException::class); @@ -176,6 +184,9 @@ public function testVariousDataTypesViaAddTerm(): void $this->assertEquals(1, $resultSet->count()); } + /** + * @group unit + */ public function testAddTermTypeError(): void { $this->expectException(\TypeError::class);