diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index 028ad1ea..1bb037f9 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -16,18 +16,6 @@ jobs: fail-fast: false matrix: include: - - php-version: '7.1' - lint: false - symfony-version: '^2.8' - - - php-version: '7.2' - lint: false - symfony-version: '^3.4' - - - php-version: '7.3' - lint: false - symfony-version: '^4.4' - - php-version: '7.4' lint: true symfony-version: '^5.0' @@ -36,9 +24,13 @@ jobs: lint: true symfony-version: '^5.0' + - php-version: '8.1' + lint: true + symfony-version: '^5.0' + services: elasticsearch: - image: elasticsearch:7.5.2 + image: elasticsearch:8.0.0 ports: - 9200:9200 env: diff --git a/README.md b/README.md index aa8be09b..4549516a 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ With some basic changes to support wider range of Symfony Versions. | Version | Supported Elasticsearch Version | Supported Symfony Version | |---------|---------------------------------|---------------------------| +| 8.x | ^8.0 | ^5.0, | | 7.x | ^7.0 | ^5.0, ^4.0, ^3.4, ^2.8 | | 6.x | ^6.0 | ^5.0, ^4.0, ^3.4, ^2.8 | | 5.x | ^5.0 | ^5.0, ^4.0, ^3.4, ^2.8 | diff --git a/composer.json b/composer.json index 366176d8..61580486 100644 --- a/composer.json +++ b/composer.json @@ -12,15 +12,20 @@ { "name": "Handcrafted in the Alps Team", "homepage": "https://github.com/handcraftedinthealps/ElasticsearchDSL/graphs/contributors" + }, + { + "name": "Haydar KULEKCI", + "homepage": "https://github.com/hkulekci/ElasticsearchDSL/graphs/contributors" } ], "require": { - "php": "^7.1|^8.0", + "php": "^7.4 || ^8.0", "symfony/serializer": "^2.8 || ^3.4 || ^4.0 || ^5.0", - "elasticsearch/elasticsearch": "^7.0" + "elasticsearch/elasticsearch": "8.0.*" }, "require-dev": { - "phpunit/phpunit": "^5.7.26 || ^7.5.20 || ^8.0", + "nyholm/psr7": "^1.5", + "phpunit/phpunit": "^5.7.26 || ^7.5.20 || ^8.0 || ^9.0", "squizlabs/php_codesniffer": "^2.0 || ^3.0" }, "suggest": { diff --git a/docs/Aggregation/Bucketing/DateHistogram.md b/docs/Aggregation/Bucketing/DateHistogram.md index d4a4736a..2d710c4d 100644 --- a/docs/Aggregation/Bucketing/DateHistogram.md +++ b/docs/Aggregation/Bucketing/DateHistogram.md @@ -13,7 +13,7 @@ Example of expressions for interval: `year`, `quarter`, `month`, `week`, `day`, "articles_over_time" : { "date_histogram" : { "field" : "date", - "interval" : "month" + "calendar_interval" : "month" } } } @@ -42,7 +42,7 @@ to provide a custom format to the results of the query: "articles_over_time" : { "date_histogram" : { "field" : "date", - "interval" : "1M", + "calendar_interval" : "1M", "format" : "yyyy-MM-dd" } } @@ -63,4 +63,4 @@ $search->addAggregation($dateHistogramAggregation); $queryArray = $search->toArray(); ``` -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html \ No newline at end of file +[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-datehistogram-aggregation.html diff --git a/docs/Query/FullText/CommonTerms.md b/docs/Query/FullText/CommonTerms.md deleted file mode 100644 index a2307a3a..00000000 --- a/docs/Query/FullText/CommonTerms.md +++ /dev/null @@ -1,46 +0,0 @@ -# Common terms query - -> More info about Common terms query is in the [official elasticsearch docs][1] - -There are so many use cases with `Common Terms` query. We highly recommend to take a look at the [official docs][1] before continuing. - -Lets take first example to write easy `Common query` with Elasticsearch DSL. - -```JSON -{ - "common": { - "name": { - "query": "this is bonsai cool", - "cutoff_frequency": 0.001, - "minimum_should_match": { - "low_freq" : 2, - "high_freq" : 3 - } - } - } -} -``` - -And now the query via DSL: - -```php -$commonTermsQuery = new CommonTermsQuery( - "field_name", - "this is bonsai cool", - [ - "cutoff_frequency" => 0.001, - "minimum_should_match" => [ - "low_freq" => 2, - "high_freq" => 3, - ], - ] -); - -$search = new Search(); -$search->addQuery($commonTermsQuery); - -$queryArray = $search->toArray(); -``` - - -[1]: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-common-terms-query.html diff --git a/src/Aggregation/Bucketing/DateHistogramAggregation.php b/src/Aggregation/Bucketing/DateHistogramAggregation.php index 352b8167..854b79ba 100644 --- a/src/Aggregation/Bucketing/DateHistogramAggregation.php +++ b/src/Aggregation/Bucketing/DateHistogramAggregation.php @@ -28,6 +28,16 @@ class DateHistogramAggregation extends AbstractAggregation */ protected $interval; + /** + * @var string + */ + protected $calendarInterval; + + /** + * @var string + */ + protected $fixedInterval; + /** * @var string */ @@ -37,34 +47,76 @@ class DateHistogramAggregation extends AbstractAggregation * Inner aggregations container init. * * @param string $name - * @param string $field - * @param string $interval + * @param string|null $field + * @param string|null $interval + * @param string|null $format */ - public function __construct($name, $field = null, $interval = null, $format = null) + public function __construct($name, string $field = null, string $interval = null, string $format = null) { parent::__construct($name); $this->setField($field); - $this->setInterval($interval); + $this->setCalendarInterval($interval); $this->setFormat($format); } /** - * @return int + * @return string + * @deprecated use getCalendarInterval instead */ public function getInterval() { - return $this->interval; + return $this->calendarInterval; } /** * @param string $interval + * @deprecated use setCalendarInterval instead * * @return $this */ public function setInterval($interval) { - $this->interval = $interval; + $this->setCalendarInterval($interval); + + return $this; + } + + + /** + * @return string + */ + public function getFixedInterval() + { + return $this->fixedInterval; + } + + /** + * @param string $interval + * @return $this + */ + public function setFixedInterval($interval) + { + $this->fixedInterval = $interval; + + return $this; + } + + /** + * @return string + */ + public function getCalendarInterval() + { + return $this->calendarInterval; + } + + /** + * @param string $interval + * @return $this + */ + public function setCalendarInterval($interval) + { + $this->calendarInterval = $interval; return $this; } @@ -94,15 +146,20 @@ public function getType() */ public function getArray() { - if (!$this->getField() || !$this->getInterval()) { + if (!$this->getField() || !($this->getCalendarInterval() || $this->getFixedInterval())) { throw new \LogicException('Date histogram aggregation must have field and interval set.'); } $out = [ 'field' => $this->getField(), - 'interval' => $this->getInterval(), ]; + if ($this->getCalendarInterval()) { + $out['calendar_interval'] = $this->getCalendarInterval(); + } elseif ($this->getFixedInterval()) { + $out['fixed_interval'] = $this->getFixedInterval(); + } + if (!empty($this->format)) { $out['format'] = $this->format; } diff --git a/src/Aggregation/Metric/PercentilesAggregation.php b/src/Aggregation/Metric/PercentilesAggregation.php index 627bb568..90297e8c 100644 --- a/src/Aggregation/Metric/PercentilesAggregation.php +++ b/src/Aggregation/Metric/PercentilesAggregation.php @@ -39,13 +39,18 @@ class PercentilesAggregation extends AbstractAggregation * Inner aggregations container init. * * @param string $name - * @param string $field - * @param array $percents - * @param string $script - * @param int $compression + * @param string|null $field + * @param array|null $percents + * @param string|null $script + * @param int|null $compression */ - public function __construct($name, $field = null, $percents = null, $script = null, $compression = null) - { + public function __construct( + string $name, + string $field = null, + array $percents = null, + string $script = null, + int $compression = null + ) { parent::__construct($name); $this->setField($field); diff --git a/src/Aggregation/Pipeline/MovingAverageAggregation.php b/src/Aggregation/Pipeline/MovingAverageAggregation.php deleted file mode 100644 index e93fdc5d..00000000 --- a/src/Aggregation/Pipeline/MovingAverageAggregation.php +++ /dev/null @@ -1,28 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ONGR\ElasticsearchDSL\Aggregation\Pipeline; - -/** - * Class representing Max Bucket Pipeline Aggregation. - * - * @link https://goo.gl/8gIfok - */ -class MovingAverageAggregation extends AbstractPipelineAggregation -{ - /** - * {@inheritdoc} - */ - public function getType() - { - return 'moving_avg'; - } -} diff --git a/src/BuilderBag.php b/src/BuilderBag.php index 997667fc..eb79fe2b 100644 --- a/src/BuilderBag.php +++ b/src/BuilderBag.php @@ -100,13 +100,13 @@ public function get($name) * * @return BuilderInterface[] */ - public function all($type = null) + public function all(string $type = null) { return array_filter( $this->bag, /** @var BuilderInterface $builder */ - function (BuilderInterface $builder) use ($type) { - return $type === null || $builder->getType() == $type; + static function (BuilderInterface $builder) use ($type) { + return $type === null || $builder->getType() === $type; } ); } diff --git a/src/Query/FullText/CommonTermsQuery.php b/src/Query/FullText/CommonTermsQuery.php deleted file mode 100644 index 2e31b13b..00000000 --- a/src/Query/FullText/CommonTermsQuery.php +++ /dev/null @@ -1,71 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ONGR\ElasticsearchDSL\Query\FullText; - -use ONGR\ElasticsearchDSL\BuilderInterface; -use ONGR\ElasticsearchDSL\ParametersTrait; - -/** - * Represents Elasticsearch "common" query. - * - * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-common-terms-query.html - */ -class CommonTermsQuery implements BuilderInterface -{ - use ParametersTrait; - - /** - * @var string - */ - private $field; - - /** - * @var string - */ - private $query; - - /** - * @param string $field - * @param string $query - * @param array $parameters - */ - public function __construct($field, $query, array $parameters = []) - { - $this->field = $field; - $this->query = $query; - $this->setParameters($parameters); - } - - /** - * {@inheritdoc} - */ - public function getType() - { - return 'common'; - } - - /** - * {@inheritdoc} - */ - public function toArray() - { - $query = [ - 'query' => $this->query, - ]; - - $output = [ - $this->field => $this->processArray($query), - ]; - - return [$this->getType() => $output]; - } -} diff --git a/src/Query/Geo/GeoShapeQuery.php b/src/Query/Geo/GeoShapeQuery.php index a2a5893a..3ded13ff 100644 --- a/src/Query/Geo/GeoShapeQuery.php +++ b/src/Query/Geo/GeoShapeQuery.php @@ -23,10 +23,10 @@ class GeoShapeQuery implements BuilderInterface { use ParametersTrait; - const INTERSECTS = 'intersects'; - const DISJOINT = 'disjoint'; - const WITHIN = 'within'; - const CONTAINS = 'contains'; + public const INTERSECTS = 'intersects'; + public const DISJOINT = 'disjoint'; + public const WITHIN = 'within'; + public const CONTAINS = 'contains'; /** * @var array @@ -60,13 +60,6 @@ public function getType() */ public function addShape($field, $type, array $coordinates, $relation = self::INTERSECTS, array $parameters = []) { - // TODO: remove this in the next major version - if (is_array($relation)) { - $parameters = $relation; - $relation = self::INTERSECTS; - trigger_error('$parameters as parameter 4 in addShape is deprecated', E_USER_DEPRECATED); - } - $filter = array_merge( $parameters, [ @@ -101,13 +94,6 @@ public function addPreIndexedShape( $relation = self::INTERSECTS, array $parameters = [] ) { - // TODO: remove this in the next major version - if (is_array($relation)) { - $parameters = $relation; - $relation = self::INTERSECTS; - trigger_error('$parameters as parameter 6 in addShape is deprecated', E_USER_DEPRECATED); - } - $filter = array_merge( $parameters, [ diff --git a/tests/Functional/AbstractElasticsearchTestCase.php b/tests/Functional/AbstractElasticsearchTestCase.php index 4765f7c6..6fa1a107 100644 --- a/tests/Functional/AbstractElasticsearchTestCase.php +++ b/tests/Functional/AbstractElasticsearchTestCase.php @@ -11,8 +11,8 @@ namespace ONGR\ElasticsearchDSL\Tests\Functional; -use Elasticsearch\Client; -use Elasticsearch\ClientBuilder; +use Elastic\Elasticsearch\Client; +use Elastic\Elasticsearch\ClientBuilder; use ONGR\ElasticsearchDSL\Search; use PHPUnit\Framework\TestCase; @@ -54,7 +54,6 @@ protected function setUp(): void $bulkBody[] = [ 'index' => [ '_index' => self::INDEX_NAME, - '_type' => $type, '_id' => $id, ] ]; @@ -119,22 +118,23 @@ protected function tearDown(): void * Execute search to the elasticsearch and handle results. * * @param Search $search Search object. - * @param null $type Types to search. Can be several types split by comma. * @param bool $returnRaw Return raw response from the client. * @return array + * @throws \Elastic\Elasticsearch\Exception\ClientResponseException + * @throws \Elastic\Elasticsearch\Exception\MissingParameterException + * @throws \Elastic\Elasticsearch\Exception\ServerResponseException */ - protected function executeSearch(Search $search, $type = null, $returnRaw = false) + protected function executeSearch(Search $search, bool $returnRaw = false): array { $response = $this->client->search( array_filter([ 'index' => self::INDEX_NAME, - 'type' => $type, 'body' => $search->toArray(), ]) ); if ($returnRaw) { - return $response; + return $response->asArray(); } $documents = []; diff --git a/tests/Functional/Aggregation/DateHistogramAggregationTest.php b/tests/Functional/Aggregation/DateHistogramAggregationTest.php new file mode 100644 index 00000000..2f36df66 --- /dev/null +++ b/tests/Functional/Aggregation/DateHistogramAggregationTest.php @@ -0,0 +1,82 @@ + + */ + +namespace ONGR\ElasticsearchDSL\Tests\Functional\Aggregation; + +use ONGR\ElasticsearchDSL\Aggregation\Bucketing\DateHistogramAggregation; +use ONGR\ElasticsearchDSL\Search; +use ONGR\ElasticsearchDSL\Tests\Functional\AbstractElasticsearchTestCase; + +class DateHistogramAggregationTest extends AbstractElasticsearchTestCase +{ + /** + * {@inheritdoc} + */ + protected function getDataArray(): array + { + return [ + 'products' => [ + [ + 'title' => 'acme', + 'price' => 10, + 'created_at' => '2022-01-01T00:02:00Z', + ], + [ + 'title' => 'foo', + 'price' => 20, + 'created_at' => '2022-01-01T00:01:00Z', + ], + [ + 'title' => 'bar', + 'price' => 10, + 'created_at' => '2022-01-01T00:03:00Z', + ], + ] + ]; + } + + /** + * Match all test + */ + public function testDateHistogramWithMinuteCalendarInterval(): void + { + $histogram = new DateHistogramAggregation('dates', 'created_at'); + $histogram->setCalendarInterval('minute'); + + $search = new Search(); + $search->addAggregation($histogram); + $results = $this->executeSearch($search, true); + $this->assertCount(count($this->getDataArray()['products']), $results['aggregations']['dates']['buckets']); + } + + /** + * Match all test + */ + public function testDateHistogramWithMonthCalendarInterval(): void + { + $histogram = new DateHistogramAggregation('dates', 'created_at'); + $histogram->setCalendarInterval('month'); + + $search = new Search(); + $search->addAggregation($histogram); + $results = $this->executeSearch($search, true); + $this->assertCount(1, $results['aggregations']['dates']['buckets']); + } + + /** + * Match all test + */ + public function testDateHistogramWitMinuteFixedInterval(): void + { + $histogram = new DateHistogramAggregation('dates', 'created_at'); + $histogram->setFixedInterval('2m'); + + $search = new Search(); + $search->addAggregation($histogram); + $results = $this->executeSearch($search, true); + $this->assertCount(2, $results['aggregations']['dates']['buckets']); + } +} diff --git a/tests/Unit/Aggregation/Bucketing/ChildrenAggregationTest.php b/tests/Unit/Aggregation/Bucketing/ChildrenAggregationTest.php index f4cb6b3a..9f84d619 100644 --- a/tests/Unit/Aggregation/Bucketing/ChildrenAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/ChildrenAggregationTest.php @@ -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/DateHistogramAggregationTest.php b/tests/Unit/Aggregation/Bucketing/DateHistogramAggregationTest.php index 6f7544bb..b9d7088f 100644 --- a/tests/Unit/Aggregation/Bucketing/DateHistogramAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/DateHistogramAggregationTest.php @@ -12,6 +12,7 @@ namespace ONGR\ElasticsearchDSL\Tests\Unit\Bucketing\Aggregation; use ONGR\ElasticsearchDSL\Aggregation\Bucketing\DateHistogramAggregation; +use ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation; /** * Unit test for children aggregation. @@ -20,15 +21,24 @@ 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(); } + /** + * Tests if ChildrenAggregation#getArray throws exception when expected. + */ + public function testGetArrayExceptionWhenDontSendInterval() + { + $this->expectException(\LogicException::class); + $aggregation = new DateHistogramAggregation('foo', 'date'); + $aggregation->getArray(); + } + /** * Tests getType method. */ @@ -44,15 +54,41 @@ public function testDateHistogramAggregationGetType() */ public function testChildrenAggregationGetArray() { - $mock = $this->getMockBuilder('ONGR\ElasticsearchDSL\Aggregation\AbstractAggregation') + $mock = $this->getMockBuilder(AbstractAggregation::class) ->disableOriginalConstructor() ->getMockForAbstractClass(); $aggregation = new DateHistogramAggregation('foo'); $aggregation->addAggregation($mock); $aggregation->setField('date'); - $aggregation->setInterval('month'); + $aggregation->setCalendarInterval('month'); + $result = $aggregation->getArray(); + $expected = ['field' => 'date', 'calendar_interval' => 'month']; + $this->assertEquals($expected, $result); + } + + /** + * Tests getArray method. + */ + public function testCalendarIntervalGetArray() + { + $aggregation = new DateHistogramAggregation('foo'); + $aggregation->setField('date'); + $aggregation->setCalendarInterval('month'); + $result = $aggregation->getArray(); + $expected = ['field' => 'date', 'calendar_interval' => 'month']; + $this->assertEquals($expected, $result); + } + + /** + * Tests getArray method. + */ + public function testFixedIntervalGetArray() + { + $aggregation = new DateHistogramAggregation('foo'); + $aggregation->setField('date'); + $aggregation->setFixedInterval('month'); $result = $aggregation->getArray(); - $expected = ['field' => 'date', 'interval' => 'month']; + $expected = ['field' => 'date', 'fixed_interval' => 'month']; $this->assertEquals($expected, $result); } } diff --git a/tests/Unit/Aggregation/Bucketing/DateRangeAggregationTest.php b/tests/Unit/Aggregation/Bucketing/DateRangeAggregationTest.php index ca32f902..61482cbd 100644 --- a/tests/Unit/Aggregation/Bucketing/DateRangeAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/DateRangeAggregationTest.php @@ -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->expectExceptionMessage("Date range aggregation must have field, format set and range added."); + $this->expectException(\LogicException::class); $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->expectExceptionMessage("Either from or to must be set. Both cannot be null."); + $this->expectException(\LogicException::class); $agg = new DateRangeAggregation('test_agg'); $agg->addRange(null, null); } @@ -108,9 +106,9 @@ public function getDateRangeAggregationConstructorProvider() /** * Tests constructor method. * - * @param string $field - * @param string $format - * @param array $ranges + * @param null $field + * @param null $format + * @param array|null $ranges * * @dataProvider getDateRangeAggregationConstructorProvider */ diff --git a/tests/Unit/Aggregation/Bucketing/FilterAggregationTest.php b/tests/Unit/Aggregation/Bucketing/FilterAggregationTest.php index c86757be..d53946c9 100644 --- a/tests/Unit/Aggregation/Bucketing/FilterAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/FilterAggregationTest.php @@ -101,24 +101,22 @@ public function testToArray($aggregation, $expectedResult) /** * Test for setField(). - * - * @expectedException \LogicException - * @expectedExceptionMessage doesn't support `field` parameter */ public function testSetField() { + $this->expectExceptionMessage("doesn't support `field` parameter"); + $this->expectException(\LogicException::class); $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->expectExceptionMessage("has no filter added"); + $this->expectException(\LogicException::class); $aggregation = new FilterAggregation('test_agg'); $result = $aggregation->toArray(); diff --git a/tests/Unit/Aggregation/Bucketing/FiltersAggregationTest.php b/tests/Unit/Aggregation/Bucketing/FiltersAggregationTest.php index b3032a31..345dc64f 100644 --- a/tests/Unit/Aggregation/Bucketing/FiltersAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/FiltersAggregationTest.php @@ -21,13 +21,12 @@ 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() { - $mock = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface')->getMock(); + $this->expectExceptionMessage("In not anonymous filters filter name must be set."); + $this->expectException(\LogicException::class); + $mock = $this->getMockBuilder(BuilderInterface::class)->getMock(); $aggregation = new FiltersAggregation('test_agg'); $aggregation->addFilter($mock); } @@ -37,7 +36,7 @@ public function testIfExceptionIsThrown() */ public function testFiltersAggregationGetArray() { - $mock = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface')->getMock(); + $mock = $this->getMockBuilder(BuilderInterface::class)->getMock(); $aggregation = new FiltersAggregation('test_agg'); $aggregation->setAnonymous(true); $aggregation->addFilter($mock, 'name'); @@ -61,7 +60,7 @@ public function testFiltersAggregationGetType() public function testToArray() { $aggregation = new FiltersAggregation('test_agg'); - $filter = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface') + $filter = $this->getMockBuilder(BuilderInterface::class) ->setMethods(['toArray', 'getType']) ->getMockForAbstractClass(); $filter->expects($this->any()) @@ -96,9 +95,9 @@ public function testToArray() public function testConstructorFilter() { /** @var BuilderInterface|\PHPUnit_Framework_MockObject_MockObject $builderInterface1 */ - $builderInterface1 = $this->getMockForAbstractClass('ONGR\ElasticsearchDSL\BuilderInterface'); + $builderInterface1 = $this->getMockForAbstractClass(BuilderInterface::class); /** @var BuilderInterface|\PHPUnit_Framework_MockObject_MockObject $builderInterface2 */ - $builderInterface2 = $this->getMockForAbstractClass('ONGR\ElasticsearchDSL\BuilderInterface'); + $builderInterface2 = $this->getMockForAbstractClass(BuilderInterface::class); $aggregation = new FiltersAggregation( 'test', diff --git a/tests/Unit/Aggregation/Bucketing/GeoDistanceAggregationTest.php b/tests/Unit/Aggregation/Bucketing/GeoDistanceAggregationTest.php index 96fd79fc..5cdc17f7 100644 --- a/tests/Unit/Aggregation/Bucketing/GeoDistanceAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/GeoDistanceAggregationTest.php @@ -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->expectExceptionMessage("Geo distance aggregation must have a field set."); + $this->expectException(\LogicException::class); $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->expectExceptionMessage("Geo distance aggregation must have an origin set."); + $this->expectException(\LogicException::class); $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->expectExceptionMessage("Either from or to must be set. Both cannot be null."); + $this->expectException(\LogicException::class); $agg = new GeoDistanceAggregation('test_agg'); $agg->addRange(); } diff --git a/tests/Unit/Aggregation/Bucketing/GeoHashGridAggregationTest.php b/tests/Unit/Aggregation/Bucketing/GeoHashGridAggregationTest.php index 1ef28d34..17beff12 100644 --- a/tests/Unit/Aggregation/Bucketing/GeoHashGridAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/GeoHashGridAggregationTest.php @@ -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(); } @@ -65,7 +64,7 @@ public function getArrayDataProvider() * * @dataProvider getArrayDataProvider */ - public function testGeoHashGridAggregationGetArray($filterData, $expected) + public function testGeoHashGridAggregationGetArray(array $filterData, array $expected) { $aggregation = new GeoHashGridAggregation('foo'); $aggregation->setPrecision($filterData['precision']); diff --git a/tests/Unit/Aggregation/Bucketing/GlobalAggregationTest.php b/tests/Unit/Aggregation/Bucketing/GlobalAggregationTest.php index 725ed283..1e4db55a 100644 --- a/tests/Unit/Aggregation/Bucketing/GlobalAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/GlobalAggregationTest.php @@ -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..a862cda9 100644 --- a/tests/Unit/Aggregation/Bucketing/Ipv4RangeAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/Ipv4RangeAggregationTest.php @@ -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..1fc8fc74 100644 --- a/tests/Unit/Aggregation/Bucketing/MissingAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/MissingAggregationTest.php @@ -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->expectExceptionMessage("Missing aggregation must have a field set."); + $this->expectException(\LogicException::class); $agg = new MissingAggregation('test_agg'); $agg->getArray(); } diff --git a/tests/Unit/Aggregation/Bucketing/TermsAggregationTest.php b/tests/Unit/Aggregation/Bucketing/TermsAggregationTest.php index 47924419..eb647d6c 100644 --- a/tests/Unit/Aggregation/Bucketing/TermsAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/TermsAggregationTest.php @@ -178,12 +178,12 @@ public function testTermsAggregationSetOrderDESC() // Case #7 terms aggregation with order term mode, desc direction. $aggregation = new TermsAggregation('test_agg'); $aggregation->setField('test_field'); - $aggregation->addParameter('order', ['_term' => 'desc']); + $aggregation->addParameter('order', ['_key' => 'desc']); $result = [ 'terms' => [ 'field' => 'test_field', - 'order' => ['_term' => 'desc'], + 'order' => ['_key' => 'desc'], ], ]; diff --git a/tests/Unit/Aggregation/Metric/CardinalityAggregationTest.php b/tests/Unit/Aggregation/Metric/CardinalityAggregationTest.php index 8ec9f2cf..94fcc0b6 100644 --- a/tests/Unit/Aggregation/Metric/CardinalityAggregationTest.php +++ b/tests/Unit/Aggregation/Metric/CardinalityAggregationTest.php @@ -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->expectExceptionMessage("Cardinality aggregation must have field or script set."); + $this->expectException(\LogicException::class); $aggregation = new CardinalityAggregation('bar'); $aggregation->getArray(); } diff --git a/tests/Unit/Aggregation/Metric/GeoBoundsAggregationTest.php b/tests/Unit/Aggregation/Metric/GeoBoundsAggregationTest.php index efccb9ba..67e424c0 100644 --- a/tests/Unit/Aggregation/Metric/GeoBoundsAggregationTest.php +++ b/tests/Unit/Aggregation/Metric/GeoBoundsAggregationTest.php @@ -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..1aad2750 100644 --- a/tests/Unit/Aggregation/Metric/GeoCentroidAggregationTest.php +++ b/tests/Unit/Aggregation/Metric/GeoCentroidAggregationTest.php @@ -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 ec613c5c..d9be556a 100644 --- a/tests/Unit/Aggregation/Metric/PercentileRanksAggregationTest.php +++ b/tests/Unit/Aggregation/Metric/PercentileRanksAggregationTest.php @@ -34,32 +34,29 @@ public function setUp(): void /** * 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..80e1911f 100644 --- a/tests/Unit/Aggregation/Metric/PercentilesAggregationTest.php +++ b/tests/Unit/Aggregation/Metric/PercentilesAggregationTest.php @@ -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->expectExceptionMessage("Percentiles aggregation must have field or script set."); + $this->expectException(\LogicException::class); $aggregation = new PercentilesAggregation('bar'); $aggregation->getArray(); } diff --git a/tests/Unit/Aggregation/Pipeline/BucketScriptAggregationTest.php b/tests/Unit/Aggregation/Pipeline/BucketScriptAggregationTest.php index 16c85b62..4191fa6b 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->expectExceptionMessage("`test` aggregation must have script set."); + $this->expectException(\LogicException::class); $agg = new BucketScriptAggregation('test', []); $agg->getArray(); diff --git a/tests/Unit/Aggregation/Pipeline/BucketSelectorAggregationTest.php b/tests/Unit/Aggregation/Pipeline/BucketSelectorAggregationTest.php index c8edbc9c..c2b0bf61 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->expectExceptionMessage("`test` aggregation must have script set."); + $this->expectException(\LogicException::class); $agg = new BucketSelectorAggregation('test', []); $agg->getArray(); diff --git a/tests/Unit/Query/Compound/BoolQueryTest.php b/tests/Unit/Query/Compound/BoolQueryTest.php index 93fe2db7..9f25a4de 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->expectExceptionMessage("The bool operator acme is not supported"); + $this->expectException(\UnexpectedValueException::class); $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->expectExceptionMessage("The bool operator acme is not supported"); + $this->expectException(\UnexpectedValueException::class); 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/FullText/CommonTermsQueryTest.php b/tests/Unit/Query/FullText/CommonTermsQueryTest.php deleted file mode 100644 index 8a387132..00000000 --- a/tests/Unit/Query/FullText/CommonTermsQueryTest.php +++ /dev/null @@ -1,35 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace ONGR\ElasticsearchDSL\Tests\Unit\Query\FullText; - -use ONGR\ElasticsearchDSL\Query\FullText\CommonTermsQuery; - -class CommonTermsQueryTest extends \PHPUnit\Framework\TestCase -{ - /** - * Tests toArray(). - */ - public function testToArray() - { - $query = new CommonTermsQuery('body', 'this is bonsai cool', ['cutoff_frequency' => 0.01]); - $expected = [ - 'common' => [ - 'body' => [ - 'query' => 'this is bonsai cool', - 'cutoff_frequency' => 0.01, - ], - ], - ]; - - $this->assertEquals($expected, $query->toArray()); - } -} 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/SpanOrQueryTest.php b/tests/Unit/Query/Span/SpanOrQueryTest.php index 537caf44..d6835d8c 100644 --- a/tests/Unit/Query/Span/SpanOrQueryTest.php +++ b/tests/Unit/Query/Span/SpanOrQueryTest.php @@ -12,6 +12,7 @@ namespace ONGR\ElasticsearchDSL\Tests\Unit\Query\Span; use ONGR\ElasticsearchDSL\Query\Span\SpanOrQuery; +use ONGR\ElasticsearchDSL\Query\Span\SpanQueryInterface; /** * Unit test for SpanOrQuery. @@ -23,7 +24,7 @@ class SpanOrQueryTest extends \PHPUnit\Framework\TestCase */ public function testToArray() { - $mock = $this->getMockBuilder('ONGR\ElasticsearchDSL\Query\Span\SpanQueryInterface')->getMock(); + $mock = $this->getMockBuilder(SpanQueryInterface::class)->getMock(); $mock ->expects($this->once()) ->method('toArray') @@ -43,7 +44,7 @@ public function testToArray() $this->assertEquals($result, $query->toArray()); $result = $query->getQueries(); - $this->assertInternalType('array', $result); - $this->assertEquals(1, count($result)); + $this->assertIsArray($result); + $this->assertCount(1, $result); } } 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..1ed46094 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; @@ -25,7 +25,7 @@ class AggregationsEndpointTest extends \PHPUnit\Framework\TestCase public function testItCanBeInstantiated() { $this->assertInstanceOf( - 'ONGR\ElasticsearchDSL\SearchEndpoint\AggregationsEndpoint', + AggregationsEndpoint::class, new AggregationsEndpoint() ); } diff --git a/tests/Unit/SearchEndpoint/HighlightEndpointTest.php b/tests/Unit/SearchEndpoint/HighlightEndpointTest.php index 55d6080f..45a48bc7 100644 --- a/tests/Unit/SearchEndpoint/HighlightEndpointTest.php +++ b/tests/Unit/SearchEndpoint/HighlightEndpointTest.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\Highlight\Highlight; use ONGR\ElasticsearchDSL\SearchEndpoint\HighlightEndpoint; diff --git a/tests/Unit/SearchEndpoint/InnerHitsEndpointTest.php b/tests/Unit/SearchEndpoint/InnerHitsEndpointTest.php index 26e2a7a3..d61f4257 100644 --- a/tests/Unit/SearchEndpoint/InnerHitsEndpointTest.php +++ b/tests/Unit/SearchEndpoint/InnerHitsEndpointTest.php @@ -9,9 +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\InnerHitsEndpoint; +use ONGR\ElasticsearchDSL\BuilderInterface; +use Symfony\Component\Serializer\Normalizer\NormalizerInterface; /** * Class AggregationsEndpointTest. @@ -24,7 +26,7 @@ class InnerHitsEndpointTest extends \PHPUnit\Framework\TestCase public function testItCanBeInstantiated() { $this->assertInstanceOf( - 'ONGR\ElasticsearchDSL\SearchEndpoint\InnerHitsEndpoint', + InnerHitsEndpoint::class, new InnerHitsEndpoint() ); } @@ -35,7 +37,7 @@ public function testItCanBeInstantiated() public function testEndpointGetter() { $hitName = 'foo'; - $innerHit = $this->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface')->getMock(); + $innerHit = $this->getMockBuilder(BuilderInterface::class)->getMock(); $endpoint = new InnerHitsEndpoint(); $endpoint->add($innerHit, $hitName); $builders = $endpoint->getAll(); @@ -50,10 +52,10 @@ public function testEndpointGetter() public function testNormalization() { $normalizer = $this - ->getMockBuilder('Symfony\Component\Serializer\Normalizer\NormalizerInterface') + ->getMockBuilder(NormalizerInterface::class) ->getMock(); $innerHit = $this - ->getMockBuilder('ONGR\ElasticsearchDSL\BuilderInterface') + ->getMockBuilder(BuilderInterface::class) ->setMethods(['getName', 'toArray', 'getType']) ->getMock(); $innerHit->expects($this->any())->method('getName')->willReturn('foo'); diff --git a/tests/Unit/SearchEndpoint/PostFilterEndpointTest.php b/tests/Unit/SearchEndpoint/PostFilterEndpointTest.php index 36adfc3e..3234e14f 100644 --- a/tests/Unit/SearchEndpoint/PostFilterEndpointTest.php +++ b/tests/Unit/SearchEndpoint/PostFilterEndpointTest.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\Query\MatchAllQuery; use ONGR\ElasticsearchDSL\SearchEndpoint\PostFilterEndpoint; @@ -26,7 +26,7 @@ class PostFilterEndpointTest extends \PHPUnit\Framework\TestCase */ public function testItCanBeInstantiated() { - $this->assertInstanceOf('ONGR\ElasticsearchDSL\SearchEndpoint\PostFilterEndpoint', new PostFilterEndpoint()); + $this->assertInstanceOf(PostFilterEndpoint::class, new PostFilterEndpoint()); } /** @@ -46,7 +46,7 @@ public function testNormalization() $instance = new PostFilterEndpoint(); /** @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/QueryEndpointTest.php b/tests/Unit/SearchEndpoint/QueryEndpointTest.php index 5d28e152..7e5e73e8 100644 --- a/tests/Unit/SearchEndpoint/QueryEndpointTest.php +++ b/tests/Unit/SearchEndpoint/QueryEndpointTest.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\Query\MatchAllQuery; use ONGR\ElasticsearchDSL\SearchEndpoint\QueryEndpoint; @@ -26,7 +26,7 @@ class QueryEndpointTest extends \PHPUnit\Framework\TestCase */ public function testItCanBeInstantiated() { - $this->assertInstanceOf('ONGR\ElasticsearchDSL\SearchEndpoint\QueryEndpoint', new QueryEndpoint()); + $this->assertInstanceOf(QueryEndpoint::class, new QueryEndpoint()); } /** @@ -46,7 +46,7 @@ public function testEndpoint() $instance = new QueryEndpoint(); /** @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/SearchEndpointFactoryTest.php b/tests/Unit/SearchEndpoint/SearchEndpointFactoryTest.php index 3c0da38d..c928f19c 100644 --- a/tests/Unit/SearchEndpoint/SearchEndpointFactoryTest.php +++ b/tests/Unit/SearchEndpoint/SearchEndpointFactoryTest.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\AggregationsEndpoint; use ONGR\ElasticsearchDSL\SearchEndpoint\SearchEndpointFactory; @@ -22,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'); } diff --git a/tests/Unit/SearchEndpoint/SortEndpointTest.php b/tests/Unit/SearchEndpoint/SortEndpointTest.php index 7f825bcf..9397ead8 100644 --- a/tests/Unit/SearchEndpoint/SortEndpointTest.php +++ b/tests/Unit/SearchEndpoint/SortEndpointTest.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\SortEndpoint; use ONGR\ElasticsearchDSL\Sort\FieldSort; @@ -26,7 +26,7 @@ class SortEndpointTest extends \PHPUnit\Framework\TestCase */ public function testItCanBeInstantiated() { - $this->assertInstanceOf('ONGR\ElasticsearchDSL\SearchEndpoint\SortEndpoint', new SortEndpoint()); + $this->assertInstanceOf(SortEndpoint::class, new SortEndpoint()); } /** @@ -38,7 +38,7 @@ public function testNormalize() /** @var NormalizerInterface|MockObject $normalizerInterface */ $normalizerInterface = $this->getMockForAbstractClass( - 'Symfony\Component\Serializer\Normalizer\NormalizerInterface' + NormalizerInterface::class ); $sort = new FieldSort('acme', ['order' => FieldSort::ASC]); diff --git a/tests/Unit/SearchEndpoint/SuggestEndpointTest.php b/tests/Unit/SearchEndpoint/SuggestEndpointTest.php index 34c8704b..6c1bc5de 100644 --- a/tests/Unit/SearchEndpoint/SuggestEndpointTest.php +++ b/tests/Unit/SearchEndpoint/SuggestEndpointTest.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\SuggestEndpoint; use ONGR\ElasticsearchDSL\Suggest\Suggest; @@ -23,7 +23,7 @@ class SuggestEndpointTest extends \PHPUnit\Framework\TestCase */ public function testItCanBeInstantiated() { - $this->assertInstanceOf('ONGR\ElasticsearchDSL\SearchEndpoint\SuggestEndpoint', new SuggestEndpoint()); + $this->assertInstanceOf(SuggestEndpoint::class, new SuggestEndpoint()); } /** @@ -51,7 +51,7 @@ public function testNormalize() /** @var NormalizerInterface|MockObject $normalizerInterface */ $normalizerInterface = $this->getMockForAbstractClass( - 'Symfony\Component\Serializer\Normalizer\NormalizerInterface' + NormalizerInterface::class ); $suggest = new Suggest('foo', 'bar', 'acme', 'foo'); diff --git a/tests/Unit/SearchTest.php b/tests/Unit/SearchTest.php index bfb2f4d3..3454a8e8 100644 --- a/tests/Unit/SearchTest.php +++ b/tests/Unit/SearchTest.php @@ -27,7 +27,7 @@ class SearchTest extends \PHPUnit\Framework\TestCase */ public function testItCanBeInstantiated() { - $this->assertInstanceOf('ONGR\ElasticsearchDSL\Search', new Search()); + $this->assertInstanceOf(Search::class, new Search()); } public function testScrollUriParameter()