From d1a8e086d48f494e1c9a3e04a5f9710101b46e15 Mon Sep 17 00:00:00 2001 From: Reedy Date: Thu, 23 Sep 2021 04:45:07 +0100 Subject: [PATCH] PHP8 support * Swap Match and MatchQuery around in heirarchy * Start testing on PHP 8 * Add yoast/phpunit-polyfills for PHPUnit support * PHPUnit version for PHP 8 support (8.5.12 is lowest version with PHP >= 7.2 support; previous are ^7.2). ** Inspiration and help from https://github.com/ruflin/Elastica/commit/e701617059208fbd83276040677317f9ddc5dd40 --- .github/workflows/continuous-integration.yaml | 2 + .gitignore | 1 + composer.json | 5 +- lib/Elastica/Query/Match.php | 208 +----------------- lib/Elastica/Query/MatchQuery.php | 207 ++++++++++++++++- lib/Elastica/QueryBuilder/DSL/Query.php | 6 +- .../AbstractSimpleAggregationTest.php | 2 +- test/Elastica/Aggregation/CardinalityTest.php | 7 +- test/Elastica/Aggregation/DateRangeTest.php | 4 +- test/Elastica/Base.php | 10 +- test/Elastica/BasePipeline.php | 4 +- test/Elastica/Bulk/ResponseSetTest.php | 15 +- test/Elastica/BulkTest.php | 9 +- test/Elastica/ClientTest.php | 13 +- test/Elastica/Cluster/Health/IndexTest.php | 9 +- test/Elastica/Cluster/Health/ShardTest.php | 4 +- test/Elastica/Cluster/HealthTest.php | 9 +- test/Elastica/Cluster/SettingsTest.php | 4 +- test/Elastica/ClusterTest.php | 5 +- test/Elastica/DeprecatedClassBase.php | 8 +- test/Elastica/DocumentTest.php | 7 +- .../Connection/GuzzleExceptionTest.php | 4 +- test/Elastica/Index/SettingsTest.php | 17 +- test/Elastica/IndexTest.php | 5 +- test/Elastica/LogTest.php | 4 +- test/Elastica/Multi/MultiBuilderTest.php | 4 +- test/Elastica/Multi/SearchTest.php | 31 +-- test/Elastica/Node/InfoTest.php | 5 +- test/Elastica/PipelineTest.php | 8 +- test/Elastica/Processor/ConvertTest.php | 5 +- test/Elastica/Processor/FailTest.php | 2 +- test/Elastica/Processor/KvTest.php | 6 +- test/Elastica/Query/IdsTest.php | 4 +- test/Elastica/Query/MatchTest.php | 24 +- test/Elastica/Query/PostFilterTest.php | 4 +- test/Elastica/Query/PrefixTest.php | 7 +- test/Elastica/Query/QueryStringTest.php | 6 +- test/Elastica/Query/RescoreTest.php | 12 +- test/Elastica/Query/ScriptTest.php | 5 +- test/Elastica/Query/TermTest.php | 11 +- .../QueryBuilder/DSL/AbstractDSLTest.php | 8 +- test/Elastica/QueryBuilder/DSL/QueryTest.php | 10 +- test/Elastica/ReindexTest.php | 4 +- test/Elastica/RequestTest.php | 11 +- test/Elastica/ResponseTest.php | 11 +- test/Elastica/ResultSet/BuilderTest.php | 4 +- .../ResultSet/ProcessingBuilderTest.php | 4 +- test/Elastica/ResultSetTest.php | 7 +- test/Elastica/ResultTest.php | 7 +- test/Elastica/SnapshotTest.php | 4 +- test/Elastica/StatusTest.php | 7 +- test/Elastica/TaskTest.php | 5 +- test/Elastica/Transport/AwsAuthV4Test.php | 4 +- test/Elastica/Transport/GuzzleTest.php | 11 +- test/Elastica/Transport/HttpTest.php | 4 +- test/Elastica/Transport/NullTransportTest.php | 22 +- .../Transport/TransportBenchmarkTest.php | 8 +- test/Elastica/Type/MappingTest.php | 25 +-- test/Elastica/TypeTest.php | 10 +- 59 files changed, 471 insertions(+), 398 deletions(-) diff --git a/.github/workflows/continuous-integration.yaml b/.github/workflows/continuous-integration.yaml index a1269d4d1d..577b726307 100644 --- a/.github/workflows/continuous-integration.yaml +++ b/.github/workflows/continuous-integration.yaml @@ -37,6 +37,8 @@ jobs: elasticsearch: '6.5.2' - php: '7.4' elasticsearch: '6.5.2' + - php: '8.0' + elasticsearch: '6.5.2' fail-fast: false steps: - name: 'Checkout' diff --git a/.gitignore b/.gitignore index b78ee3d81e..f6e239ee21 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ .vagrant .php_cs .php_cs.cache +.phpunit.result.cache cache.properties /nbproject diff --git a/composer.json b/composer.json index d611d3e59a..9bb714814c 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ } ], "require": { - "php": "^7.0", + "php": "^7.0||^8.0", "ext-json": "*", "psr/log": "~1.0", "elasticsearch/elasticsearch": "^6.0" @@ -20,7 +20,8 @@ "require-dev": { "aws/aws-sdk-php": "~3.0", "guzzlehttp/guzzle": "~6.0", - "phpunit/phpunit": "^6.0" + "phpunit/phpunit": "^6.0||^8.5.20", + "yoast/phpunit-polyfills": "1.0.1" }, "conflict": { "elasticsearch/elasticsearch": "6.8.0 || 6.8.1" diff --git a/lib/Elastica/Query/Match.php b/lib/Elastica/Query/Match.php index 085471be93..107e1b6ce1 100644 --- a/lib/Elastica/Query/Match.php +++ b/lib/Elastica/Query/Match.php @@ -5,212 +5,8 @@ /** * Match query. * - * @author F21 - * @author WONG Wing Lun - * - * @deprecated since version 6.1.2, use the MatchQuery class instead. - * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html + * @deprecated since 6.1.2, use the MatchQuery class instead. */ -class Match extends AbstractQuery +class Match extends MatchQuery { - const OPERATOR_OR = 'or'; - const OPERATOR_AND = 'and'; - - const ZERO_TERM_NONE = 'none'; - const ZERO_TERM_ALL = 'all'; - - const FUZZINESS_AUTO = 'AUTO'; - - /** - * @param string $field - * @param mixed $values - */ - public function __construct($field = null, $values = null) - { - if (null !== $field && null !== $values) { - $this->setParam($field, $values); - } - } - - /** - * Sets a param for the message array. - * - * @param string $field - * @param mixed $values - * - * @return $this - */ - public function setField($field, $values) - { - return $this->setParam($field, $values); - } - - /** - * Sets a param for the given field. - * - * @param string $field - * @param string $key - * @param string $value - * - * @return $this - */ - public function setFieldParam($field, $key, $value) - { - if (!isset($this->_params[$field])) { - $this->_params[$field] = []; - } - - $this->_params[$field][$key] = $value; - - return $this; - } - - /** - * Sets the query string. - * - * @param string $field - * @param string $query - * - * @return $this - */ - public function setFieldQuery($field, $query) - { - return $this->setFieldParam($field, 'query', $query); - } - - /** - * Set field operator. - * - * @param string $field - * @param string $operator - * - * @return $this - */ - public function setFieldOperator($field, $operator = self::OPERATOR_OR) - { - return $this->setFieldParam($field, 'operator', $operator); - } - - /** - * Set field analyzer. - * - * @param string $field - * @param string $analyzer - * - * @return $this - */ - public function setFieldAnalyzer($field, $analyzer) - { - return $this->setFieldParam($field, 'analyzer', $analyzer); - } - - /** - * Set field boost value. - * - * If not set, defaults to 1.0. - * - * @param string $field - * @param float $boost - * - * @return $this - */ - public function setFieldBoost($field, $boost = 1.0) - { - return $this->setFieldParam($field, 'boost', (float) $boost); - } - - /** - * Set field minimum should match. - * - * @param string $field - * @param int|string $minimumShouldMatch - * - * @return $this - * - * @see Possible values for minimum_should_match https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html - */ - public function setFieldMinimumShouldMatch($field, $minimumShouldMatch) - { - return $this->setFieldParam($field, 'minimum_should_match', $minimumShouldMatch); - } - - /** - * Set field fuzziness. - * - * @param string $field - * @param mixed $fuzziness - * - * @return $this - */ - public function setFieldFuzziness($field, $fuzziness) - { - return $this->setFieldParam($field, 'fuzziness', $fuzziness); - } - - /** - * Set field fuzzy rewrite. - * - * @param string $field - * @param string $fuzzyRewrite - * - * @return $this - */ - public function setFieldFuzzyRewrite($field, $fuzzyRewrite) - { - return $this->setFieldParam($field, 'fuzzy_rewrite', $fuzzyRewrite); - } - - /** - * Set field prefix length. - * - * @param string $field - * @param int $prefixLength - * - * @return $this - */ - public function setFieldPrefixLength($field, $prefixLength) - { - return $this->setFieldParam($field, 'prefix_length', (int) $prefixLength); - } - - /** - * Set field max expansions. - * - * @param string $field - * @param int $maxExpansions - * - * @return $this - */ - public function setFieldMaxExpansions($field, $maxExpansions) - { - return $this->setFieldParam($field, 'max_expansions', (int) $maxExpansions); - } - - /** - * Set zero terms query. - * - * If not set, default to 'none' - * - * @param string $field - * @param string $zeroTermQuery - * - * @return $this - */ - public function setFieldZeroTermsQuery($field, $zeroTermQuery = self::ZERO_TERM_NONE) - { - return $this->setFieldParam($field, 'zero_terms_query', $zeroTermQuery); - } - - /** - * Set cutoff frequency. - * - * @param string $field - * @param float $cutoffFrequency - * - * @return $this - */ - public function setFieldCutoffFrequency($field, $cutoffFrequency) - { - return $this->setFieldParam($field, 'cutoff_frequency', $cutoffFrequency); - } } diff --git a/lib/Elastica/Query/MatchQuery.php b/lib/Elastica/Query/MatchQuery.php index 888ed4fb99..4d1018c6a2 100644 --- a/lib/Elastica/Query/MatchQuery.php +++ b/lib/Elastica/Query/MatchQuery.php @@ -5,8 +5,211 @@ /** * Match query. * - * This class is for forward compatibility reasons. For PHP 8 and above use MatchQuery as Match is reserved. + * @author F21 + * @author WONG Wing Lun + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html */ -class MatchQuery extends Match +class MatchQuery extends AbstractQuery { + const OPERATOR_OR = 'or'; + const OPERATOR_AND = 'and'; + + const ZERO_TERM_NONE = 'none'; + const ZERO_TERM_ALL = 'all'; + + const FUZZINESS_AUTO = 'AUTO'; + + /** + * @param string $field + * @param mixed $values + */ + public function __construct($field = null, $values = null) + { + if (null !== $field && null !== $values) { + $this->setParam($field, $values); + } + } + + /** + * Sets a param for the message array. + * + * @param string $field + * @param mixed $values + * + * @return $this + */ + public function setField($field, $values) + { + return $this->setParam($field, $values); + } + + /** + * Sets a param for the given field. + * + * @param string $field + * @param string $key + * @param string $value + * + * @return $this + */ + public function setFieldParam($field, $key, $value) + { + if (!isset($this->_params[$field])) { + $this->_params[$field] = []; + } + + $this->_params[$field][$key] = $value; + + return $this; + } + + /** + * Sets the query string. + * + * @param string $field + * @param string $query + * + * @return $this + */ + public function setFieldQuery($field, $query) + { + return $this->setFieldParam($field, 'query', $query); + } + + /** + * Set field operator. + * + * @param string $field + * @param string $operator + * + * @return $this + */ + public function setFieldOperator($field, $operator = self::OPERATOR_OR) + { + return $this->setFieldParam($field, 'operator', $operator); + } + + /** + * Set field analyzer. + * + * @param string $field + * @param string $analyzer + * + * @return $this + */ + public function setFieldAnalyzer($field, $analyzer) + { + return $this->setFieldParam($field, 'analyzer', $analyzer); + } + + /** + * Set field boost value. + * + * If not set, defaults to 1.0. + * + * @param string $field + * @param float $boost + * + * @return $this + */ + public function setFieldBoost($field, $boost = 1.0) + { + return $this->setFieldParam($field, 'boost', (float) $boost); + } + + /** + * Set field minimum should match. + * + * @param string $field + * @param int|string $minimumShouldMatch + * + * @return $this + * + * @see Possible values for minimum_should_match https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-minimum-should-match.html + */ + public function setFieldMinimumShouldMatch($field, $minimumShouldMatch) + { + return $this->setFieldParam($field, 'minimum_should_match', $minimumShouldMatch); + } + + /** + * Set field fuzziness. + * + * @param string $field + * @param mixed $fuzziness + * + * @return $this + */ + public function setFieldFuzziness($field, $fuzziness) + { + return $this->setFieldParam($field, 'fuzziness', $fuzziness); + } + + /** + * Set field fuzzy rewrite. + * + * @param string $field + * @param string $fuzzyRewrite + * + * @return $this + */ + public function setFieldFuzzyRewrite($field, $fuzzyRewrite) + { + return $this->setFieldParam($field, 'fuzzy_rewrite', $fuzzyRewrite); + } + + /** + * Set field prefix length. + * + * @param string $field + * @param int $prefixLength + * + * @return $this + */ + public function setFieldPrefixLength($field, $prefixLength) + { + return $this->setFieldParam($field, 'prefix_length', (int) $prefixLength); + } + + /** + * Set field max expansions. + * + * @param string $field + * @param int $maxExpansions + * + * @return $this + */ + public function setFieldMaxExpansions($field, $maxExpansions) + { + return $this->setFieldParam($field, 'max_expansions', (int) $maxExpansions); + } + + /** + * Set zero terms query. + * + * If not set, default to 'none' + * + * @param string $field + * @param string $zeroTermQuery + * + * @return $this + */ + public function setFieldZeroTermsQuery($field, $zeroTermQuery = self::ZERO_TERM_NONE) + { + return $this->setFieldParam($field, 'zero_terms_query', $zeroTermQuery); + } + + /** + * Set cutoff frequency. + * + * @param string $field + * @param float $cutoffFrequency + * + * @return $this + */ + public function setFieldCutoffFrequency($field, $cutoffFrequency) + { + return $this->setFieldParam($field, 'cutoff_frequency', $cutoffFrequency); + } } diff --git a/lib/Elastica/QueryBuilder/DSL/Query.php b/lib/Elastica/QueryBuilder/DSL/Query.php index 3c04673f7c..5cd4ba966e 100644 --- a/lib/Elastica/QueryBuilder/DSL/Query.php +++ b/lib/Elastica/QueryBuilder/DSL/Query.php @@ -16,9 +16,9 @@ use Elastica\Query\HasChild; use Elastica\Query\HasParent; use Elastica\Query\Ids; -use Elastica\Query\Match; use Elastica\Query\MatchAll; use Elastica\Query\MatchNone; +use Elastica\Query\MatchQuery; use Elastica\Query\MoreLikeThis; use Elastica\Query\MultiMatch; use Elastica\Query\Nested; @@ -70,11 +70,11 @@ public function getType() * @param string $field * @param mixed $values * - * @return Match + * @return MatchQuery */ public function match($field = null, $values = null) { - return new Match($field, $values); + return new MatchQuery($field, $values); } /** diff --git a/test/Elastica/Aggregation/AbstractSimpleAggregationTest.php b/test/Elastica/Aggregation/AbstractSimpleAggregationTest.php index 329a1dcd93..f7813316a6 100644 --- a/test/Elastica/Aggregation/AbstractSimpleAggregationTest.php +++ b/test/Elastica/Aggregation/AbstractSimpleAggregationTest.php @@ -7,7 +7,7 @@ class AbstractSimpleAggregationTest extends BaseAggregationTest { - protected function setUp() + protected function set_up() { $this->aggregation = $this->getMockForAbstractClass( AbstractSimpleAggregation::class, diff --git a/test/Elastica/Aggregation/CardinalityTest.php b/test/Elastica/Aggregation/CardinalityTest.php index 17d47a99db..3d4f8fbf6e 100644 --- a/test/Elastica/Aggregation/CardinalityTest.php +++ b/test/Elastica/Aggregation/CardinalityTest.php @@ -6,9 +6,12 @@ use Elastica\Document; use Elastica\Query; use Elastica\Type\Mapping; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; class CardinalityTest extends BaseAggregationTest { + use AssertIsType; + protected function _getIndexForTest() { $index = $this->_createIndex(); @@ -73,7 +76,7 @@ public function testPrecisionThreshold($threshold) $agg->setPrecisionThreshold($threshold); $this->assertNotNull($agg->getParam('precision_threshold')); - $this->assertInternalType('int', $agg->getParam('precision_threshold')); + self::assertIsInt($agg->getParam('precision_threshold')); } public function invalidPrecisionThresholdProvider() @@ -109,7 +112,7 @@ public function testRehash($rehash) $agg->setRehash($rehash); $this->assertNotNull($agg->getParam('rehash')); - $this->assertInternalType('boolean', $agg->getParam('rehash')); + self::assertIsBool($agg->getParam('rehash')); } /** diff --git a/test/Elastica/Aggregation/DateRangeTest.php b/test/Elastica/Aggregation/DateRangeTest.php index 0e715811f1..6a32f14a05 100644 --- a/test/Elastica/Aggregation/DateRangeTest.php +++ b/test/Elastica/Aggregation/DateRangeTest.php @@ -88,8 +88,8 @@ public function testDateRangeSetFormatAccordingToFormatTargetField() } catch (ResponseException $e) { $error = $e->getResponse()->getFullError(); - $this->assertContains('search_phase_execution_exception', $error['type']); - $this->assertContains('failed to parse date field', $error['root_cause'][0]['reason']); + $this->assertSame('search_phase_execution_exception', $error['type']); + $this->assertStringStartsWith('failed to parse date field', $error['root_cause'][0]['reason']); } } } diff --git a/test/Elastica/Base.php b/test/Elastica/Base.php index d5f030a811..2f34ddd787 100644 --- a/test/Elastica/Base.php +++ b/test/Elastica/Base.php @@ -6,9 +6,9 @@ use Elastica\Connection; use Elastica\Index; use Elasticsearch\Endpoints\Ingest\Pipeline\Put; -use PHPUnit\Framework\TestCase; use PHPUnit\Util\Test as TestUtil; use Psr\Log\LoggerInterface; +use Yoast\PHPUnitPolyfills\TestCases\TestCase; class Base extends TestCase { @@ -202,23 +202,23 @@ protected function _waitForAllocation(Index $index) } while (!$allocated); } - protected function setUp() + protected function set_up() { - parent::setUp(); + parent::set_up(); $hasGroup = $this->_isUnitGroup() || $this->_isFunctionalGroup() || $this->_isBenchmarkGroup(); $this->assertTrue($hasGroup, 'Every test must have one of "unit", "functional", "benchmark" group'); $this->showDeprecated(); } - protected function tearDown() + protected function tear_down() { if ($this->_isFunctionalGroup()) { $this->_getClient()->getIndex('_all')->delete(); $this->_getClient()->getIndex('_all')->clearCache(); } - parent::tearDown(); + parent::tear_down(); } protected function _isUnitGroup() diff --git a/test/Elastica/BasePipeline.php b/test/Elastica/BasePipeline.php index b3ffaae173..ba060a8a2a 100644 --- a/test/Elastica/BasePipeline.php +++ b/test/Elastica/BasePipeline.php @@ -31,12 +31,12 @@ protected function _createPipeline(string $id = null, string $description = '') /** * {@inheritdoc} */ - protected function tearDown() + protected function tear_down() { if ($this->_isFunctionalGroup()) { $this->_createPipeline()->deletePipeline('*'); } - parent::tearDown(); + parent::tear_down(); } } diff --git a/test/Elastica/Bulk/ResponseSetTest.php b/test/Elastica/Bulk/ResponseSetTest.php index feec7b42cf..a5e19a726f 100644 --- a/test/Elastica/Bulk/ResponseSetTest.php +++ b/test/Elastica/Bulk/ResponseSetTest.php @@ -10,9 +10,14 @@ use Elastica\Exception\Bulk\ResponseException; use Elastica\Response; use Elastica\Test\Base as BaseTest; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; +use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains; class ResponseSetTest extends BaseTest { + use AssertIsType; + use AssertStringContains; + /** * @group unit */ @@ -68,12 +73,12 @@ public function testGetError() $this->assertInstanceOf(ActionException::class, $actionExceptions[0]); $this->assertSame($actions[1], $actionExceptions[0]->getAction()); - $this->assertContains('SomeExceptionMessage', $actionExceptions[0]->getMessage()); + self::assertStringContainsStringIgnoringCase('SomeExceptionMessage', $actionExceptions[0]->getMessage()); $this->assertTrue($actionExceptions[0]->getResponse()->hasError()); $this->assertInstanceOf(ActionException::class, $actionExceptions[1]); $this->assertSame($actions[2], $actionExceptions[1]->getAction()); - $this->assertContains('AnotherExceptionMessage', $actionExceptions[1]->getMessage()); + self::assertStringContainsStringIgnoringCase('AnotherExceptionMessage', $actionExceptions[1]->getMessage()); $this->assertTrue($actionExceptions[1]->getResponse()->hasError()); } } @@ -88,13 +93,13 @@ public function testGetBulkResponses() $responseSet = $this->_createResponseSet($responseData, $actions); $bulkResponses = $responseSet->getBulkResponses(); - $this->assertInternalType('array', $bulkResponses); + self::assertIsArray($bulkResponses); $this->assertCount(3, $bulkResponses); foreach ($bulkResponses as $i => $bulkResponse) { $this->assertInstanceOf(Bulk\Response::class, $bulkResponse); $bulkResponseData = $bulkResponse->getData(); - $this->assertInternalType('array', $bulkResponseData); + self::assertIsArray($bulkResponseData); $this->assertArrayHasKey('_id', $bulkResponseData); $this->assertEquals($responseData['items'][$i]['index']['_id'], $bulkResponseData['_id']); $this->assertSame($actions[$i], $bulkResponse->getAction()); @@ -116,7 +121,7 @@ public function testIterator() foreach ($responseSet as $i => $bulkResponse) { $this->assertInstanceOf(Bulk\Response::class, $bulkResponse); $bulkResponseData = $bulkResponse->getData(); - $this->assertInternalType('array', $bulkResponseData); + self::assertIsArray($bulkResponseData); $this->assertArrayHasKey('_id', $bulkResponseData); $this->assertEquals($responseData['items'][$i]['index']['_id'], $bulkResponseData['_id']); $this->assertSame($actions[$i], $bulkResponse->getAction()); diff --git a/test/Elastica/BulkTest.php b/test/Elastica/BulkTest.php index 1477befebe..bb4dcd38c0 100644 --- a/test/Elastica/BulkTest.php +++ b/test/Elastica/BulkTest.php @@ -15,9 +15,12 @@ use Elastica\Exception\NotFoundException; use Elastica\Script\Script; use Elastica\Test\Base as BaseTest; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; class BulkTest extends BaseTest { + use AssertIsType; + /** * @group functional */ @@ -257,7 +260,7 @@ public function testAddRawData() $actions = $bulk->getActions(); - $this->assertInternalType('array', $actions); + self::assertIsArray($actions); $this->assertCount(5, $actions); $this->assertInstanceOf(Action::class, $actions[0]); @@ -368,9 +371,9 @@ public function testErrorRequest() $bulk->fail('3rd document create should produce error'); } catch (ResponseException $e) { $error = $e->getResponseSet()->getFullError(); - $this->assertContains('version_conflict_engine_exception', $error['type']); + $this->assertSame('version_conflict_engine_exception', $error['type']); $failures = $e->getFailures(); - $this->assertInternalType('array', $failures); + self::assertIsArray($failures); $this->assertArrayHasKey(0, $failures); } } diff --git a/test/Elastica/ClientTest.php b/test/Elastica/ClientTest.php index 4d81911b6d..9368bfd081 100644 --- a/test/Elastica/ClientTest.php +++ b/test/Elastica/ClientTest.php @@ -20,9 +20,12 @@ use Elasticsearch\Endpoints\Get; use Elasticsearch\Endpoints\Indices\Stats; use Elasticsearch\Endpoints\Search; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; class ClientTest extends BaseTest { + use AssertIsType; + /** * @group unit */ @@ -377,8 +380,8 @@ public function testDeleteIdsIdxStringTypeString() // deleteIds are the type we are testing for $idxString = $index->getName(); $typeString = $type->getName(); - $this->assertInternalType('string', $idxString); - $this->assertInternalType('string', $typeString); + self::assertIsString($idxString); + self::assertIsString($typeString); // Try to delete doc with a routing value which hashes to // a different shard then the id. @@ -453,7 +456,7 @@ public function testDeleteIdsIdxStringTypeObject() // And verify that the variables we are doing to send to // deleteIds are the type we are testing for $idxString = $index->getName(); - $this->assertInternalType('string', $idxString); + self::assertIsString($idxString); $this->assertInstanceOf(Type::class, $type); // Using the existing $index and $type variables which @@ -518,7 +521,7 @@ public function testDeleteIdsIdxObjectTypeString() // deleteIds are the type we are testing for $typeString = $type->getName(); $this->assertInstanceOf(Index::class, $index); - $this->assertInternalType('string', $typeString); + self::assertIsString($typeString); // Using the existing $index and $type variables which // are \Elastica\Index and \Elastica\Type objects respectively @@ -1167,7 +1170,7 @@ public function testConfigValue() $this->assertNotEquals(10, $client->getConfigValue('level11', 10)); $this->assertEquals('value3', $client->getConfigValue(['level1', 'level2', 'level3'])); - $this->assertInternalType('array', $client->getConfigValue(['level1', 'level2'])); + self::assertIsArray($client->getConfigValue(['level1', 'level2'])); } /** diff --git a/test/Elastica/Cluster/Health/IndexTest.php b/test/Elastica/Cluster/Health/IndexTest.php index 779d45ebeb..64ae97f23f 100644 --- a/test/Elastica/Cluster/Health/IndexTest.php +++ b/test/Elastica/Cluster/Health/IndexTest.php @@ -5,17 +5,20 @@ use Elastica\Cluster\Health\Index; use Elastica\Cluster\Health\Shard; use Elastica\Test\Base as BaseTest; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; class IndexTest extends BaseTest { + use AssertIsType; + /** * @var Index */ protected $_index; - protected function setUp() + protected function set_up() { - parent::setUp(); + parent::set_up(); $data = [ 'status' => 'yellow', @@ -136,7 +139,7 @@ public function testGetShards() { $shards = $this->_index->getShards(); - $this->assertInternalType('array', $shards); + self::assertIsArray($shards); $this->assertCount(3, $shards); $this->assertContainsOnlyInstancesOf(Shard::class, $shards); } diff --git a/test/Elastica/Cluster/Health/ShardTest.php b/test/Elastica/Cluster/Health/ShardTest.php index 9f1b5cc877..b1970aba53 100644 --- a/test/Elastica/Cluster/Health/ShardTest.php +++ b/test/Elastica/Cluster/Health/ShardTest.php @@ -12,9 +12,9 @@ class ShardTest extends BaseTest */ protected $_shard; - protected function setUp() + protected function set_up() { - parent::setUp(); + parent::set_up(); $shardData = [ 'status' => 'red', diff --git a/test/Elastica/Cluster/HealthTest.php b/test/Elastica/Cluster/HealthTest.php index d87819ab47..f1a3bbc4d3 100644 --- a/test/Elastica/Cluster/HealthTest.php +++ b/test/Elastica/Cluster/HealthTest.php @@ -5,17 +5,20 @@ use Elastica\Cluster\Health; use Elastica\Cluster\Health\Index; use Elastica\Test\Base as BaseTest; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; class HealthTest extends BaseTest { + use AssertIsType; + /** * @var Health */ protected $_health; - protected function setUp() + protected function set_up() { - parent::setUp(); + parent::set_up(); $data = [ 'cluster_name' => 'test_cluster', @@ -186,7 +189,7 @@ public function testGetIndices() { $indices = $this->_health->getIndices(); - $this->assertInternalType('array', $indices); + self::assertIsArray($indices); $this->assertCount(2, $indices); $this->assertArrayHasKey('index_one', $indices); $this->assertArrayHasKey('index_two', $indices); diff --git a/test/Elastica/Cluster/SettingsTest.php b/test/Elastica/Cluster/SettingsTest.php index 2e1b7ab115..d53cd84425 100644 --- a/test/Elastica/Cluster/SettingsTest.php +++ b/test/Elastica/Cluster/SettingsTest.php @@ -84,8 +84,8 @@ public function testSetReadOnly() $this->fail('should throw read only exception'); } catch (ResponseException $e) { $error = $e->getResponse()->getFullError(); - $this->assertContains('cluster_block_exception', $error['type']); - $this->assertContains('cluster read-only', $error['reason']); + $this->assertSame('cluster_block_exception', $error['type']); + $this->assertStringContainsString('cluster read-only', $error['reason']); } $response = $settings->setReadOnly(false); diff --git a/test/Elastica/ClusterTest.php b/test/Elastica/ClusterTest.php index 13d60be216..c110d396c4 100644 --- a/test/Elastica/ClusterTest.php +++ b/test/Elastica/ClusterTest.php @@ -6,9 +6,12 @@ use Elastica\Cluster\Health; use Elastica\Node; use Elastica\Test\Base as BaseTest; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; class ClusterTest extends BaseTest { + use AssertIsType; + /** * @group functional */ @@ -54,7 +57,7 @@ public function testGetState() $client = $this->_getClient(); $cluster = $client->getCluster(); $state = $cluster->getState(); - $this->assertInternalType('array', $state); + self::assertIsArray($state); } /** diff --git a/test/Elastica/DeprecatedClassBase.php b/test/Elastica/DeprecatedClassBase.php index 45f9ddb432..c6f25012af 100644 --- a/test/Elastica/DeprecatedClassBase.php +++ b/test/Elastica/DeprecatedClassBase.php @@ -9,15 +9,15 @@ */ class DeprecatedClassBase extends Base { - protected function setUp() + protected function set_up() { - parent::setUp(); + parent::set_up(); $this->hideDeprecated(); } - protected function tearDown() + protected function tear_down() { $this->showDeprecated(); - parent::tearDown(); + parent::tear_down(); } } diff --git a/test/Elastica/DocumentTest.php b/test/Elastica/DocumentTest.php index 8e7cf79b88..b247722690 100644 --- a/test/Elastica/DocumentTest.php +++ b/test/Elastica/DocumentTest.php @@ -6,9 +6,12 @@ use Elastica\Exception\InvalidException; use Elastica\Index; use Elastica\Test\Base as BaseTest; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; class DocumentTest extends BaseTest { + use AssertIsType; + /** * @group unit */ @@ -153,7 +156,7 @@ public function testGetOptions() $options = $document->getOptions(['index', 'type', 'id', 'parent']); - $this->assertInternalType('array', $options); + self::assertIsArray($options); $this->assertCount(3, $options); $this->assertArrayHasKey('index', $options); $this->assertArrayHasKey('id', $options); @@ -169,7 +172,7 @@ public function testGetOptions() $options = $document->getOptions(['parent', 'op_type', 'percolate'], true); - $this->assertInternalType('array', $options); + self::assertIsArray($options); $this->assertCount(2, $options); $this->assertArrayHasKey('_parent', $options); $this->assertArrayHasKey('_op_type', $options); diff --git a/test/Elastica/Exception/Connection/GuzzleExceptionTest.php b/test/Elastica/Exception/Connection/GuzzleExceptionTest.php index 643f1d5cc8..c223c12f2a 100644 --- a/test/Elastica/Exception/Connection/GuzzleExceptionTest.php +++ b/test/Elastica/Exception/Connection/GuzzleExceptionTest.php @@ -6,8 +6,10 @@ class GuzzleExceptionTest extends AbstractExceptionTest { - public static function setUpBeforeClass() + public static function set_up_before_class() { + parent::set_up_before_class(); + if (!class_exists('GuzzleHttp\\Client')) { self::markTestSkipped('guzzlehttp/guzzle package should be installed to run guzzle transport tests'); } diff --git a/test/Elastica/Index/SettingsTest.php b/test/Elastica/Index/SettingsTest.php index 58b7ba2b6e..1623ae4595 100644 --- a/test/Elastica/Index/SettingsTest.php +++ b/test/Elastica/Index/SettingsTest.php @@ -8,9 +8,12 @@ use Elastica\Index\Settings as IndexSettings; use Elastica\Response; use Elastica\Test\Base as BaseTest; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; class SettingsTest extends BaseTest { + use AssertIsType; + /** * @group functional */ @@ -24,7 +27,7 @@ public function testGet() $index->refresh(); $settings = $index->getSettings(); - $this->assertInternalType('array', $settings->get()); + self::assertIsArray($settings->get()); $this->assertNotNull($settings->get('number_of_replicas')); $this->assertNotNull($settings->get('number_of_shards')); $this->assertNull($settings->get('kjqwerjlqwer')); @@ -49,7 +52,7 @@ public function testGetWithAlias() $index = $client->getIndex($aliasName); $settings = $index->getSettings(); - $this->assertInternalType('array', $settings->get()); + self::assertIsArray($settings->get()); $this->assertNotNull($settings->get('number_of_replicas')); $this->assertNotNull($settings->get('number_of_shards')); $this->assertNull($settings->get('kjqwerjlqwer')); @@ -80,8 +83,8 @@ public function testDeleteAliasWithException() } catch (ResponseException $e) { $error = $e->getResponse()->getFullError(); - $this->assertContains('illegal_argument_exception', $error['type']); - $this->assertContains('specify the corresponding concrete indices instead.', $error['reason']); + $this->assertSame('illegal_argument_exception', $error['type']); + $this->assertStringContainsString('specify the corresponding concrete indices instead.', $error['reason']); } } @@ -278,8 +281,8 @@ public function testSetReadOnly() } catch (ResponseException $e) { $error = $e->getResponse()->getFullError(); - $this->assertContains('cluster_block_exception', $error['type']); - $this->assertContains('read-only', $error['reason']); + $this->assertSame('cluster_block_exception', $error['type']); + $this->assertStringContainsString('read-only', $error['reason']); } // Remove read only, add document @@ -379,7 +382,7 @@ public function testNotFoundIndex() $this->fail('Should throw exception because of index not found'); } catch (ResponseException $e) { $error = $e->getResponse()->getFullError(); - $this->assertContains('index_not_found_exception', $error['type']); + $this->assertSame('index_not_found_exception', $error['type']); } } diff --git a/test/Elastica/IndexTest.php b/test/Elastica/IndexTest.php index ce860f1abb..93690429ea 100644 --- a/test/Elastica/IndexTest.php +++ b/test/Elastica/IndexTest.php @@ -15,9 +15,12 @@ use Elastica\Type; use Elastica\Type\Mapping; use Elasticsearch\Endpoints\Indices\Analyze; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; class IndexTest extends BaseTest { + use AssertIsType; + /** * @group functional */ @@ -805,7 +808,7 @@ public function testConvertScalarsToString() $index = $client->getIndex(1); $this->assertEquals('1', $index->getName()); - $this->assertInternalType('string', $index->getName()); + self::assertIsString($index->getName()); } /** diff --git a/test/Elastica/LogTest.php b/test/Elastica/LogTest.php index 46434d3f64..aa9a6bab63 100644 --- a/test/Elastica/LogTest.php +++ b/test/Elastica/LogTest.php @@ -11,8 +11,10 @@ class LogTest extends BaseTest private $_context = []; private $_message = 'hello world'; - public static function setUpBeforeClass() + public static function set_up_before_class() { + parent::set_up_before_class(); + if (!class_exists('Psr\Log\AbstractLogger')) { self::markTestSkipped('The Psr extension is not available.'); } diff --git a/test/Elastica/Multi/MultiBuilderTest.php b/test/Elastica/Multi/MultiBuilderTest.php index 24205ae6c5..9737f6cac9 100644 --- a/test/Elastica/Multi/MultiBuilderTest.php +++ b/test/Elastica/Multi/MultiBuilderTest.php @@ -25,9 +25,9 @@ class MultiBuilderTest extends BaseTest */ private $multiBuilder; - protected function setUp() + protected function set_up() { - parent::setUp(); + parent::set_up(); $this->builder = $this->createMock(BuilderInterface::class); $this->multiBuilder = new MultiBuilder($this->builder); diff --git a/test/Elastica/Multi/SearchTest.php b/test/Elastica/Multi/SearchTest.php index 1f45c810a1..60dc00d01b 100644 --- a/test/Elastica/Multi/SearchTest.php +++ b/test/Elastica/Multi/SearchTest.php @@ -11,9 +11,12 @@ use Elastica\ResultSet; use Elastica\Search; use Elastica\Test\Base as BaseTest; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; class SearchTest extends BaseTest { + use AssertIsType; + /** * @return \Elastica\Type */ @@ -70,7 +73,7 @@ public function testSetSearches() $searches = $multiSearch->getSearches(); - $this->assertInternalType('array', $searches); + self::assertIsArray($searches); $this->assertCount(3, $searches); $this->assertArrayHasKey(0, $searches); $this->assertSame($search1, $searches[0]); @@ -82,7 +85,7 @@ public function testSetSearches() $multiSearch->clearSearches(); $searches = $multiSearch->getSearches(); - $this->assertInternalType('array', $searches); + self::assertIsArray($searches); $this->assertCount(0, $searches); } @@ -102,7 +105,7 @@ public function testSetSearchesByKeys() $searches = $multiSearch->getSearches(); - $this->assertInternalType('array', $searches); + self::assertIsArray($searches); $this->assertCount(3, $searches); $this->assertArrayHasKey('search1', $searches); $this->assertSame($search1, $searches['search1']); @@ -114,7 +117,7 @@ public function testSetSearchesByKeys() $multiSearch->clearSearches(); $searches = $multiSearch->getSearches(); - $this->assertInternalType('array', $searches); + self::assertIsArray($searches); $this->assertCount(0, $searches); } @@ -168,7 +171,7 @@ public function testSearch() $resultSets = $multiResultSet->getResultSets(); - $this->assertInternalType('array', $resultSets); + self::assertIsArray($resultSets); $this->assertArrayHasKey(0, $resultSets); $this->assertInstanceOf(ResultSet::class, $resultSets[0]); @@ -194,7 +197,7 @@ public function testSearch() $resultSets = $multiResultSet->getResultSets(); - $this->assertInternalType('array', $resultSets); + self::assertIsArray($resultSets); $this->assertArrayHasKey(0, $resultSets); $this->assertInstanceOf(ResultSet::class, $resultSets[0]); @@ -261,7 +264,7 @@ public function testSearchWithKeys() $resultSets = $multiResultSet->getResultSets(); - $this->assertInternalType('array', $resultSets); + self::assertIsArray($resultSets); $this->assertArrayHasKey('search1', $resultSets); $this->assertInstanceOf(ResultSet::class, $resultSets['search1']); @@ -287,7 +290,7 @@ public function testSearchWithKeys() $resultSets = $multiResultSet->getResultSets(); - $this->assertInternalType('array', $resultSets); + self::assertIsArray($resultSets); $this->assertArrayHasKey('search1', $resultSets); $this->assertInstanceOf(ResultSet::class, $resultSets['search1']); @@ -329,7 +332,7 @@ public function testSearchWithError() $this->assertInstanceOf(MultiResultSet::class, $multiResultSet); $resultSets = $multiResultSet->getResultSets(); - $this->assertInternalType('array', $resultSets); + self::assertIsArray($resultSets); $this->assertArrayHasKey(0, $resultSets); $this->assertInstanceOf(ResultSet::class, $resultSets[0]); @@ -375,7 +378,7 @@ public function testSearchWithErrorWithKeys() $this->assertInstanceOf(MultiResultSet::class, $multiResultSet); $resultSets = $multiResultSet->getResultSets(); - $this->assertInternalType('array', $resultSets); + self::assertIsArray($resultSets); $this->assertArrayHasKey('search1', $resultSets); $this->assertInstanceOf(ResultSet::class, $resultSets['search1']); @@ -439,7 +442,7 @@ public function testGlobalSearchTypeSearch() $resultSets = $multiResultSet->getResultSets(); - $this->assertInternalType('array', $resultSets); + self::assertIsArray($resultSets); $this->assertArrayHasKey(0, $resultSets); $this->assertInstanceOf(ResultSet::class, $resultSets[0]); @@ -463,7 +466,7 @@ public function testGlobalSearchTypeSearch() $resultSets = $multiResultSet->getResultSets(); - $this->assertInternalType('array', $resultSets); + self::assertIsArray($resultSets); $this->assertArrayHasKey(0, $resultSets); $this->assertInstanceOf(ResultSet::class, $resultSets[0]); @@ -524,7 +527,7 @@ public function testGlobalSearchTypeSearchWithKeys() $resultSets = $multiResultSet->getResultSets(); - $this->assertInternalType('array', $resultSets); + self::assertIsArray($resultSets); $this->assertArrayHasKey(0, $resultSets); $this->assertInstanceOf(ResultSet::class, $resultSets[0]); @@ -548,7 +551,7 @@ public function testGlobalSearchTypeSearchWithKeys() $resultSets = $multiResultSet->getResultSets(); - $this->assertInternalType('array', $resultSets); + self::assertIsArray($resultSets); $this->assertArrayHasKey(0, $resultSets); $this->assertInstanceOf(ResultSet::class, $resultSets[0]); diff --git a/test/Elastica/Node/InfoTest.php b/test/Elastica/Node/InfoTest.php index d82df48b94..4bee210534 100644 --- a/test/Elastica/Node/InfoTest.php +++ b/test/Elastica/Node/InfoTest.php @@ -5,9 +5,12 @@ use Elastica\Node; use Elastica\Node\Info as NodeInfo; use Elastica\Test\Base as BaseTest; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; class InfoTest extends BaseTest { + use AssertIsType; + /** * @group functional */ @@ -28,7 +31,7 @@ public function testGet() $this->assertNotNull($info->get('os', 'name')); $this->assertNotNull($info->get('process', 'id')); $this->assertNotNull($info->get('jvm', 'mem', 'heap_init_in_bytes')); - $this->assertInternalType('array', $info->get('jvm', 'mem')); + self::assertIsArray($info->get('jvm', 'mem')); $this->assertNull($info->get('test', 'notest', 'notexist')); } diff --git a/test/Elastica/PipelineTest.php b/test/Elastica/PipelineTest.php index a9bb8a8930..a7d2984f18 100644 --- a/test/Elastica/PipelineTest.php +++ b/test/Elastica/PipelineTest.php @@ -68,10 +68,10 @@ public function testPipelineCreate() $pipeGet = $pipeline->getPipeline('my_custom_pipeline'); $result = $pipeGet->getData(); - $this->assertContains($result['my_custom_pipeline']['description'], 'pipeline for Set'); - $this->assertContains($result['my_custom_pipeline']['processors'][0]['set']['field'], 'field4'); - $this->assertContains($result['my_custom_pipeline']['processors'][0]['set']['value'], '333'); - $this->assertContains($result['my_custom_pipeline']['processors'][0]['trim']['field'], 'field1'); + $this->assertSame($result['my_custom_pipeline']['description'], 'pipeline for Set'); + $this->assertSame($result['my_custom_pipeline']['processors'][0]['set']['field'], 'field4'); + $this->assertSame($result['my_custom_pipeline']['processors'][0]['set']['value'], '333'); + $this->assertSame($result['my_custom_pipeline']['processors'][0]['trim']['field'], 'field1'); } /** diff --git a/test/Elastica/Processor/ConvertTest.php b/test/Elastica/Processor/ConvertTest.php index 0ad70b1903..406bc5c5aa 100644 --- a/test/Elastica/Processor/ConvertTest.php +++ b/test/Elastica/Processor/ConvertTest.php @@ -7,9 +7,12 @@ use Elastica\Processor\Convert; use Elastica\ResultSet; use Elastica\Test\BasePipeline as BasePipelineTest; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; class ConvertTest extends BasePipelineTest { + use AssertIsType; + /** * @group unit */ @@ -96,7 +99,7 @@ public function testConvertField() $results = $result->getResults(); foreach ($results as $result) { $value = $result->getData(); - $this->assertInternalType('float', $value['foo']); + self::assertIsFloat($value['foo']); } $this->assertSame(5.290, ($results[0]->getHit())['_source']['foo']); diff --git a/test/Elastica/Processor/FailTest.php b/test/Elastica/Processor/FailTest.php index bf2c4e6ded..e086a70a0a 100644 --- a/test/Elastica/Processor/FailTest.php +++ b/test/Elastica/Processor/FailTest.php @@ -57,7 +57,7 @@ public function testFailField() $index->refresh(); $this->fail('test should raise an exception!'); } catch (\Exception $e) { - $this->assertContains('custom error fail message', $e->getMessage()); + $this->assertStringContainsString('custom error fail message', $e->getMessage()); } } } diff --git a/test/Elastica/Processor/KvTest.php b/test/Elastica/Processor/KvTest.php index 67adb325e5..698d52b01f 100644 --- a/test/Elastica/Processor/KvTest.php +++ b/test/Elastica/Processor/KvTest.php @@ -69,8 +69,8 @@ public function testKVIncludeExludeKeys() $pipelineGet = $pipeline->getPipeline('my_custom_pipeline'); $result = $pipelineGet->getData(); - $this->assertContains($result['my_custom_pipeline']['processors'][0]['kv']['field'], 'field1'); - $this->assertContains($result['my_custom_pipeline']['processors'][0]['kv']['field_split'], '&'); - $this->assertContains($result['my_custom_pipeline']['processors'][0]['kv']['value_split'], '='); + $this->assertSame($result['my_custom_pipeline']['processors'][0]['kv']['field'], 'field1'); + $this->assertSame($result['my_custom_pipeline']['processors'][0]['kv']['field_split'], '&'); + $this->assertSame($result['my_custom_pipeline']['processors'][0]['kv']['value_split'], '='); } } diff --git a/test/Elastica/Query/IdsTest.php b/test/Elastica/Query/IdsTest.php index 689c3cbc88..0c143114ae 100644 --- a/test/Elastica/Query/IdsTest.php +++ b/test/Elastica/Query/IdsTest.php @@ -12,9 +12,9 @@ class IdsTest extends BaseTest protected $_index; protected $_type; - protected function setUp() + protected function set_up() { - parent::setUp(); + parent::set_up(); if (!$this->_isFunctionalGroup()) { return; diff --git a/test/Elastica/Query/MatchTest.php b/test/Elastica/Query/MatchTest.php index c461691b16..7748627717 100644 --- a/test/Elastica/Query/MatchTest.php +++ b/test/Elastica/Query/MatchTest.php @@ -3,7 +3,7 @@ namespace Elastica\Test\Query; use Elastica\Document; -use Elastica\Query\Match; +use Elastica\Query\MatchQuery; use Elastica\Test\Base as BaseTest; class MatchTest extends BaseTest @@ -24,7 +24,7 @@ public function testToArray() $prefixLength = 3; $maxExpansions = 12; - $query = new Match(); + $query = new MatchQuery(); $query->setFieldQuery($field, $testQuery); $this->hideDeprecated(); $this->showDeprecated(); @@ -78,7 +78,7 @@ public function testMatch() $field = 'name'; $operator = 'or'; - $query = new Match(); + $query = new MatchQuery(); $query->setFieldQuery($field, 'Basel New'); $query->setFieldOperator($field, $operator); @@ -109,7 +109,7 @@ public function testMatchSetFieldBoost() $field = 'name'; $operator = 'or'; - $query = new Match(); + $query = new MatchQuery(); $query->setFieldQuery($field, 'Basel New'); $query->setFieldOperator($field, $operator); $query->setFieldBoost($field, 1.2); @@ -141,7 +141,7 @@ public function testMatchSetFieldBoostWithString() $field = 'name'; $operator = 'or'; - $query = new Match(); + $query = new MatchQuery(); $query->setFieldQuery($field, 'Basel New'); $query->setFieldOperator($field, $operator); $query->setFieldBoost($field, '1.2'); @@ -168,9 +168,9 @@ public function testMatchZeroTerm() $index->refresh(); - $query = new Match(); + $query = new MatchQuery(); $query->setFieldQuery('name', ''); - $query->setFieldZeroTermsQuery('name', Match::ZERO_TERM_ALL); + $query->setFieldZeroTermsQuery('name', MatchQuery::ZERO_TERM_ALL); $resultSet = $index->search($query); @@ -183,7 +183,7 @@ public function testMatchZeroTerm() public function testMatchFuzzinessType() { $field = 'test'; - $query = new Match(); + $query = new MatchQuery(); $fuzziness = 'AUTO'; $query->setFieldFuzziness($field, $fuzziness); @@ -203,14 +203,14 @@ public function testMatchFuzzinessType() */ public function testConstruct() { - $match = new Match(null, 'values'); + $match = new MatchQuery(null, 'values'); $this->assertEquals(['match' => []], $match->toArray()); - $match = new Match('field', null); + $match = new MatchQuery('field', null); $this->assertEquals(['match' => []], $match->toArray()); - $match1 = new Match('field', 'values'); - $match2 = new Match(); + $match1 = new MatchQuery('field', 'values'); + $match2 = new MatchQuery(); $match2->setField('field', 'values'); $this->assertEquals($match1->toArray(), $match2->toArray()); } diff --git a/test/Elastica/Query/PostFilterTest.php b/test/Elastica/Query/PostFilterTest.php index e548f13ca6..d5c2f1deff 100644 --- a/test/Elastica/Query/PostFilterTest.php +++ b/test/Elastica/Query/PostFilterTest.php @@ -4,7 +4,7 @@ use Elastica\Document; use Elastica\Query; -use Elastica\Query\Match; +use Elastica\Query\MatchQuery; use Elastica\Query\Term; use Elastica\Test\Base as BaseTest; @@ -48,7 +48,7 @@ public function testQuery() { $query = new Query(); - $match = new Match(); + $match = new MatchQuery(); $match->setField('make', 'ford'); $query->setQuery($match); diff --git a/test/Elastica/Query/PrefixTest.php b/test/Elastica/Query/PrefixTest.php index 070097fe6b..19ac53f5f9 100644 --- a/test/Elastica/Query/PrefixTest.php +++ b/test/Elastica/Query/PrefixTest.php @@ -4,9 +4,12 @@ use Elastica\Query\Prefix; use Elastica\Test\Base as BaseTest; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; class PrefixTest extends BaseTest { + use AssertIsType; + /** * @group unit */ @@ -20,8 +23,8 @@ public function testToArray() $data = $query->toArray(); - $this->assertInternalType('array', $data['prefix']); - $this->assertInternalType('array', $data['prefix'][$key]); + self::assertIsArray($data['prefix']); + self::assertIsArray($data['prefix'][$key]); $this->assertEquals($data['prefix'][$key]['value'], $value); $this->assertEquals($data['prefix'][$key]['boost'], $boost); } diff --git a/test/Elastica/Query/QueryStringTest.php b/test/Elastica/Query/QueryStringTest.php index cae1ce06ad..59ac41da83 100644 --- a/test/Elastica/Query/QueryStringTest.php +++ b/test/Elastica/Query/QueryStringTest.php @@ -106,11 +106,11 @@ public function testSearchFieldsValidationException() } catch (ResponseException $ex) { $error = $ex->getResponse()->getFullError(); - $this->assertContains('query_shard_exception', $error['root_cause'][0]['type']); - $this->assertContains('failed to create query', $error['root_cause'][0]['reason']); + $this->assertSame('query_shard_exception', $error['root_cause'][0]['type']); + $this->assertStringContainsString('failed to create query', $error['root_cause'][0]['reason']); $this->assertContains('query_validation_exception', $error); - $this->assertContains('[fields] parameter in conjunction with [default_field]', $error['failed_shards'][0]['reason']['caused_by']['reason']); + $this->assertStringContainsString('[fields] parameter in conjunction with [default_field]', $error['failed_shards'][0]['reason']['caused_by']['reason']); $this->assertEquals(400, $ex->getResponse()->getStatus()); } diff --git a/test/Elastica/Query/RescoreTest.php b/test/Elastica/Query/RescoreTest.php index e26c3a9c31..0743b973ab 100644 --- a/test/Elastica/Query/RescoreTest.php +++ b/test/Elastica/Query/RescoreTest.php @@ -3,7 +3,7 @@ namespace Elastica\Test\Query; use Elastica\Query; -use Elastica\Query\Match; +use Elastica\Query\MatchQuery; use Elastica\Query\Term; use Elastica\Rescore\Query as QueryRescore; use Elastica\Test\Base as BaseTest; @@ -16,7 +16,7 @@ class RescoreTest extends BaseTest public function testToArray() { $query = new Query(); - $mainQuery = new Match(); + $mainQuery = new MatchQuery(); $mainQuery = $mainQuery->setFieldQuery('test1', 'foo'); $secQuery = new Term(); $secQuery = $secQuery->setTerm('test2', 'bar', 2); @@ -56,7 +56,7 @@ public function testToArray() public function testSetSize() { $query = new Query(); - $mainQuery = new Match(); + $mainQuery = new MatchQuery(); $mainQuery = $mainQuery->setFieldQuery('test1', 'foo'); $secQuery = new Term(); $secQuery = $secQuery->setTerm('test2', 'bar', 2); @@ -98,7 +98,7 @@ public function testSetSize() public function testSetWeights() { $query = new Query(); - $mainQuery = new Match(); + $mainQuery = new MatchQuery(); $mainQuery = $mainQuery->setFieldQuery('test1', 'foo'); $secQuery = new Term(); $secQuery = $secQuery->setTerm('test2', 'bar', 2); @@ -144,7 +144,7 @@ public function testSetWeights() public function testMultipleQueries() { $query = new Query(); - $mainQuery = new Match(); + $mainQuery = new MatchQuery(); $mainQuery = $mainQuery->setFieldQuery('test1', 'foo'); $secQuery1 = new Term(); @@ -216,7 +216,7 @@ public function testMultipleQueries() public function testQuery() { $query = new Query(); - $mainQuery = new Match(); + $mainQuery = new MatchQuery(); $mainQuery = $mainQuery->setFieldQuery('test1', 'foo'); $secQuery = new Term(); $secQuery = $secQuery->setTerm('test2', 'bar', 2); diff --git a/test/Elastica/Query/ScriptTest.php b/test/Elastica/Query/ScriptTest.php index 8351486645..5eecc39e42 100644 --- a/test/Elastica/Query/ScriptTest.php +++ b/test/Elastica/Query/ScriptTest.php @@ -5,9 +5,12 @@ use Elastica\Query\Script as ScriptQuery; use Elastica\Script\Script; use Elastica\Test\Base as BaseTest; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; class ScriptTest extends BaseTest { + use AssertIsType; + /** * @group unit */ @@ -18,7 +21,7 @@ public function testToArray() $query = new ScriptQuery($string); $array = $query->toArray(); - $this->assertInternalType('array', $array); + self::assertIsArray($array); $expected = [ 'script' => [ diff --git a/test/Elastica/Query/TermTest.php b/test/Elastica/Query/TermTest.php index 40a42bfc81..2f8a177e71 100644 --- a/test/Elastica/Query/TermTest.php +++ b/test/Elastica/Query/TermTest.php @@ -4,9 +4,12 @@ use Elastica\Query\Term; use Elastica\Test\Base as BaseTest; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; class TermTest extends BaseTest { + use AssertIsType; + /** * @group unit */ @@ -20,8 +23,8 @@ public function testToArray() $data = $query->toArray(); - $this->assertInternalType('array', $data['term']); - $this->assertInternalType('array', $data['term'][$key]); + self::assertIsArray($data['term']); + self::assertIsArray($data['term'][$key]); $this->assertEquals($data['term'][$key]['value'], $value); $this->assertEquals($data['term'][$key]['boost'], $boost); } @@ -39,8 +42,8 @@ public function testDiacriticsValueToArray() $data = $query->toArray(); - $this->assertInternalType('array', $data['term']); - $this->assertInternalType('array', $data['term'][$key]); + self::assertIsArray($data['term']); + self::assertIsArray($data['term'][$key]); $this->assertEquals($data['term'][$key]['value'], $value); $this->assertEquals($data['term'][$key]['boost'], $boost); } diff --git a/test/Elastica/QueryBuilder/DSL/AbstractDSLTest.php b/test/Elastica/QueryBuilder/DSL/AbstractDSLTest.php index f2e4837f86..ff357c67db 100644 --- a/test/Elastica/QueryBuilder/DSL/AbstractDSLTest.php +++ b/test/Elastica/QueryBuilder/DSL/AbstractDSLTest.php @@ -103,10 +103,10 @@ protected function _getHintName(\ReflectionParameter $param) return null; } - if ($class = $param->getClass()) { - return $class->getName(); + if (\in_array($type->getName(), ['array', 'callable'], true) + || !$type->isBuiltin() + ) { + return $type->getName(); } - - return null; } } diff --git a/test/Elastica/QueryBuilder/DSL/QueryTest.php b/test/Elastica/QueryBuilder/DSL/QueryTest.php index 7bafc6d80c..e441c01c29 100644 --- a/test/Elastica/QueryBuilder/DSL/QueryTest.php +++ b/test/Elastica/QueryBuilder/DSL/QueryTest.php @@ -3,7 +3,7 @@ namespace Elastica\Test\QueryBuilder\DSL; use Elastica\Query; -use Elastica\Query\Match; +use Elastica\Query\MatchQuery; use Elastica\QueryBuilder\DSL; class QueryTest extends AbstractDSLTest @@ -28,7 +28,7 @@ public function testMatch() $match = $queryDSL->match('field', 'match'); $this->assertEquals('match', $match->getParam('field')); - $this->assertInstanceOf(Match::class, $match); + $this->assertInstanceOf(MatchQuery::class, $match); } /** @@ -44,10 +44,10 @@ public function testInterface() $this->_assertImplemented($queryDSL, 'dis_max', Query\DisMax::class, []); $this->_assertImplemented($queryDSL, 'function_score', Query\FunctionScore::class, []); $this->_assertImplemented($queryDSL, 'fuzzy', Query\Fuzzy::class, ['field', 'type']); - $this->_assertImplemented($queryDSL, 'has_child', Query\HasChild::class, [new Match()]); - $this->_assertImplemented($queryDSL, 'has_parent', Query\HasParent::class, [new Match(), 'type']); + $this->_assertImplemented($queryDSL, 'has_child', Query\HasChild::class, [new MatchQuery()]); + $this->_assertImplemented($queryDSL, 'has_parent', Query\HasParent::class, [new MatchQuery(), 'type']); $this->_assertImplemented($queryDSL, 'ids', Query\Ids::class, [[]]); - $this->_assertImplemented($queryDSL, 'match', Match::class, ['field', 'values']); + $this->_assertImplemented($queryDSL, 'match', MatchQuery::class, ['field', 'values']); $this->_assertImplemented($queryDSL, 'match_all', Query\MatchAll::class, []); $this->_assertImplemented($queryDSL, 'match_none', Query\MatchNone::class, []); $this->_assertImplemented($queryDSL, 'more_like_this', Query\MoreLikeThis::class, []); diff --git a/test/Elastica/ReindexTest.php b/test/Elastica/ReindexTest.php index 200a2060aa..82fa216488 100644 --- a/test/Elastica/ReindexTest.php +++ b/test/Elastica/ReindexTest.php @@ -4,7 +4,7 @@ use Elastica\Document; use Elastica\Index; -use Elastica\Query\Match; +use Elastica\Query\MatchQuery; use Elastica\Reindex; use Elastica\Type; @@ -107,7 +107,7 @@ public function testReindexWithQueryOption() $newIndex = $this->_createIndex('idx2', true, 2); - $query = new Match('id', 8); + $query = new MatchQuery('id', 8); $reindex = new Reindex($oldIndex, $newIndex, [ Reindex::QUERY => $query, diff --git a/test/Elastica/RequestTest.php b/test/Elastica/RequestTest.php index 7e2e93a998..a7fb95cafb 100644 --- a/test/Elastica/RequestTest.php +++ b/test/Elastica/RequestTest.php @@ -6,9 +6,12 @@ use Elastica\Request; use Elastica\Response; use Elastica\Test\Base as BaseTest; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; class RequestTest extends BaseTest { + use AssertIsType; + /** * @group unit */ @@ -72,7 +75,7 @@ public function testToString() $data = $request->toArray(); - $this->assertInternalType('array', $data); + self::assertIsArray($data); $this->assertArrayHasKey('method', $data); $this->assertArrayHasKey('path', $data); $this->assertArrayHasKey('query', $data); @@ -82,7 +85,7 @@ public function testToString() $this->assertEquals($request->getPath(), $data['path']); $this->assertEquals($request->getQuery(), $data['query']); $this->assertEquals($request->getData(), $data['data']); - $this->assertInternalType('array', $data['connection']); + self::assertIsArray($data['connection']); $this->assertArrayHasKey('host', $data['connection']); $this->assertArrayHasKey('port', $data['connection']); $this->assertEquals($request->getConnection()->getHost(), $data['connection']['host']); @@ -90,9 +93,9 @@ public function testToString() $string = $request->toString(); - $this->assertInternalType('string', $string); + self::assertIsString($string); $string = (string) $request; - $this->assertInternalType('string', $string); + self::assertIsString($string); } } diff --git a/test/Elastica/ResponseTest.php b/test/Elastica/ResponseTest.php index 28e410df60..3e22fe8de9 100644 --- a/test/Elastica/ResponseTest.php +++ b/test/Elastica/ResponseTest.php @@ -10,9 +10,12 @@ use Elastica\Response; use Elastica\Test\Base as BaseTest; use Elastica\Type\Mapping; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; class ResponseTest extends BaseTest { + use AssertIsType; + /** * @group functional */ @@ -43,8 +46,8 @@ public function testResponse() $engineTime = $resultSet->getResponse()->getEngineTime(); $shardsStats = $resultSet->getResponse()->getShardsStatistics(); - $this->assertInternalType('int', $engineTime); - $this->assertInternalType('array', $shardsStats); + self::assertIsInt($engineTime); + self::assertIsArray($shardsStats); $this->assertArrayHasKey('total', $shardsStats); $this->assertArrayHasKey('successful', $shardsStats); } @@ -216,7 +219,7 @@ public function testDecodeResponseWithBigIntSetToTrue() ])); $response->setJsonBigintConversion(true); - $this->assertInternalType('array', $response->getData()); + self::assertIsArray($response->getData()); } /** @@ -235,7 +238,7 @@ public function testGetDataEmpty() } catch (ResponseException $e) { $error = $e->getResponse()->getFullError(); $this->assertEquals('type_missing_exception', $error['type']); - $this->assertContains('non-existent-type', $error['reason']); + $this->assertStringContainsString('non-existent-type', $error['reason']); } $this->assertNull($response); diff --git a/test/Elastica/ResultSet/BuilderTest.php b/test/Elastica/ResultSet/BuilderTest.php index b02e705167..605c7a6129 100644 --- a/test/Elastica/ResultSet/BuilderTest.php +++ b/test/Elastica/ResultSet/BuilderTest.php @@ -17,9 +17,9 @@ class BuilderTest extends BaseTest */ private $builder; - protected function setUp() + protected function set_up() { - parent::setUp(); + parent::set_up(); $this->builder = new DefaultBuilder(); } diff --git a/test/Elastica/ResultSet/ProcessingBuilderTest.php b/test/Elastica/ResultSet/ProcessingBuilderTest.php index 781dfd414f..5ec74f3b0c 100644 --- a/test/Elastica/ResultSet/ProcessingBuilderTest.php +++ b/test/Elastica/ResultSet/ProcessingBuilderTest.php @@ -30,9 +30,9 @@ class ProcessingBuilderTest extends BaseTest */ private $processor; - protected function setUp() + protected function set_up() { - parent::setUp(); + parent::set_up(); $this->innerBuilder = $this->createMock(BuilderInterface::class); $this->processor = $this->createMock(ProcessorInterface::class); diff --git a/test/Elastica/ResultSetTest.php b/test/Elastica/ResultSetTest.php index 14e7aa1016..3d18f02f57 100644 --- a/test/Elastica/ResultSetTest.php +++ b/test/Elastica/ResultSetTest.php @@ -6,9 +6,12 @@ use Elastica\Result; use Elastica\ResultSet; use Elastica\Test\Base as BaseTest; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; class ResultSetTest extends BaseTest { + use AssertIsType; + /** * @group functional */ @@ -32,7 +35,7 @@ public function testGetters() $this->assertNotTrue($resultSet->hasTimedOut()); $this->assertNotTrue($resultSet->hasAggregations()); $this->assertNotTrue($resultSet->hasSuggests()); - $this->assertInternalType('array', $resultSet->getResults()); + self::assertIsArray($resultSet->getResults()); $this->assertCount(3, $resultSet); } @@ -82,7 +85,7 @@ public function testDocumentsAccess() $documents = $resultSet->getDocuments(); - $this->assertInternalType('array', $documents); + self::assertIsArray($documents); $this->assertCount(3, $documents); $this->assertInstanceOf(Document::class, $documents[0]); $this->assertInstanceOf(Document::class, $documents[1]); diff --git a/test/Elastica/ResultTest.php b/test/Elastica/ResultTest.php index 16d51156d1..8eec2e8650 100644 --- a/test/Elastica/ResultTest.php +++ b/test/Elastica/ResultTest.php @@ -6,9 +6,12 @@ use Elastica\Result; use Elastica\Test\Base as BaseTest; use Elastica\Type\Mapping; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; class ResultTest extends BaseTest { + use AssertIsType; + /** * @group functional */ @@ -40,7 +43,7 @@ public function testGetters() $this->assertEquals($typeName, $result->getType()); $this->assertEquals($docId, $result->getId()); $this->assertGreaterThan(0, $result->getScore()); - $this->assertInternalType('array', $result->getData()); + self::assertIsArray($result->getData()); $this->assertTrue(isset($result->username)); $this->assertEquals('hans', $result->username); } @@ -83,7 +86,7 @@ public function testGetIdNoSource() $this->assertEquals($typeName, $result->getType()); $this->assertEquals($docId, $result->getId()); $this->assertGreaterThan(0, $result->getScore()); - $this->assertInternalType('array', $result->getData()); + self::assertIsArray($result->getData()); } /** diff --git a/test/Elastica/SnapshotTest.php b/test/Elastica/SnapshotTest.php index f643b4a9fe..3f4c98bd92 100644 --- a/test/Elastica/SnapshotTest.php +++ b/test/Elastica/SnapshotTest.php @@ -26,9 +26,9 @@ class SnapshotTest extends Base */ protected $_docs; - protected function setUp() + protected function set_up() { - parent::setUp(); + parent::set_up(); $this->_snapshot = new Snapshot($this->_getClient()); $this->_index = $this->_createIndex(); diff --git a/test/Elastica/StatusTest.php b/test/Elastica/StatusTest.php index f247f1152c..e70d440a45 100644 --- a/test/Elastica/StatusTest.php +++ b/test/Elastica/StatusTest.php @@ -6,9 +6,12 @@ use Elastica\Response; use Elastica\Status; use Elastica\Test\Base as BaseTest; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; class StatusTest extends BaseTest { + use AssertIsType; + /** * @group functional */ @@ -35,11 +38,11 @@ public function testGetIndexNames() $status = new Status($index->getClient()); $names = $status->getIndexNames(); - $this->assertInternalType('array', $names); + self::assertIsArray($names); $this->assertContains($index->getName(), $names); foreach ($names as $name) { - $this->assertInternalType('string', $name); + self::assertIsString($name); } } diff --git a/test/Elastica/TaskTest.php b/test/Elastica/TaskTest.php index 4e1322aa43..f8776183a0 100644 --- a/test/Elastica/TaskTest.php +++ b/test/Elastica/TaskTest.php @@ -5,9 +5,12 @@ use Elastica\Document; use Elastica\Task; use Elastica\Type; +use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType; class TaskTest extends Base { + use AssertIsType; + /** * @group functional */ @@ -16,7 +19,7 @@ public function testGetData() $task = $this->_createTask(); $data = $task->getData(); - $this->assertInternalType('array', $data); + self::assertIsArray($data); $this->assertNotEmpty($data); } diff --git a/test/Elastica/Transport/AwsAuthV4Test.php b/test/Elastica/Transport/AwsAuthV4Test.php index 0241d9f12d..c64225127f 100644 --- a/test/Elastica/Transport/AwsAuthV4Test.php +++ b/test/Elastica/Transport/AwsAuthV4Test.php @@ -7,8 +7,10 @@ class AwsAuthV4Test extends GuzzleTest { - public static function setUpBeforeClass() + public static function set_up_before_class() { + parent::set_up_before_class(); + if (!class_exists('Aws\\Sdk')) { self::markTestSkipped('aws/aws-sdk-php package should be installed to run SignatureV4 transport tests'); } diff --git a/test/Elastica/Transport/GuzzleTest.php b/test/Elastica/Transport/GuzzleTest.php index 3ec6e67c12..f3967d6249 100644 --- a/test/Elastica/Transport/GuzzleTest.php +++ b/test/Elastica/Transport/GuzzleTest.php @@ -9,8 +9,10 @@ class GuzzleTest extends BaseTest { - public static function setUpBeforeClass() + public static function set_up_before_class() { + parent::set_up_before_class(); + if (!class_exists('GuzzleHttp\\Client')) { self::markTestSkipped('guzzlehttp/guzzle package should be installed to run guzzle transport tests'); } @@ -185,14 +187,15 @@ protected function checkProxy($url) $this->_checkConnection($url['host'], $url['port']); } - protected function setUp() + protected function set_up() { + parent::set_up(); putenv('http_proxy='); } - protected function tearDown() + protected function tear_down() { - parent::tearDown(); + parent::tear_down(); putenv('http_proxy='); } } diff --git a/test/Elastica/Transport/HttpTest.php b/test/Elastica/Transport/HttpTest.php index 60a843137a..940ad6cbc5 100644 --- a/test/Elastica/Transport/HttpTest.php +++ b/test/Elastica/Transport/HttpTest.php @@ -265,9 +265,9 @@ protected function checkProxy($url) $this->_checkConnection($url['host'], $url['port']); } - protected function tearDown() + protected function tear_down() { - parent::tearDown(); + parent::tear_down(); putenv('http_proxy='); } } diff --git a/test/Elastica/Transport/NullTransportTest.php b/test/Elastica/Transport/NullTransportTest.php index 40bcc6993c..45a36bdf12 100644 --- a/test/Elastica/Transport/NullTransportTest.php +++ b/test/Elastica/Transport/NullTransportTest.php @@ -20,9 +20,9 @@ class NullTransportTest extends BaseTest /** @var NullTransport NullTransport */ protected $transport; - public function setUp() + public function set_up() { - parent::setUp(); + parent::set_up(); $this->transport = new NullTransport(); } @@ -47,13 +47,13 @@ public function testEmptyResult() // Validate most of the expected fields in the response data. Consumers of the response // object have a reasonable expectation of finding "hits", "took", etc $responseData = $response->getData(); - $this->assertContains('took', $responseData); + $this->assertArrayHasKey('took', $responseData); $this->assertEquals(0, $responseData['took']); - $this->assertContains('_shards', $responseData); - $this->assertContains('hits', $responseData); - $this->assertContains('total', $responseData['hits']); + $this->assertArrayHasKey('_shards', $responseData); + $this->assertArrayHasKey('hits', $responseData); + $this->assertArrayHasKey('total', $responseData['hits']); $this->assertEquals(0, $responseData['hits']['total']); - $this->assertContains('params', $responseData); + $this->assertArrayHasKey('params', $responseData); $took = $response->getEngineTime(); $this->assertEquals(0, $took); @@ -62,11 +62,11 @@ public function testEmptyResult() $this->assertEmpty($errorString); $shards = $response->getShardsStatistics(); - $this->assertContains('total', $shards); + $this->assertArrayHasKey('total', $shards); $this->assertEquals(0, $shards['total']); - $this->assertContains('successful', $shards); + $this->assertArrayHasKey('successful', $shards); $this->assertEquals(0, $shards['successful']); - $this->assertContains('failed', $shards); + $this->assertArrayHasKey('failed', $shards); $this->assertEquals(0, $shards['failed']); } @@ -107,7 +107,7 @@ public function testGenerateDefaultResponse() $this->assertEquals([], $response->getTransferInfo()); $responseData = $response->getData(); - $this->assertContains('params', $responseData); + $this->assertArrayHasKey('params', $responseData); $this->assertEquals($params, $responseData['params']); } } diff --git a/test/Elastica/Transport/TransportBenchmarkTest.php b/test/Elastica/Transport/TransportBenchmarkTest.php index 2c15c38874..61ce043815 100644 --- a/test/Elastica/Transport/TransportBenchmarkTest.php +++ b/test/Elastica/Transport/TransportBenchmarkTest.php @@ -12,9 +12,9 @@ class TransportBenchmarkTest extends BaseTest { - protected function setUp() + protected function set_up() { - parent::setUp(); + parent::set_up(); $this->markTestIncomplete('Benchmarks currently skipped with es2.0. Has to be reworked'); } @@ -24,9 +24,11 @@ protected function setUp() protected static $_results = []; - public static function tearDownAfterClass() + public static function tear_down_after_class() { self::printResults(); + + parent::tear_down_after_class(); } /** diff --git a/test/Elastica/Type/MappingTest.php b/test/Elastica/Type/MappingTest.php index 9f5007b2a2..d01cbcc0ca 100644 --- a/test/Elastica/Type/MappingTest.php +++ b/test/Elastica/Type/MappingTest.php @@ -248,6 +248,7 @@ public function testDynamicTemplate() { $index = $this->_createIndex(); $type = $index->getType('_doc'); + $rawFieldsType = ['raw' => ['type' => 'keyword']]; $mapping = new Mapping($type); $mapping->setParam('dynamic_templates', [ @@ -255,9 +256,7 @@ public function testDynamicTemplate() 'match' => 'multi*', 'mapping' => [ 'type' => '{dynamic_type}', - 'fields' => [ - 'raw' => ['type' => 'keyword'], - ], + 'fields' => $rawFieldsType, ], ]], ]); @@ -273,22 +272,14 @@ public function testDynamicTemplate() $index->refresh(); $newMapping = $type->getMapping(); - $this->assertArraySubset( + $this->assertArrayHasKey('properties', $newMapping['_doc']); + $this->assertArrayHasKey('multiname', $newMapping['_doc']['properties']); + $this->assertSame( [ - '_doc' => [ - 'properties' => [ - 'multiname' => [ - 'type' => 'text', - 'fields' => [ - 'raw' => [ - 'type' => 'keyword', - ], - ], - ], - ], - ], + 'type' => 'text', + 'fields' => $rawFieldsType, ], - $newMapping, + $newMapping['_doc']['properties']['multiname'], 'Mapping of dynamic "multiname" field should have been created with the type "{dynamic_type}" resolved to "text". '. 'The "multiname.raw" sub-field should be of type "keyword".' ); diff --git a/test/Elastica/TypeTest.php b/test/Elastica/TypeTest.php index 25734b4d7b..1c42b683c6 100644 --- a/test/Elastica/TypeTest.php +++ b/test/Elastica/TypeTest.php @@ -667,9 +667,9 @@ public function testUpdateDocumentWithParameter() } catch (ResponseException $e) { $error = $e->getResponse()->getFullError(); - $this->assertContains('action_request_validation_exception', $error['type']); - $this->assertContains('can\'t provide version in upsert request', $error['reason']); - $this->assertContains('can\'t provide both upsert request and a version', $error['reason']); + $this->assertStringContainsString('action_request_validation_exception', $error['type']); + $this->assertStringContainsString('can\'t provide version in upsert request', $error['reason']); + $this->assertStringContainsString('can\'t provide both upsert request and a version', $error['reason']); } $updatedDoc = $type->getDocument($id)->getData(); @@ -781,7 +781,7 @@ public function testUpdateDocumentWithoutSource() $this->fail('Update request should fail because source is disabled. Fields param is not set'); } catch (ResponseException $e) { $error = $e->getResponse()->getFullError(); - $this->assertContains('document_source_missing_exception', $error['type']); + $this->assertStringContainsString('document_source_missing_exception', $error['type']); } $newDocument->setFieldsSource(); @@ -791,7 +791,7 @@ public function testUpdateDocumentWithoutSource() $this->fail('Update request should fail because source is disabled. Fields param is set to _source'); } catch (ResponseException $e) { $error = $e->getResponse()->getFullError(); - $this->assertContains('document_source_missing_exception', $error['type']); + $this->assertStringContainsString('document_source_missing_exception', $error['type']); } }