diff --git a/.github/workflows/test-application.yaml b/.github/workflows/test-application.yaml index 028ad1ea..0e882996 100644 --- a/.github/workflows/test-application.yaml +++ b/.github/workflows/test-application.yaml @@ -16,25 +16,33 @@ jobs: fail-fast: false matrix: include: - - php-version: '7.1' + - php-version: '8.0' lint: false symfony-version: '^2.8' - - php-version: '7.2' + - php-version: '8.0' lint: false symfony-version: '^3.4' - - php-version: '7.3' + - php-version: '8.0' lint: false symfony-version: '^4.4' - - php-version: '7.4' + - php-version: '8.0' lint: true symfony-version: '^5.0' + - php-version: '8.1' + lint: true + symfony-version: '^5.4' + - php-version: '8.0' lint: true - symfony-version: '^5.0' + symfony-version: '^6.0' + + - php-version: '8.1' + lint: true + symfony-version: '^6.0' services: elasticsearch: diff --git a/README.md b/README.md index aa8be09b..c5b21453 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,15 @@ # ElasticsearchDSL -This is a fork of the [ongr/elasticsearch-dsl](https://github.com/ongr-io/elasticsearchbundle). +This is a fork of the [ongr/elasticsearch-dsl](https://github.com/ongr-io/ElasticsearchDSL). With some basic changes to support wider range of Symfony Versions. -| Version | Supported Elasticsearch Version | Supported Symfony Version | -|---------|---------------------------------|---------------------------| -| 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 | -| 2.x | ^2.0 | ^3.0, ^2.7 | -| 1.x | ^1.0 | ^3.0, ^2.7 | +| Version | Supported Elasticsearch Version | Supported Symfony Version | +|---------|---------------------------------|---------------------------------| +| 7.x | ^7.0 | ^6.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 | +| 2.x | ^2.0 | ^3.0, ^2.7 | +| 1.x | ^1.0 | ^3.0, ^2.7 | ## Documentation diff --git a/composer.json b/composer.json index 366176d8..340706fe 100644 --- a/composer.json +++ b/composer.json @@ -15,8 +15,9 @@ } ], "require": { - "php": "^7.1|^8.0", - "symfony/serializer": "^2.8 || ^3.4 || ^4.0 || ^5.0", + "ext-json": "*", + "php": "^8.0", + "symfony/serializer": "^2.8 || ^3.4 || ^4.0 || ^5.0 || ^6.0", "elasticsearch/elasticsearch": "^7.0" }, "require-dev": { diff --git a/src/SearchEndpoint/AggregationsEndpoint.php b/src/SearchEndpoint/AggregationsEndpoint.php index 079a6a5d..f3776025 100644 --- a/src/SearchEndpoint/AggregationsEndpoint.php +++ b/src/SearchEndpoint/AggregationsEndpoint.php @@ -27,8 +27,11 @@ class AggregationsEndpoint extends AbstractSearchEndpoint /** * {@inheritdoc} */ - public function normalize(NormalizerInterface $normalizer, $format = null, array $context = []) - { + public function normalize( + NormalizerInterface $normalizer, + $format = null, + array $context = [] + ): array|string|int|float|bool { $output = []; if (count($this->getAll()) > 0) { /** @var AbstractAggregation $aggregation */ diff --git a/src/SearchEndpoint/HighlightEndpoint.php b/src/SearchEndpoint/HighlightEndpoint.php index f2b8d8e9..2a35e8cf 100644 --- a/src/SearchEndpoint/HighlightEndpoint.php +++ b/src/SearchEndpoint/HighlightEndpoint.php @@ -37,13 +37,16 @@ class HighlightEndpoint extends AbstractSearchEndpoint /** * {@inheritdoc} */ - public function normalize(NormalizerInterface $normalizer, $format = null, array $context = []) - { + public function normalize( + NormalizerInterface $normalizer, + $format = null, + array $context = [] + ): array|string|int|float|bool { if ($this->highlight) { return $this->highlight->toArray(); } - return null; + return false; } /** diff --git a/src/SearchEndpoint/InnerHitsEndpoint.php b/src/SearchEndpoint/InnerHitsEndpoint.php index f1562fe6..3c7c3fc3 100644 --- a/src/SearchEndpoint/InnerHitsEndpoint.php +++ b/src/SearchEndpoint/InnerHitsEndpoint.php @@ -27,8 +27,11 @@ class InnerHitsEndpoint extends AbstractSearchEndpoint /** * {@inheritdoc} */ - public function normalize(NormalizerInterface $normalizer, $format = null, array $context = []) - { + public function normalize( + NormalizerInterface $normalizer, + $format = null, + array $context = [] + ): array|string|int|float|bool { $output = []; if (count($this->getAll()) > 0) { /** @var NestedInnerHit $innerHit */ diff --git a/src/SearchEndpoint/PostFilterEndpoint.php b/src/SearchEndpoint/PostFilterEndpoint.php index 6055b7ed..95e00b7f 100644 --- a/src/SearchEndpoint/PostFilterEndpoint.php +++ b/src/SearchEndpoint/PostFilterEndpoint.php @@ -26,10 +26,13 @@ class PostFilterEndpoint extends QueryEndpoint /** * {@inheritdoc} */ - public function normalize(NormalizerInterface $normalizer, $format = null, array $context = []) - { + public function normalize( + NormalizerInterface $normalizer, + $format = null, + array $context = [] + ): array|string|int|float|bool { if (!$this->getBool()) { - return null; + return false; } return $this->getBool()->toArray(); diff --git a/src/SearchEndpoint/QueryEndpoint.php b/src/SearchEndpoint/QueryEndpoint.php index 6212b05d..8a98247a 100644 --- a/src/SearchEndpoint/QueryEndpoint.php +++ b/src/SearchEndpoint/QueryEndpoint.php @@ -39,8 +39,11 @@ class QueryEndpoint extends AbstractSearchEndpoint implements OrderedNormalizerI /** * {@inheritdoc} */ - public function normalize(NormalizerInterface $normalizer, $format = null, array $context = []) - { + public function normalize( + NormalizerInterface $normalizer, + $format = null, + array $context = [] + ): array|string|int|float|bool { if (!$this->filtersSet && $this->hasReference('filter_query')) { /** @var BuilderInterface $filter */ $filter = $this->getReference('filter_query'); @@ -49,7 +52,7 @@ public function normalize(NormalizerInterface $normalizer, $format = null, array } if (!$this->bool) { - return null; + return false; } return $this->bool->toArray(); diff --git a/src/SearchEndpoint/SortEndpoint.php b/src/SearchEndpoint/SortEndpoint.php index 2461c858..27def92f 100644 --- a/src/SearchEndpoint/SortEndpoint.php +++ b/src/SearchEndpoint/SortEndpoint.php @@ -26,8 +26,11 @@ class SortEndpoint extends AbstractSearchEndpoint /** * {@inheritdoc} */ - public function normalize(NormalizerInterface $normalizer, $format = null, array $context = []) - { + public function normalize( + NormalizerInterface $normalizer, + $format = null, + array $context = [] + ): array|string|int|float|bool { $output = []; foreach ($this->getAll() as $sort) { diff --git a/src/SearchEndpoint/SuggestEndpoint.php b/src/SearchEndpoint/SuggestEndpoint.php index 2e2e16ac..9c9d8367 100644 --- a/src/SearchEndpoint/SuggestEndpoint.php +++ b/src/SearchEndpoint/SuggestEndpoint.php @@ -27,8 +27,11 @@ class SuggestEndpoint extends AbstractSearchEndpoint /** * {@inheritdoc} */ - public function normalize(NormalizerInterface $normalizer, $format = null, array $context = []) - { + public function normalize( + NormalizerInterface $normalizer, + $format = null, + array $context = [] + ): array|string|int|float|bool { $output = []; if (count($this->getAll()) > 0) { /** @var TermSuggest $suggest */ diff --git a/src/Serializer/Normalizer/CustomReferencedNormalizer.php b/src/Serializer/Normalizer/CustomReferencedNormalizer.php index 6cd24a8e..0d84dd84 100644 --- a/src/Serializer/Normalizer/CustomReferencedNormalizer.php +++ b/src/Serializer/Normalizer/CustomReferencedNormalizer.php @@ -26,20 +26,15 @@ class CustomReferencedNormalizer extends CustomNormalizer /** * {@inheritdoc} */ - public function normalize($object, $format = null, array $context = []) - { + public function normalize( + mixed $object, + $format = null, + array $context = [] + ): array|string|int|float|bool|\ArrayObject|null { $object->setReferences($this->references); $data = parent::normalize($object, $format, $context); $this->references = array_merge($this->references, $object->getReferences()); return $data; } - - /** - * {@inheritdoc} - */ - public function supportsNormalization($data, $format = null) - { - return $data instanceof AbstractNormalizable; - } } diff --git a/src/Serializer/OrderedSerializer.php b/src/Serializer/OrderedSerializer.php index 055c177e..fdb41b9e 100644 --- a/src/Serializer/OrderedSerializer.php +++ b/src/Serializer/OrderedSerializer.php @@ -12,19 +12,34 @@ namespace ONGR\ElasticsearchDSL\Serializer; use ONGR\ElasticsearchDSL\Serializer\Normalizer\OrderedNormalizerInterface; +use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; +use Symfony\Component\Serializer\Normalizer\NormalizerInterface; use Symfony\Component\Serializer\Serializer; /** * Custom serializer which orders data before normalization. */ -class OrderedSerializer extends Serializer +class OrderedSerializer implements NormalizerInterface, DenormalizerInterface { + /** + * @var Serializer + */ + private $serializer; + + /** + * @param array $normalizers + */ + public function __construct(array $normalizers = []) + { + $this->serializer = new Serializer($normalizers); + } + /** * {@inheritdoc} */ public function normalize($data, $format = null, array $context = []) { - return parent::normalize( + return $this->serializer->normalize( is_array($data) ? $this->order($data) : $data, $format, $context @@ -36,7 +51,7 @@ public function normalize($data, $format = null, array $context = []) */ public function denormalize($data, $type, $format = null, array $context = []) { - return parent::denormalize( + return $this->serializer->denormalize( is_array($data) ? $this->order($data) : $data, $type, $format, @@ -85,4 +100,20 @@ function ($value) { } ); } + + /** + * {@inheritdoc} + */ + public function supportsDenormalization($data, $type, $format = null) + { + return $this->serializer->supportsDenormalization($data, $format); + } + + /** + * {@inheritdoc} + */ + public function supportsNormalization($data, $format = null) + { + return $this->serializer->supportsNormalization($data, $format); + } } diff --git a/tests/Unit/Aggregation/Bucketing/AdjacencyMatrixAggregationTest.php b/tests/Unit/Aggregation/Bucketing/AdjacencyMatrixAggregationTest.php index f73cc612..773080ce 100644 --- a/tests/Unit/Aggregation/Bucketing/AdjacencyMatrixAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/AdjacencyMatrixAggregationTest.php @@ -21,12 +21,11 @@ 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() // { +// $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); 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..0a48a869 100644 --- a/tests/Unit/Aggregation/Bucketing/DateHistogramAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/DateHistogramAggregationTest.php @@ -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 ca32f902..175d1881 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->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); } diff --git a/tests/Unit/Aggregation/Bucketing/FilterAggregationTest.php b/tests/Unit/Aggregation/Bucketing/FilterAggregationTest.php index c86757be..e32dbaea 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->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'); $result = $aggregation->toArray(); diff --git a/tests/Unit/Aggregation/Bucketing/FiltersAggregationTest.php b/tests/Unit/Aggregation/Bucketing/FiltersAggregationTest.php index b3032a31..e38dd674 100644 --- a/tests/Unit/Aggregation/Bucketing/FiltersAggregationTest.php +++ b/tests/Unit/Aggregation/Bucketing/FiltersAggregationTest.php @@ -21,12 +21,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); diff --git a/tests/Unit/Aggregation/Bucketing/GeoDistanceAggregationTest.php b/tests/Unit/Aggregation/Bucketing/GeoDistanceAggregationTest.php index 96fd79fc..d7e4953b 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->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(); } diff --git a/tests/Unit/Aggregation/Bucketing/GeoHashGridAggregationTest.php b/tests/Unit/Aggregation/Bucketing/GeoHashGridAggregationTest.php index 1ef28d34..74968ee9 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(); } 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..4e6142f8 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->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/Metric/CardinalityAggregationTest.php b/tests/Unit/Aggregation/Metric/CardinalityAggregationTest.php index 8ec9f2cf..9f168b11 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->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..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..39bea2ef 100644 --- a/tests/Unit/Aggregation/Metric/PercentileRanksAggregationTest.php +++ b/tests/Unit/Aggregation/Metric/PercentileRanksAggregationTest.php @@ -12,7 +12,6 @@ namespace ONGR\ElasticsearchDSL\Tests\Unit\Metric\Aggregation; use ONGR\ElasticsearchDSL\Aggregation\Metric\PercentileRanksAggregation; -use phpDocumentor\Reflection\Types\Void_; /** * Percentile ranks aggregation unit tests. @@ -34,32 +33,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..8406cdef 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->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/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/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/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..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/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/HighlightEndpointTest.php b/tests/Unit/SearchEndpoint/HighlightEndpointTest.php index 55d6080f..1a4d2e3a 100644 --- a/tests/Unit/SearchEndpoint/HighlightEndpointTest.php +++ b/tests/Unit/SearchEndpoint/HighlightEndpointTest.php @@ -40,7 +40,7 @@ public function testNormalization() NormalizerInterface::class ); - $this->assertNull($instance->normalize($normalizerInterface)); + $this->assertFalse($instance->normalize($normalizerInterface)); $highlight = new Highlight(); $highlight->addField('acme'); diff --git a/tests/Unit/SearchEndpoint/PostFilterEndpointTest.php b/tests/Unit/SearchEndpoint/PostFilterEndpointTest.php index 36adfc3e..51040e91 100644 --- a/tests/Unit/SearchEndpoint/PostFilterEndpointTest.php +++ b/tests/Unit/SearchEndpoint/PostFilterEndpointTest.php @@ -48,7 +48,7 @@ public function testNormalization() $normalizerInterface = $this->getMockForAbstractClass( 'Symfony\Component\Serializer\Normalizer\NormalizerInterface' ); - $this->assertNull($instance->normalize($normalizerInterface)); + $this->assertFalse($instance->normalize($normalizerInterface)); $matchAll = new MatchAllQuery(); $instance->add($matchAll); diff --git a/tests/Unit/SearchEndpoint/QueryEndpointTest.php b/tests/Unit/SearchEndpoint/QueryEndpointTest.php index 5d28e152..68aff7e4 100644 --- a/tests/Unit/SearchEndpoint/QueryEndpointTest.php +++ b/tests/Unit/SearchEndpoint/QueryEndpointTest.php @@ -49,7 +49,7 @@ public function testEndpoint() 'Symfony\Component\Serializer\Normalizer\NormalizerInterface' ); - $this->assertNull($instance->normalize($normalizerInterface)); + $this->assertFalse($instance->normalize($normalizerInterface)); $matchAll = new MatchAllQuery(); $instance->add($matchAll); diff --git a/tests/Unit/SearchEndpoint/SearchEndpointFactoryTest.php b/tests/Unit/SearchEndpoint/SearchEndpointFactoryTest.php index 3c0da38d..63716a22 100644 --- a/tests/Unit/SearchEndpoint/SearchEndpointFactoryTest.php +++ b/tests/Unit/SearchEndpoint/SearchEndpointFactoryTest.php @@ -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'); }