diff --git a/.github/wait_for_es.php b/.github/wait_for_es.php new file mode 100644 index 00000000..10501a6e --- /dev/null +++ b/.github/wait_for_es.php @@ -0,0 +1,26 @@ +build(); + $client->ping(); + echo 'Is up and running' . PHP_EOL; + exit(0); + } catch (NoNodesAvailableException $e) { + if ($retries === $maxRetries) { + echo 'Cannot reach elasticsearch server' . PHP_EOL; + exit(1); + } + + sleep(5); + $retries++; + } +} diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml new file mode 100644 index 00000000..c8b58315 --- /dev/null +++ b/.github/workflows/phpunit.yml @@ -0,0 +1,48 @@ +name: PHPUnit + +on: + push: + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + services: + elasticsearch: + image: elastic/elasticsearch:7.4.0 + ports: + - 9200:9200 + env: + discovery.type: single-node + strategy: + matrix: + php: ['7.4', '8.0'] + steps: + - uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + tools: composer:v2 + coverage: xdebug + + - name: Validate composer.json and composer.lock + run: composer validate + + - name: Install dependencies + run: composer install --prefer-dist --no-progress + + - name: Wait for Elasticsearch + run: php ./.github/wait_for_es.php + + - name: Run PHPUnit + run: vendor/bin/phpunit --coverage-clover=coverage.xml + + - name: Run PHPCS + run: vendor/bin/phpcs -p --standard=PSR2 --ignore=vendor/ ./ + + - name: Upload Codecov + uses: codecov/codecov-action@v1 + with: + file: ./coverage.xml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 65d6b9db..00000000 --- a/.travis.yml +++ /dev/null @@ -1,26 +0,0 @@ -sudo: false -language: php -php: - - 7.1 - - 7.2 - - 7.3 - - 7.4snapshot -matrix: - allow_failures: - - php: 7.4snapshot -env: - global: - - ES_VERSION=7.4.0 ES_DOWNLOAD_URL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VERSION}-linux-x86_64.tar.gz -install: - - wget ${ES_DOWNLOAD_URL} - - tar -xzf elasticsearch-${ES_VERSION}-linux-x86_64.tar.gz - - ./elasticsearch-${ES_VERSION}/bin/elasticsearch -d -before_script: - - if [ "$GITHUB_COMPOSER_AUTH" ]; then composer config -g github-oauth.github.com $GITHUB_COMPOSER_AUTH; fi - - composer install --no-interaction --prefer-dist -script: - - wget -q --waitretry=1 --retry-connrefused -T 10 -O - http://127.0.0.1:9200 - - vendor/bin/phpunit --coverage-clover=coverage.xml - - vendor/bin/phpcs -p --standard=PSR2 --ignore=vendor/ ./ -after_script: - - travis_retry bash <(curl -s https://codecov.io/bash) diff --git a/composer.json b/composer.json index 1cc93d8a..2b633cab 100644 --- a/composer.json +++ b/composer.json @@ -11,18 +11,14 @@ } ], "require": { - "php": "^7.0", - "symfony/serializer": "^3.0|^4.0", - "paragonie/random_compat": "*" + "php": "^7.4 || ^8.0", + "symfony/serializer": "^7.0", + "elasticsearch/elasticsearch": "^7.0" }, "require-dev": { - "elasticsearch/elasticsearch": "^7.0", - "phpunit/phpunit": "~6.0", + "phpunit/phpunit": "^9.0", "squizlabs/php_codesniffer": "^3.0" }, - "suggest": { - "elasticsearch/elasticsearch": "This library is for elasticsearch/elasticsearch client to enhance it with DSL functionality." - }, "autoload": { "psr-4": { "ONGR\\ElasticsearchDSL\\": "src/" @@ -33,10 +29,9 @@ "ONGR\\ElasticsearchDSL\\Tests\\": "tests/" } }, - "minimum-stability": "dev", "extra": { "branch-alias": { - "dev-master": "7.0-dev" + "dev-master": "7.2-dev" } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 17185e94..7233b3df 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,7 @@ @@ -23,16 +24,16 @@ - - + + ./ - - ./tests - ./vendor - - - - - - + + + ./tests + ./vendor + + + + + diff --git a/src/Aggregation/Matrix/MatrixStatsAggregation.php b/src/Aggregation/Matrix/MaxAggregation.php similarity index 100% rename from src/Aggregation/Matrix/MatrixStatsAggregation.php rename to src/Aggregation/Matrix/MaxAggregation.php diff --git a/src/ParametersTrait.php b/src/ParametersTrait.php index 013b4b6d..e74927b3 100644 --- a/src/ParametersTrait.php +++ b/src/ParametersTrait.php @@ -37,12 +37,15 @@ public function hasParameter($name) * Removes parameter. * * @param string $name + * @return $this */ public function removeParameter($name) { if ($this->hasParameter($name)) { unset($this->parameters[$name]); } + + return $this; } /** @@ -70,10 +73,13 @@ public function getParameters() /** * @param string $name * @param array|string|int|float|bool|\stdClass $value + * @return $this */ public function addParameter($name, $value) { $this->parameters[$name] = $value; + + return $this; } /** diff --git a/src/Query/Compound/FunctionScoreQuery.php b/src/Query/Compound/FunctionScoreQuery.php index e7d96c1b..844bab13 100644 --- a/src/Query/Compound/FunctionScoreQuery.php +++ b/src/Query/Compound/FunctionScoreQuery.php @@ -181,7 +181,7 @@ public function addRandomFunction($seed = null, BuilderInterface $query = null) /** * Adds script score function. * - * @param string $inline + * @param string $source * @param array $params * @param array $options * @param BuilderInterface $query @@ -189,7 +189,7 @@ public function addRandomFunction($seed = null, BuilderInterface $query = null) * @return $this */ public function addScriptScoreFunction( - $inline, + $source, array $params = [], array $options = [], BuilderInterface $query = null @@ -201,7 +201,7 @@ public function addScriptScoreFunction( array_merge( [ 'lang' => 'painless', - 'inline' => $inline, + 'source' => $source, 'params' => $params ], $options diff --git a/src/SearchEndpoint/AggregationsEndpoint.php b/src/SearchEndpoint/AggregationsEndpoint.php index 079a6a5d..3e035f43 100644 --- a/src/SearchEndpoint/AggregationsEndpoint.php +++ b/src/SearchEndpoint/AggregationsEndpoint.php @@ -27,7 +27,7 @@ class AggregationsEndpoint extends AbstractSearchEndpoint /** * {@inheritdoc} */ - public function normalize(NormalizerInterface $normalizer, $format = null, array $context = []) + public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = []) { $output = []; if (count($this->getAll()) > 0) { diff --git a/src/SearchEndpoint/HighlightEndpoint.php b/src/SearchEndpoint/HighlightEndpoint.php index f2b8d8e9..aa57b3d7 100644 --- a/src/SearchEndpoint/HighlightEndpoint.php +++ b/src/SearchEndpoint/HighlightEndpoint.php @@ -37,7 +37,7 @@ class HighlightEndpoint extends AbstractSearchEndpoint /** * {@inheritdoc} */ - public function normalize(NormalizerInterface $normalizer, $format = null, array $context = []) + public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = []) { if ($this->highlight) { return $this->highlight->toArray(); diff --git a/src/SearchEndpoint/InnerHitsEndpoint.php b/src/SearchEndpoint/InnerHitsEndpoint.php index f1562fe6..8428bd88 100644 --- a/src/SearchEndpoint/InnerHitsEndpoint.php +++ b/src/SearchEndpoint/InnerHitsEndpoint.php @@ -27,7 +27,7 @@ class InnerHitsEndpoint extends AbstractSearchEndpoint /** * {@inheritdoc} */ - public function normalize(NormalizerInterface $normalizer, $format = null, array $context = []) + public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = []) { $output = []; if (count($this->getAll()) > 0) { diff --git a/src/SearchEndpoint/PostFilterEndpoint.php b/src/SearchEndpoint/PostFilterEndpoint.php index 6055b7ed..de3e263c 100644 --- a/src/SearchEndpoint/PostFilterEndpoint.php +++ b/src/SearchEndpoint/PostFilterEndpoint.php @@ -26,7 +26,7 @@ class PostFilterEndpoint extends QueryEndpoint /** * {@inheritdoc} */ - public function normalize(NormalizerInterface $normalizer, $format = null, array $context = []) + public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = []) { if (!$this->getBool()) { return null; diff --git a/src/SearchEndpoint/QueryEndpoint.php b/src/SearchEndpoint/QueryEndpoint.php index 6212b05d..b7626910 100644 --- a/src/SearchEndpoint/QueryEndpoint.php +++ b/src/SearchEndpoint/QueryEndpoint.php @@ -39,7 +39,7 @@ class QueryEndpoint extends AbstractSearchEndpoint implements OrderedNormalizerI /** * {@inheritdoc} */ - public function normalize(NormalizerInterface $normalizer, $format = null, array $context = []) + public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = []) { if (!$this->filtersSet && $this->hasReference('filter_query')) { /** @var BuilderInterface $filter */ diff --git a/src/SearchEndpoint/SortEndpoint.php b/src/SearchEndpoint/SortEndpoint.php index 2461c858..cd00bb2f 100644 --- a/src/SearchEndpoint/SortEndpoint.php +++ b/src/SearchEndpoint/SortEndpoint.php @@ -26,7 +26,7 @@ class SortEndpoint extends AbstractSearchEndpoint /** * {@inheritdoc} */ - public function normalize(NormalizerInterface $normalizer, $format = null, array $context = []) + public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = []) { $output = []; diff --git a/src/SearchEndpoint/SuggestEndpoint.php b/src/SearchEndpoint/SuggestEndpoint.php index 2e2e16ac..6d292239 100644 --- a/src/SearchEndpoint/SuggestEndpoint.php +++ b/src/SearchEndpoint/SuggestEndpoint.php @@ -27,7 +27,7 @@ class SuggestEndpoint extends AbstractSearchEndpoint /** * {@inheritdoc} */ - public function normalize(NormalizerInterface $normalizer, $format = null, array $context = []) + public function normalize(NormalizerInterface $normalizer, string $format = null, array $context = []) { $output = []; if (count($this->getAll()) > 0) { diff --git a/src/Serializer/Normalizer/CustomReferencedNormalizer.php b/src/Serializer/Normalizer/CustomReferencedNormalizer.php index 6cd24a8e..fd32a89b 100644 --- a/src/Serializer/Normalizer/CustomReferencedNormalizer.php +++ b/src/Serializer/Normalizer/CustomReferencedNormalizer.php @@ -26,7 +26,7 @@ class CustomReferencedNormalizer extends CustomNormalizer /** * {@inheritdoc} */ - public function normalize($object, $format = null, array $context = []) + public function normalize($object, string $format = null, array $context = []) { $object->setReferences($this->references); $data = parent::normalize($object, $format, $context); diff --git a/src/Serializer/OrderedSerializer.php b/src/Serializer/OrderedSerializer.php index bcbb9c3d..9019e43e 100644 --- a/src/Serializer/OrderedSerializer.php +++ b/src/Serializer/OrderedSerializer.php @@ -59,7 +59,7 @@ private function order(array $data) uasort( $filteredData, function (OrderedNormalizerInterface $a, OrderedNormalizerInterface $b) { - return $a->getOrder() > $b->getOrder(); + return $a->getOrder() <=> $b->getOrder(); } ); diff --git a/tests/Functional/AbstractElasticsearchTestCase.php b/tests/Functional/AbstractElasticsearchTestCase.php index 3c023410..4765f7c6 100644 --- a/tests/Functional/AbstractElasticsearchTestCase.php +++ b/tests/Functional/AbstractElasticsearchTestCase.php @@ -31,7 +31,7 @@ abstract class AbstractElasticsearchTestCase extends TestCase /** * {@inheritdoc} */ - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -109,7 +109,7 @@ protected function getDataArray() /** * {@inheritdoc} */ - protected function tearDown() + protected function tearDown(): void { parent::tearDown(); $this->deleteIndex(); diff --git a/tests/Unit/Aggregation/Bucketing/AdjacencyMatrixAggregationTest.php b/tests/Unit/Aggregation/Bucketing/AdjacencyMatrixAggregationTest.php index f73cc612..038da8c7 100644 --- a/tests/Unit/Aggregation/Bucketing/AdjacencyMatrixAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/AdjacencyMatrixAggregationTest.php @@ -9,28 +9,27 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Bucketing; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\AdjacencyMatrixAggregation; -use ONGR\ElasticsearchDSL\BuilderInterface; +use ONGR\ElasticsearchDSL\Aggregation\Bucketing\FiltersAggregation; /** * Unit test for adjacency matrix aggregation. */ class AdjacencyMatrixAggregationTest extends \PHPUnit\Framework\TestCase { -// /** -// * Test if exception is thrown when not anonymous filter is without name. -// * -// * @expectedException \LogicException -// * @expectedExceptionMessage In not anonymous filters filter name must be set. -// */ -// public function testIfExceptionIsThrown() -// { -// $mock = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface')->getMock(); -// $aggregation = new FiltersAggregation('test_agg'); -// $aggregation->addFilter($mock); -// } + /** + * Test if exception is thrown when not anonymous filter is without name. + */ + public function testIfExceptionIsThrown() + { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage("In not anonymous filters filter name must be set."); + $mock = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface')->getMock(); + $aggregation = new FiltersAggregation('test_agg'); + $aggregation->addFilter($mock); + } /** * Test GetArray method. @@ -61,7 +60,7 @@ public function testToArray() { $aggregation = new AdjacencyMatrixAggregation('test_agg'); $filter = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface') - ->setMethods(['toArray', 'getType']) + ->onlyMethods(['toArray', 'getType']) ->getMockForAbstractClass(); $filter->expects($this->any()) ->method('toArray') @@ -95,9 +94,7 @@ public function testToArray() */ public function testFilterConstructor() { - /** @var BuilderInterface|\PHPUnit_Framework_MockObject_MockObject $builderInterface1 */ $builderInterface1 = $this->getMockForAbstractClass('ONGR\ElasticsearchDSL\BuilderInterface'); - /** @var BuilderInterface|\PHPUnit_Framework_MockObject_MockObject $builderInterface2 */ $builderInterface2 = $this->getMockForAbstractClass('ONGR\ElasticsearchDSL\BuilderInterface'); $aggregation = new AdjacencyMatrixAggregation( diff --git a/tests/Unit/Aggregation/Bucketing/AudoDateHistogramAggregationTest.php b/tests/Unit/Aggregation/Bucketing/AudoDateHistogramAggregationTest.php index bece77d3..3a6c21c9 100644 --- a/tests/Unit/Aggregation/Bucketing/AudoDateHistogramAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/AudoDateHistogramAggregationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Bucketing; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\AutoDateHistogramAggregation; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\TermsAggregation; diff --git a/tests/Unit/Aggregation/Bucketing/ChildrenAggregationTest.php b/tests/Unit/Aggregation/Bucketing/ChildrenAggregationTest.php index f4cb6b3a..8e10461a 100644 --- a/tests/Unit/Aggregation/Bucketing/ChildrenAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/ChildrenAggregationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Bucketing; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\ChildrenAggregation; @@ -20,11 +20,10 @@ class ChildrenAggregationTest extends \PHPUnit\Framework\TestCase { /** * Tests if ChildrenAggregation#getArray throws exception when expected. - * - * @expectedException \LogicException */ public function testGetArrayException() { + $this->expectException(\LogicException::class); $aggregation = new ChildrenAggregation('foo'); $aggregation->getArray(); } diff --git a/tests/Unit/Aggregation/Bucketing/CompositeAggregationTest.php b/tests/Unit/Aggregation/Bucketing/CompositeAggregationTest.php index b45c2233..a735dc37 100644 --- a/tests/Unit/Aggregation/Bucketing/CompositeAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/CompositeAggregationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Bucketing; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\CompositeAggregation; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\TermsAggregation; diff --git a/tests/Unit/Aggregation/Bucketing/DateHistogramAggregationTest.php b/tests/Unit/Aggregation/Bucketing/DateHistogramAggregationTest.php index 6f7544bb..5fce811a 100644 --- a/tests/Unit/Aggregation/Bucketing/DateHistogramAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/DateHistogramAggregationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Bucketing; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\DateHistogramAggregation; @@ -20,11 +20,10 @@ class DateHistogramAggregationTest extends \PHPUnit\Framework\TestCase { /** * Tests if ChildrenAggregation#getArray throws exception when expected. - * - * @expectedException \LogicException */ public function testGetArrayException() { + $this->expectException(\LogicException::class); $aggregation = new DateHistogramAggregation('foo'); $aggregation->getArray(); } diff --git a/tests/Unit/Aggregation/Bucketing/DateRangeAggregationTest.php b/tests/Unit/Aggregation/Bucketing/DateRangeAggregationTest.php index 6a3c5dbe..c86ebb55 100644 --- a/tests/Unit/Aggregation/Bucketing/DateRangeAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/DateRangeAggregationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Bucketing; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\DateRangeAggregation; @@ -17,24 +17,22 @@ class DateRangeAggregationTest extends \PHPUnit\Framework\TestCase { /** * Test if exception is thrown. - * - * @expectedException \LogicException - * @expectedExceptionMessage Date range aggregation must have field, format set and range added. */ public function testIfExceptionIsThrownWhenNoParametersAreSet() { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Date range aggregation must have field, format set and range added.'); $agg = new DateRangeAggregation('test_agg'); $agg->getArray(); } /** * Test if exception is thrown when both range parameters are null. - * - * @expectedException \LogicException - * @expectedExceptionMessage Either from or to must be set. Both cannot be null. */ public function testIfExceptionIsThrownWhenBothRangesAreNull() { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Either from or to must be set. Both cannot be null.'); $agg = new DateRangeAggregation('test_agg'); $agg->addRange(null, null); } @@ -73,7 +71,7 @@ public function testDateRangeAggregationGetType() * * @return array */ - public function testDateRangeAggregationConstructorProvider() + public function getDateRangeAggregationConstructorProvider() { return [ // Case #0. Minimum arguments. @@ -112,13 +110,12 @@ public function testDateRangeAggregationConstructorProvider() * @param string $format * @param array $ranges * - * @dataProvider testDateRangeAggregationConstructorProvider + * @dataProvider getDateRangeAggregationConstructorProvider */ public function testDateRangeAggregationConstructor($field = null, $format = null, array $ranges = null) { - /** @var DateRangeAggregation|\PHPUnit_Framework_MockObject_MockObject $aggregation */ $aggregation = $this->getMockBuilder('ONGR\ElasticsearchDSL\Aggregation\Bucketing\DateRangeAggregation') - ->setMethods(['setField', 'setFormat', 'addRange']) + ->onlyMethods(['setField', 'setFormat', 'addRange']) ->disableOriginalConstructor() ->getMock(); $aggregation->expects($this->once())->method('setField')->with($field); diff --git a/tests/Unit/Aggregation/Bucketing/FilterAggregationTest.php b/tests/Unit/Aggregation/Bucketing/FilterAggregationTest.php index b453e014..a5659a59 100644 --- a/tests/Unit/Aggregation/Bucketing/FilterAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/FilterAggregationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Bucketing; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\FilterAggregation; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\HistogramAggregation; @@ -101,26 +101,35 @@ public function testToArray($aggregation, $expectedResult) /** * Test for setField(). - * - * @expectedException \LogicException - * @expectedExceptionMessage doesn't support `field` parameter */ public function testSetField() { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('doesn\'t support `field` parameter'); $aggregation = new FilterAggregation('test_agg'); $aggregation->setField('test_field'); } /** * Test for toArray() without setting a filter. - * - * @expectedException \LogicException - * @expectedExceptionMessage has no filter added */ public function testToArrayNoFilter() { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('has no filter added'); $aggregation = new FilterAggregation('test_agg'); - $aggregation->toArray(); + $result = $aggregation->toArray(); + + $this->assertEquals( + [ + 'aggregation' => [ + 'test_agg' => [ + 'filter' => [] + ] + ] + ], + $result + ); } /** @@ -129,9 +138,19 @@ public function testToArrayNoFilter() public function testToArrayWithFilter() { $aggregation = new FilterAggregation('test_agg'); - $aggregation->setFilter(new ExistsQuery('test')); - $aggregation->toArray(); + $result = $aggregation->toArray(); + + $this->assertEquals( + [ + 'filter' => [ + 'exists' => [ + 'field' => 'test' + ] + ] + ], + $result + ); } /** diff --git a/tests/Unit/Aggregation/Bucketing/FiltersAggregationTest.php b/tests/Unit/Aggregation/Bucketing/FiltersAggregationTest.php index b3032a31..174bacd8 100644 --- a/tests/Unit/Aggregation/Bucketing/FiltersAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/FiltersAggregationTest.php @@ -9,10 +9,9 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Bucketing; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\FiltersAggregation; -use ONGR\ElasticsearchDSL\BuilderInterface; /** * Unit test for filters aggregation. @@ -21,12 +20,11 @@ class FiltersAggregationTest extends \PHPUnit\Framework\TestCase { /** * Test if exception is thrown when not anonymous filter is without name. - * - * @expectedException \LogicException - * @expectedExceptionMessage In not anonymous filters filter name must be set. */ public function testIfExceptionIsThrown() { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('In not anonymous filters filter name must be set.'); $mock = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface')->getMock(); $aggregation = new FiltersAggregation('test_agg'); $aggregation->addFilter($mock); @@ -62,7 +60,7 @@ public function testToArray() { $aggregation = new FiltersAggregation('test_agg'); $filter = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface') - ->setMethods(['toArray', 'getType']) + ->onlyMethods(['toArray', 'getType']) ->getMockForAbstractClass(); $filter->expects($this->any()) ->method('toArray') @@ -95,9 +93,7 @@ public function testToArray() */ public function testConstructorFilter() { - /** @var BuilderInterface|\PHPUnit_Framework_MockObject_MockObject $builderInterface1 */ $builderInterface1 = $this->getMockForAbstractClass('ONGR\ElasticsearchDSL\BuilderInterface'); - /** @var BuilderInterface|\PHPUnit_Framework_MockObject_MockObject $builderInterface2 */ $builderInterface2 = $this->getMockForAbstractClass('ONGR\ElasticsearchDSL\BuilderInterface'); $aggregation = new FiltersAggregation( diff --git a/tests/Unit/Aggregation/Bucketing/GeoDistanceAggregationTest.php b/tests/Unit/Aggregation/Bucketing/GeoDistanceAggregationTest.php index 89f2f5d5..5f95f6d1 100644 --- a/tests/Unit/Aggregation/Bucketing/GeoDistanceAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/GeoDistanceAggregationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Bucketing; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\GeoDistanceAggregation; @@ -17,12 +17,11 @@ class GeoDistanceAggregationTest extends \PHPUnit\Framework\TestCase { /** * Test if exception is thrown when field is not set. - * - * @expectedException \LogicException - * @expectedExceptionMessage Geo distance aggregation must have a field set. */ public function testGeoDistanceAggregationExceptionWhenFieldIsNotSet() { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Geo distance aggregation must have a field set.'); $agg = new GeoDistanceAggregation('test_agg'); $agg->setOrigin('50, 70'); $agg->getArray(); @@ -30,12 +29,11 @@ public function testGeoDistanceAggregationExceptionWhenFieldIsNotSet() /** * Test if exception is thrown when origin is not set. - * - * @expectedException \LogicException - * @expectedExceptionMessage Geo distance aggregation must have an origin set. */ public function testGeoDistanceAggregationExceptionWhenOriginIsNotSet() { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Geo distance aggregation must have an origin set.'); $agg = new GeoDistanceAggregation('test_agg'); $agg->setField('location'); $agg->getArray(); @@ -43,12 +41,11 @@ public function testGeoDistanceAggregationExceptionWhenOriginIsNotSet() /** * Test if exception is thrown when field is not set. - * - * @expectedException \LogicException - * @expectedExceptionMessage Either from or to must be set. Both cannot be null. */ public function testGeoDistanceAggregationAddRangeException() { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Either from or to must be set. Both cannot be null.'); $agg = new GeoDistanceAggregation('test_agg'); $agg->addRange(); } @@ -58,7 +55,7 @@ public function testGeoDistanceAggregationAddRangeException() * * @return array */ - public function testGeoDistanceAggregationGetArrayDataProvider() + public function getGeoDistanceAggregationGetArrayDataProvider() { $out = []; $filterData = [ @@ -88,7 +85,7 @@ public function testGeoDistanceAggregationGetArrayDataProvider() * @param array $filterData * @param array $expected * - * @dataProvider testGeoDistanceAggregationGetArrayDataProvider + * @dataProvider getGeoDistanceAggregationGetArrayDataProvider */ public function testGeoDistanceAggregationGetArray($filterData, $expected) { diff --git a/tests/Unit/Aggregation/Bucketing/GeoHashGridAggregationTest.php b/tests/Unit/Aggregation/Bucketing/GeoHashGridAggregationTest.php index 1ef28d34..f2791195 100644 --- a/tests/Unit/Aggregation/Bucketing/GeoHashGridAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/GeoHashGridAggregationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Bucketing; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\GeoHashGridAggregation; @@ -20,11 +20,10 @@ class GeoHashGridAggregationTest extends \PHPUnit\Framework\TestCase { /** * Test if exception is thrown. - * - * @expectedException \LogicException */ public function testGeoHashGridAggregationException() { + $this->expectException(\LogicException::class); $agg = new GeoHashGridAggregation('test_agg'); $agg->getArray(); } diff --git a/tests/Unit/Aggregation/Bucketing/GlobalAggregationTest.php b/tests/Unit/Aggregation/Bucketing/GlobalAggregationTest.php index 725ed283..4e499f6f 100644 --- a/tests/Unit/Aggregation/Bucketing/GlobalAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/GlobalAggregationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Bucketing; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\GlobalAggregation; @@ -74,11 +74,10 @@ public function testToArray($aggregation, $expectedResult) /** * Test for setField method on global aggregation. - * - * @expectedException \LogicException */ public function testSetField() { + $this->expectException(\LogicException::class); $aggregation = new GlobalAggregation('test_agg'); $aggregation->setField('test_field'); } diff --git a/tests/Unit/Aggregation/Bucketing/Ipv4RangeAggregationTest.php b/tests/Unit/Aggregation/Bucketing/Ipv4RangeAggregationTest.php index 7566efe8..28543c02 100644 --- a/tests/Unit/Aggregation/Bucketing/Ipv4RangeAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/Ipv4RangeAggregationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Bucketing; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\Ipv4RangeAggregation; @@ -17,11 +17,10 @@ class Ipv4RangeAggregationTest extends \PHPUnit\Framework\TestCase { /** * Test exception when field and range are not set. - * - * @expectedException \LogicException */ public function testIfExceptionIsThrownWhenFieldAndRangeAreNotSet() { + $this->expectException(\LogicException::class); $agg = new Ipv4RangeAggregation('foo'); $agg->toArray(); } diff --git a/tests/Unit/Aggregation/Bucketing/MissingAggregationTest.php b/tests/Unit/Aggregation/Bucketing/MissingAggregationTest.php index 613d97ba..d29c4f01 100644 --- a/tests/Unit/Aggregation/Bucketing/MissingAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/MissingAggregationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Bucketing; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\MissingAggregation; @@ -17,12 +17,11 @@ class MissingAggregationTest extends \PHPUnit\Framework\TestCase { /** * Test if exception is thrown when field is not set. - * - * @expectedException \LogicException - * @expectedExceptionMessage Missing aggregation must have a field set. */ public function testIfExceptionIsThrown() { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Missing aggregation must have a field set.'); $agg = new MissingAggregation('test_agg'); $agg->getArray(); } diff --git a/tests/Unit/Aggregation/Bucketing/NestedAggregationTest.php b/tests/Unit/Aggregation/Bucketing/NestedAggregationTest.php index b4458f12..cfc4b4f4 100644 --- a/tests/Unit/Aggregation/Bucketing/NestedAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/NestedAggregationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Bucketing; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\NestedAggregation; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\TermsAggregation; diff --git a/tests/Unit/Aggregation/Bucketing/RangeAggregationTest.php b/tests/Unit/Aggregation/Bucketing/RangeAggregationTest.php index 55134a86..59f53acd 100644 --- a/tests/Unit/Aggregation/Bucketing/RangeAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/RangeAggregationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Bucketing; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\RangeAggregation; diff --git a/tests/Unit/Aggregation/Bucketing/ReverseNestedAggregationTest.php b/tests/Unit/Aggregation/Bucketing/ReverseNestedAggregationTest.php index 11ed18f7..a88f58b0 100644 --- a/tests/Unit/Aggregation/Bucketing/ReverseNestedAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/ReverseNestedAggregationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Bucketing; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\ReverseNestedAggregation; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\TermsAggregation; diff --git a/tests/Unit/Aggregation/Bucketing/SamplerAggregationTest.php b/tests/Unit/Aggregation/Bucketing/SamplerAggregationTest.php index 0bbb209b..a0ee85f5 100644 --- a/tests/Unit/Aggregation/Bucketing/SamplerAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/SamplerAggregationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Bucketing; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\SamplerAggregation; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\TermsAggregation; diff --git a/tests/Unit/Aggregation/Bucketing/SignificantTermsAggregationTest.php b/tests/Unit/Aggregation/Bucketing/SignificantTermsAggregationTest.php index c6cf2133..699fb5bb 100644 --- a/tests/Unit/Aggregation/Bucketing/SignificantTermsAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/SignificantTermsAggregationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Bucketing; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\SignificantTermsAggregation; diff --git a/tests/Unit/Aggregation/Bucketing/SignificantTextAggregationTest.php b/tests/Unit/Aggregation/Bucketing/SignificantTextAggregationTest.php index 23b96f3f..d268eefe 100644 --- a/tests/Unit/Aggregation/Bucketing/SignificantTextAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/SignificantTextAggregationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Bucketing; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\SignificantTextAggregation; diff --git a/tests/Unit/Aggregation/Bucketing/TermsAggregationTest.php b/tests/Unit/Aggregation/Bucketing/TermsAggregationTest.php index 47924419..dc46b7df 100644 --- a/tests/Unit/Aggregation/Bucketing/TermsAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/TermsAggregationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Bucketing; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\TermsAggregation; diff --git a/tests/Unit/Aggregation/Metric/CardinalityAggregationTest.php b/tests/Unit/Aggregation/Metric/CardinalityAggregationTest.php index 8ec9f2cf..7ebe6d1c 100644 --- a/tests/Unit/Aggregation/Metric/CardinalityAggregationTest.php +++ b/tests/Unit/Aggregation/Metric/CardinalityAggregationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Metric\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Metric; use ONGR\ElasticsearchDSL\Aggregation\Metric\CardinalityAggregation; @@ -52,12 +52,11 @@ public function testGetArray() /** * Tests if CardinalityAggregation#getArray throws exception when expected. - * - * @expectedException \LogicException - * @expectedExceptionMessage Cardinality aggregation must have field or script set. */ public function testGetArrayException() { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Cardinality aggregation must have field or script set.'); $aggregation = new CardinalityAggregation('bar'); $aggregation->getArray(); } diff --git a/tests/Unit/Aggregation/Metric/GeoBoundsAggregationTest.php b/tests/Unit/Aggregation/Metric/GeoBoundsAggregationTest.php index efccb9ba..8e22e071 100644 --- a/tests/Unit/Aggregation/Metric/GeoBoundsAggregationTest.php +++ b/tests/Unit/Aggregation/Metric/GeoBoundsAggregationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Metric\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Metric; use ONGR\ElasticsearchDSL\Aggregation\Metric\GeoBoundsAggregation; @@ -20,11 +20,10 @@ class GeoBoundsAggregationTest extends \PHPUnit\Framework\TestCase { /** * Test if exception is thrown. - * - * @expectedException \LogicException */ public function testGeoBoundsAggregationException() { + $this->expectException(\LogicException::class); $agg = new GeoBoundsAggregation('test_agg'); $agg->getArray(); } diff --git a/tests/Unit/Aggregation/Metric/GeoCentroidAggregationTest.php b/tests/Unit/Aggregation/Metric/GeoCentroidAggregationTest.php index dca14573..759b33f5 100644 --- a/tests/Unit/Aggregation/Metric/GeoCentroidAggregationTest.php +++ b/tests/Unit/Aggregation/Metric/GeoCentroidAggregationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Metric\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Metric; use ONGR\ElasticsearchDSL\Aggregation\Metric\GeoCentroidAggregation; @@ -20,11 +20,10 @@ class GeoCentroidAggregationTest extends \PHPUnit\Framework\TestCase { /** * Test if exception is thrown when field is not provided - * - * @expectedException \LogicException */ public function testGetArrayException() { + $this->expectException(\LogicException::class); $aggregation = new GeoCentroidAggregation('foo'); $aggregation->getArray(); } diff --git a/tests/Unit/Aggregation/Metric/PercentileRanksAggregationTest.php b/tests/Unit/Aggregation/Metric/PercentileRanksAggregationTest.php index 12aeffcc..c4187532 100644 --- a/tests/Unit/Aggregation/Metric/PercentileRanksAggregationTest.php +++ b/tests/Unit/Aggregation/Metric/PercentileRanksAggregationTest.php @@ -9,9 +9,10 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Metric\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Metric; use ONGR\ElasticsearchDSL\Aggregation\Metric\PercentileRanksAggregation; +use phpDocumentor\Reflection\Types\Void_; /** * Percentile ranks aggregation unit tests. @@ -26,39 +27,36 @@ class PercentileRanksAggregationTest extends \PHPUnit\Framework\TestCase /** * Phpunit setup. */ - public function setUp() + public function setUp(): void { $this->agg = new PercentileRanksAggregation('foo'); } /** * Tests if exception is thrown when required parameters not set. - * - * @expectedException \LogicException */ public function testIfPercentileRanksAggregationThrowsAnException() { + $this->expectException(\LogicException::class); $this->agg->toArray(); } /** * Tests exception when only field is set. - * - * @expectedException \LogicException */ public function testIfExceptionIsThrownWhenFieldSetAndValueNotSet() { + $this->expectException(\LogicException::class); $this->agg->setField('bar'); $this->agg->toArray(); } /** * Tests exception when only value is set. - * - * @expectedException \LogicException */ public function testIfExceptionIsThrownWhenScriptSetAndValueNotSet() { + $this->expectException(\LogicException::class); $this->agg->setScript('bar'); $this->agg->toArray(); } diff --git a/tests/Unit/Aggregation/Metric/PercentilesAggregationTest.php b/tests/Unit/Aggregation/Metric/PercentilesAggregationTest.php index aa98aa3e..a22b80b8 100644 --- a/tests/Unit/Aggregation/Metric/PercentilesAggregationTest.php +++ b/tests/Unit/Aggregation/Metric/PercentilesAggregationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Metric\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Metric; use ONGR\ElasticsearchDSL\Aggregation\Metric\PercentilesAggregation; @@ -17,12 +17,11 @@ class PercentilesAggregationTest extends \PHPUnit\Framework\TestCase { /** * Tests if PercentilesAggregation#getArray throws exception when expected. - * - * @expectedException \LogicException - * @expectedExceptionMessage Percentiles aggregation must have field or script set. */ public function testPercentilesAggregationGetArrayException() { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Percentiles aggregation must have field or script set.'); $aggregation = new PercentilesAggregation('bar'); $aggregation->getArray(); } diff --git a/tests/Unit/Aggregation/Metric/StatsAggregationTest.php b/tests/Unit/Aggregation/Metric/StatsAggregationTest.php index e130641e..991f18e2 100644 --- a/tests/Unit/Aggregation/Metric/StatsAggregationTest.php +++ b/tests/Unit/Aggregation/Metric/StatsAggregationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Metric\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Metric; use ONGR\ElasticsearchDSL\Aggregation\Metric\StatsAggregation; diff --git a/tests/Unit/Aggregation/Metric/TopHitsAggregationTest.php b/tests/Unit/Aggregation/Metric/TopHitsAggregationTest.php index f6018dc8..65824e92 100644 --- a/tests/Unit/Aggregation/Metric/TopHitsAggregationTest.php +++ b/tests/Unit/Aggregation/Metric/TopHitsAggregationTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Metric\Aggregation; +namespace ONGR\ElasticsearchDSL\Tests\Unit\Aggregation\Metric; use ONGR\ElasticsearchDSL\Aggregation\Metric\TopHitsAggregation; use ONGR\ElasticsearchDSL\Sort\FieldSort; diff --git a/tests/Unit/Aggregation/Pipeline/BucketScriptAggregationTest.php b/tests/Unit/Aggregation/Pipeline/BucketScriptAggregationTest.php index 16c85b62..9754ab46 100644 --- a/tests/Unit/Aggregation/Pipeline/BucketScriptAggregationTest.php +++ b/tests/Unit/Aggregation/Pipeline/BucketScriptAggregationTest.php @@ -50,12 +50,11 @@ public function testToArray() /** * Tests if the exception is thrown in getArray method if no * buckets_path or script is set - * - * @expectedException \LogicException - * @expectedExceptionMessage `test` aggregation must have script set. */ public function testGetArrayException() { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('`test` aggregation must have script set.'); $agg = new BucketScriptAggregation('test', []); $agg->getArray(); diff --git a/tests/Unit/Aggregation/Pipeline/BucketSelectorAggregationTest.php b/tests/Unit/Aggregation/Pipeline/BucketSelectorAggregationTest.php index c8edbc9c..83a45453 100644 --- a/tests/Unit/Aggregation/Pipeline/BucketSelectorAggregationTest.php +++ b/tests/Unit/Aggregation/Pipeline/BucketSelectorAggregationTest.php @@ -48,12 +48,11 @@ public function testToArray() /** * Tests if the exception is thrown in getArray method if no * buckets_path or script is set - * - * @expectedException \LogicException - * @expectedExceptionMessage `test` aggregation must have script set. */ public function testGetArrayException() { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('`test` aggregation must have script set.'); $agg = new BucketSelectorAggregation('test', []); $agg->getArray(); diff --git a/tests/Unit/BuilderBagTest.php b/tests/Unit/BuilderBagTest.php index 49d6a2ff..7749c4c4 100644 --- a/tests/Unit/BuilderBagTest.php +++ b/tests/Unit/BuilderBagTest.php @@ -13,6 +13,7 @@ use ONGR\ElasticsearchDSL\BuilderBag; use ONGR\ElasticsearchDSL\BuilderInterface; +use PHPUnit\Framework\MockObject\MockBuilder; class BuilderBagTest extends \PHPUnit\Framework\TestCase { @@ -79,12 +80,13 @@ public function testGet() * * @param string $name * - * @return \PHPUnit_Framework_MockObject_MockObject|BuilderInterface + * @return MockBuilder|BuilderInterface */ private function getBuilder($name) { $friendlyBuilderMock = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface') - ->setMethods(['getName', 'toArray', 'getType']) + ->onlyMethods(['toArray', 'getType']) + ->addMethods(['getName']) ->disableOriginalConstructor() ->getMock(); diff --git a/tests/Unit/ParametersTraitTest.php b/tests/Unit/ParametersTraitTest.php index d456e288..cd9c25d7 100644 --- a/tests/Unit/ParametersTraitTest.php +++ b/tests/Unit/ParametersTraitTest.php @@ -11,6 +11,7 @@ namespace ONGR\ElasticsearchDSL\Tests\Unit; +use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation; use ONGR\ElasticsearchDSL\ParametersTrait; /** @@ -26,7 +27,7 @@ class ParametersTraitTest extends \PHPUnit\Framework\TestCase /** * {@inheritdoc} */ - public function setUp() + public function setUp(): void { $this->parametersTraitMock = $this->getMockForTrait('ONGR\ElasticsearchDSL\ParametersTrait'); } @@ -36,9 +37,10 @@ public function setUp() */ public function testGetAndAddParameter() { - $this->parametersTraitMock->addParameter('acme', 123); + $this->assertTrue(is_object($this->parametersTraitMock->addParameter('acme', 123))); $this->assertEquals(123, $this->parametersTraitMock->getParameter('acme')); $this->parametersTraitMock->addParameter('bar', 321); $this->assertEquals(321, $this->parametersTraitMock->getParameter('bar')); + $this->assertTrue(is_object($this->parametersTraitMock->removeParameter('acme'))); } } diff --git a/tests/Unit/Query/Compound/BoolQueryTest.php b/tests/Unit/Query/Compound/BoolQueryTest.php index 93fe2db7..959ca075 100644 --- a/tests/Unit/Query/Compound/BoolQueryTest.php +++ b/tests/Unit/Query/Compound/BoolQueryTest.php @@ -22,12 +22,11 @@ class BoolQueryTest extends \PHPUnit\Framework\TestCase { /** * Test for addToBool() without setting a correct bool operator. - * - * @expectedException \UnexpectedValueException - * @expectedExceptionMessage The bool operator acme is not supported */ public function testBoolAddToBoolException() { + $this->expectException(\UnexpectedValueException::class); + $this->expectExceptionMessage('The bool operator acme is not supported'); $bool = new BoolQuery(); $bool->add(new MatchAllQuery(), 'acme'); } @@ -81,12 +80,11 @@ public function testBoolConstructor() /** * Tests exception thrown if invalid BoolQuery type key is specified - * - * @expectedException \UnexpectedValueException - * @expectedExceptionMessage The bool operator acme is not supported */ public function testBoolConstructorException() { + $this->expectException(\UnexpectedValueException::class); + $this->expectExceptionMessage('The bool operator acme is not supported'); new BoolQuery([ 'acme' => [new TermQuery('key1', 'value1')], ]); @@ -190,7 +188,7 @@ public function testGetQueriesEmpty() { $bool = new BoolQuery(); - $this->assertInternalType('array', $bool->getQueries()); + $this->assertIsArray($bool->getQueries()); } /** @@ -215,7 +213,7 @@ public function testGetQueriesByBoolTypeEmpty() { $bool = new BoolQuery(); - $this->assertInternalType('array', $bool->getQueries(BoolQuery::MUST)); + $this->assertIsArray($bool->getQueries(BoolQuery::MUST)); } /** diff --git a/tests/Unit/Query/Compound/FunctionScoreQueryTest.php b/tests/Unit/Query/Compound/FunctionScoreQueryTest.php index 9997b0b7..7904aa72 100644 --- a/tests/Unit/Query/Compound/FunctionScoreQueryTest.php +++ b/tests/Unit/Query/Compound/FunctionScoreQueryTest.php @@ -11,10 +11,8 @@ namespace ONGR\ElasticsearchDSL\Tests\Unit\Query\Compound; -use ONGR\ElasticsearchDSL\BuilderInterface; use ONGR\ElasticsearchDSL\Query\Compound\FunctionScoreQuery; use ONGR\ElasticsearchDSL\Query\MatchAllQuery; -use PHPUnit_Framework_MockObject_MockObject as MockObject; /** * Tests for FunctionScoreQuery. @@ -66,21 +64,19 @@ public function addRandomFunctionProvider() */ public function testAddRandomFunction($seed, $expectedArray) { - /** @var MatchAllQuery|MockObject $matchAllQuery */ - $matchAllQuery = $this->getMockBuilder('ONGR\ElasticsearchDSL\Query\MatchAllQuery')->getMock(); + $matchAllQuery = $this->getMockBuilder(MatchAllQuery::class)->getMock(); $functionScoreQuery = new FunctionScoreQuery($matchAllQuery); $functionScoreQuery->addRandomFunction($seed); $this->assertEquals(['function_score' => $expectedArray], $functionScoreQuery->toArray()); } - + /** * Tests default argument values. */ public function testAddFieldValueFactorFunction() { - /** @var BuilderInterface|MockObject $builderInterface */ $builderInterface = $this->getMockForAbstractClass('ONGR\ElasticsearchDSL\BuilderInterface'); $functionScoreQuery = new FunctionScoreQuery($builderInterface); $functionScoreQuery->addFieldValueFactorFunction('field1', 2); diff --git a/tests/Unit/Query/Geo/GeoBoundingBoxQueryTest.php b/tests/Unit/Query/Geo/GeoBoundingBoxQueryTest.php index bc9c01b1..6ff94107 100644 --- a/tests/Unit/Query/Geo/GeoBoundingBoxQueryTest.php +++ b/tests/Unit/Query/Geo/GeoBoundingBoxQueryTest.php @@ -17,11 +17,10 @@ class GeoBoundingBoxQueryTest extends \PHPUnit\Framework\TestCase { /** * Test if exception is thrown when geo points are not set. - * - * @expectedException \LogicException */ public function testGeoBoundBoxQueryException() { + $this->expectException(\LogicException::class); $query = new GeoBoundingBoxQuery('location', []); $query->toArray(); } diff --git a/tests/Unit/Query/Span/SpanContainingQueryTest.php b/tests/Unit/Query/Span/SpanContainingQueryTest.php index 71411abf..a6cd16a0 100644 --- a/tests/Unit/Query/Span/SpanContainingQueryTest.php +++ b/tests/Unit/Query/Span/SpanContainingQueryTest.php @@ -12,6 +12,7 @@ namespace ONGR\ElasticsearchDSL\Tests\Unit\Query\Span; use ONGR\ElasticsearchDSL\Query\Span\SpanContainingQuery; +use PHPUnit\Framework\MockObject\MockBuilder; /** * Unit test for SpanContainingQuery. @@ -43,7 +44,7 @@ public function testToArray() /** * @param string $value * - * @returns \PHPUnit_Framework_MockObject_MockObject + * @returns MockBuilder */ private function getSpanQueryMock($value) { diff --git a/tests/Unit/Query/Span/SpanOrQueryTest.php b/tests/Unit/Query/Span/SpanOrQueryTest.php index 537caf44..6aa203d3 100644 --- a/tests/Unit/Query/Span/SpanOrQueryTest.php +++ b/tests/Unit/Query/Span/SpanOrQueryTest.php @@ -43,7 +43,7 @@ public function testToArray() $this->assertEquals($result, $query->toArray()); $result = $query->getQueries(); - $this->assertInternalType('array', $result); + $this->assertIsArray($result); $this->assertEquals(1, count($result)); } } diff --git a/tests/Unit/Query/Span/SpanWithinQueryTest.php b/tests/Unit/Query/Span/SpanWithinQueryTest.php index d0a7c160..550e37be 100644 --- a/tests/Unit/Query/Span/SpanWithinQueryTest.php +++ b/tests/Unit/Query/Span/SpanWithinQueryTest.php @@ -12,6 +12,7 @@ namespace ONGR\ElasticsearchDSL\Tests\Unit\Query\Span; use ONGR\ElasticsearchDSL\Query\Span\SpanWithinQuery; +use PHPUnit\Framework\MockObject\MockBuilder; /** * Unit test for SpanWithinQuery. @@ -43,7 +44,7 @@ public function testToArray() /** * @param string $value * - * @returns \PHPUnit_Framework_MockObject_MockObject + * @returns MockBuilder */ private function getSpanQueryMock($value) { diff --git a/tests/Unit/Query/Specialized/TemplateQueryTest.php b/tests/Unit/Query/Specialized/TemplateQueryTest.php index 80e497a5..12c6e0d8 100644 --- a/tests/Unit/Query/Specialized/TemplateQueryTest.php +++ b/tests/Unit/Query/Specialized/TemplateQueryTest.php @@ -56,11 +56,10 @@ public function testToArrayFile() /** * Tests toArray() exception - * - * @expectedException \InvalidArgumentException */ public function testToArrayException() { + $this->expectException(\InvalidArgumentException::class); $query = new TemplateQuery(); $query->toArray(); } diff --git a/tests/Unit/SearchEndpoint/AggregationsEndpointTest.php b/tests/Unit/SearchEndpoint/AggregationsEndpointTest.php index 016c1ff7..bc7489fd 100644 --- a/tests/Unit/SearchEndpoint/AggregationsEndpointTest.php +++ b/tests/Unit/SearchEndpoint/AggregationsEndpointTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Unit\SearchEndpoint; +namespace ONGR\ElasticsearchDSL\Tests\Unit\SearchEndpoint; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\MissingAggregation; use ONGR\ElasticsearchDSL\SearchEndpoint\AggregationsEndpoint; diff --git a/tests/Unit/SearchEndpoint/HighlightEndpointTest.php b/tests/Unit/SearchEndpoint/HighlightEndpointTest.php index 5b1a623f..6306b694 100644 --- a/tests/Unit/SearchEndpoint/HighlightEndpointTest.php +++ b/tests/Unit/SearchEndpoint/HighlightEndpointTest.php @@ -9,12 +9,11 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Unit\SearchEndpoint; +namespace ONGR\ElasticsearchDSL\Tests\Unit\SearchEndpoint; use ONGR\ElasticsearchDSL\Highlight\Highlight; use ONGR\ElasticsearchDSL\SearchEndpoint\HighlightEndpoint; use Symfony\Component\Serializer\Normalizer\NormalizerInterface; -use PHPUnit_Framework_MockObject_MockObject as MockObject; /** * Class HighlightEndpointTest. @@ -26,7 +25,7 @@ class HighlightEndpointTest extends \PHPUnit\Framework\TestCase */ public function testItCanBeInstantiated() { - $this->assertInstanceOf('ONGR\ElasticsearchDSL\SearchEndpoint\HighlightEndpoint', new HighlightEndpoint()); + $this->assertInstanceOf(HighlightEndpoint::class, new HighlightEndpoint()); } /** @@ -35,9 +34,8 @@ public function testItCanBeInstantiated() public function testNormalization() { $instance = new HighlightEndpoint(); - /** @var NormalizerInterface|MockObject $normalizerInterface */ $normalizerInterface = $this->getMockForAbstractClass( - 'Symfony\Component\Serializer\Normalizer\NormalizerInterface' + NormalizerInterface::class ); $this->assertNull($instance->normalize($normalizerInterface)); diff --git a/tests/Unit/SearchEndpoint/InnerHitsEndpointTest.php b/tests/Unit/SearchEndpoint/InnerHitsEndpointTest.php index 26e2a7a3..c726cbdf 100644 --- a/tests/Unit/SearchEndpoint/InnerHitsEndpointTest.php +++ b/tests/Unit/SearchEndpoint/InnerHitsEndpointTest.php @@ -9,7 +9,7 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Unit\SearchEndpoint; +namespace ONGR\ElasticsearchDSL\Tests\Unit\SearchEndpoint; use ONGR\ElasticsearchDSL\SearchEndpoint\InnerHitsEndpoint; @@ -54,7 +54,8 @@ public function testNormalization() ->getMock(); $innerHit = $this ->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface') - ->setMethods(['getName', 'toArray', 'getType']) + ->onlyMethods(['toArray', 'getType']) + ->addMethods(['getName']) ->getMock(); $innerHit->expects($this->any())->method('getName')->willReturn('foo'); $innerHit->expects($this->any())->method('toArray')->willReturn(['foo' => 'bar']); diff --git a/tests/Unit/SearchEndpoint/PostFilterEndpointTest.php b/tests/Unit/SearchEndpoint/PostFilterEndpointTest.php index 36adfc3e..52cdb05e 100644 --- a/tests/Unit/SearchEndpoint/PostFilterEndpointTest.php +++ b/tests/Unit/SearchEndpoint/PostFilterEndpointTest.php @@ -9,12 +9,10 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Unit\SearchEndpoint; +namespace ONGR\ElasticsearchDSL\Tests\Unit\SearchEndpoint; use ONGR\ElasticsearchDSL\Query\MatchAllQuery; use ONGR\ElasticsearchDSL\SearchEndpoint\PostFilterEndpoint; -use Symfony\Component\Serializer\Normalizer\NormalizerInterface; -use PHPUnit_Framework_MockObject_MockObject as MockObject; /** * Class PostFilterEndpointTest. @@ -44,7 +42,6 @@ public function testGetOrder() public function testNormalization() { $instance = new PostFilterEndpoint(); - /** @var NormalizerInterface|MockObject $normalizerInterface */ $normalizerInterface = $this->getMockForAbstractClass( 'Symfony\Component\Serializer\Normalizer\NormalizerInterface' ); diff --git a/tests/Unit/SearchEndpoint/QueryEndpointTest.php b/tests/Unit/SearchEndpoint/QueryEndpointTest.php index 5d28e152..a72813c8 100644 --- a/tests/Unit/SearchEndpoint/QueryEndpointTest.php +++ b/tests/Unit/SearchEndpoint/QueryEndpointTest.php @@ -9,12 +9,10 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Unit\SearchEndpoint; +namespace ONGR\ElasticsearchDSL\Tests\Unit\SearchEndpoint; use ONGR\ElasticsearchDSL\Query\MatchAllQuery; use ONGR\ElasticsearchDSL\SearchEndpoint\QueryEndpoint; -use PHPUnit_Framework_MockObject_MockObject as MockObject; -use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** * Unit test class for the QueryEndpoint. @@ -44,7 +42,6 @@ public function testGetOrder() public function testEndpoint() { $instance = new QueryEndpoint(); - /** @var NormalizerInterface|MockObject $normalizerInterface */ $normalizerInterface = $this->getMockForAbstractClass( 'Symfony\Component\Serializer\Normalizer\NormalizerInterface' ); diff --git a/tests/Unit/SearchEndpoint/SearchEndpointFactoryTest.php b/tests/Unit/SearchEndpoint/SearchEndpointFactoryTest.php index b33028bb..8b350909 100644 --- a/tests/Unit/SearchEndpoint/SearchEndpointFactoryTest.php +++ b/tests/Unit/SearchEndpoint/SearchEndpointFactoryTest.php @@ -9,10 +9,11 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Unit\SearchEndpoint; +namespace ONGR\ElasticsearchDSL\Tests\Unit\SearchEndpoint; use ONGR\ElasticsearchDSL\SearchEndpoint\AggregationsEndpoint; use ONGR\ElasticsearchDSL\SearchEndpoint\SearchEndpointFactory; +use ONGR\ElasticsearchDSL\SearchEndpoint\SearchEndpointInterface; /** * Unit test class for search endpoint factory. @@ -21,11 +22,10 @@ class SearchEndpointFactoryTest extends \PHPUnit\Framework\TestCase { /** * Tests get method exception. - * - * @expectedException \RuntimeException */ public function testGet() { + $this->expectException(\RuntimeException::class); SearchEndpointFactory::get('foo'); } @@ -34,6 +34,7 @@ public function testGet() */ public function testFactory() { - SearchEndpointFactory::get(AggregationsEndpoint::NAME); + $endpoint = SearchEndpointFactory::get(AggregationsEndpoint::NAME); + $this->assertInstanceOf(SearchEndpointInterface::class, $endpoint); } } diff --git a/tests/Unit/SearchEndpoint/SortEndpointTest.php b/tests/Unit/SearchEndpoint/SortEndpointTest.php index 7f825bcf..0bafd84a 100644 --- a/tests/Unit/SearchEndpoint/SortEndpointTest.php +++ b/tests/Unit/SearchEndpoint/SortEndpointTest.php @@ -9,12 +9,10 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Unit\SearchEndpoint; +namespace ONGR\ElasticsearchDSL\Tests\Unit\SearchEndpoint; use ONGR\ElasticsearchDSL\SearchEndpoint\SortEndpoint; use ONGR\ElasticsearchDSL\Sort\FieldSort; -use PHPUnit_Framework_MockObject_MockObject as MockObject; -use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** * Class SortEndpointTest. @@ -36,7 +34,6 @@ public function testNormalize() { $instance = new SortEndpoint(); - /** @var NormalizerInterface|MockObject $normalizerInterface */ $normalizerInterface = $this->getMockForAbstractClass( 'Symfony\Component\Serializer\Normalizer\NormalizerInterface' ); diff --git a/tests/Unit/SearchEndpoint/SuggestEndpointTest.php b/tests/Unit/SearchEndpoint/SuggestEndpointTest.php index 34c8704b..41b0550c 100644 --- a/tests/Unit/SearchEndpoint/SuggestEndpointTest.php +++ b/tests/Unit/SearchEndpoint/SuggestEndpointTest.php @@ -9,12 +9,10 @@ * file that was distributed with this source code. */ -namespace ONGR\ElasticsearchDSL\Tests\Unit\Unit\SearchEndpoint; +namespace ONGR\ElasticsearchDSL\Tests\Unit\SearchEndpoint; use ONGR\ElasticsearchDSL\SearchEndpoint\SuggestEndpoint; use ONGR\ElasticsearchDSL\Suggest\Suggest; -use PHPUnit_Framework_MockObject_MockObject as MockObject; -use Symfony\Component\Serializer\Normalizer\NormalizerInterface; class SuggestEndpointTest extends \PHPUnit\Framework\TestCase { @@ -49,7 +47,6 @@ public function testNormalize() { $instance = new SuggestEndpoint(); - /** @var NormalizerInterface|MockObject $normalizerInterface */ $normalizerInterface = $this->getMockForAbstractClass( 'Symfony\Component\Serializer\Normalizer\NormalizerInterface' ); diff --git a/tests/Unit/Sort/FieldSortTest.php b/tests/Unit/Sort/FieldSortTest.php index d8863785..8219283b 100644 --- a/tests/Unit/Sort/FieldSortTest.php +++ b/tests/Unit/Sort/FieldSortTest.php @@ -19,7 +19,6 @@ class FieldSortTest extends \PHPUnit\Framework\TestCase { /** * Test for toArray() method. - * */ public function testToArray() { diff --git a/tests/Unit/Sort/NestedSortTest.php b/tests/Unit/Sort/NestedSortTest.php index 5fb970f1..e49640dc 100644 --- a/tests/Unit/Sort/NestedSortTest.php +++ b/tests/Unit/Sort/NestedSortTest.php @@ -18,7 +18,6 @@ class NestedSortTest extends \PHPUnit\Framework\TestCase { /** * Test for single nested. - * */ public function testSingle() { @@ -37,7 +36,6 @@ public function testSingle() /** * Test for single nested, no filter. - * */ public function testNoFilter() { @@ -51,7 +49,6 @@ public function testNoFilter() /** * Test for single nested. - * */ public function testMultipleNesting() { diff --git a/tests/Unit/Suggest/SuggestTest.php b/tests/Unit/Suggest/SuggestTest.php index 7ae17892..829ae0dc 100644 --- a/tests/Unit/Suggest/SuggestTest.php +++ b/tests/Unit/Suggest/SuggestTest.php @@ -26,8 +26,6 @@ public function testSuggestGetType() /** * Data provider for testToArray() - * - * @return array[] */ public function getTestToArrayData() {