diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index 028ad1ea..55ed4e62 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' @@ -38,7 +26,7 @@ jobs: 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..8752c0a9 100644 --- a/composer.json +++ b/composer.json @@ -12,15 +12,19 @@ { "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", + "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..2f544485 100644 --- a/tests/Functional/AbstractElasticsearchTestCase.php +++ b/tests/Functional/AbstractElasticsearchTestCase.php @@ -54,7 +54,6 @@ protected function setUp(): void $bulkBody[] = [ 'index' => [ '_index' => self::INDEX_NAME, - '_type' => $type, '_id' => $id, ] ]; @@ -119,16 +118,14 @@ 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 */ - 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(), ]) ); 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/DateHistogramAggregationTest.php b/tests/Unit/Aggregation/Bucketing/DateHistogramAggregationTest.php index 0a48a869..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. @@ -28,6 +29,16 @@ public function testGetArrayException() $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. */ @@ -43,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/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/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/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 63716a22..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; 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()