diff --git a/.php_cs.dist b/.php_cs.dist index 984060b3bc..6e4d4c3cd4 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -7,19 +7,25 @@ $finder = PhpCsFixer\Finder::create() return PhpCsFixer\Config::create() ->setFinder($finder) ->setRules([ + '@PHP71Migration' => true, + '@PhpCsFixer' => true, + '@PHPUnit60Migration:risky' => true, '@PSR2' => true, '@Symfony' => true, - 'single_blank_line_before_namespace' => false, - 'ordered_imports' => true, 'array_syntax' => ['syntax' => 'short'], - 'phpdoc_order' => true, - 'ternary_to_null_coalescing' => true, - 'no_useless_else' => true, - '@PHPUnit60Migration:risky' => true, - 'php_unit_dedicate_assert' => ['target' => 'newest'], + 'is_null' => true, + 'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'], 'native_function_invocation' => true, 'no_alias_functions' => true, + 'no_useless_else' => true, 'nullable_type_declaration_for_default_null_value' => true, + 'ordered_imports' => true, + 'php_unit_dedicate_assert' => ['target' => 'newest'], + 'php_unit_test_class_requires_covers' => false, + 'phpdoc_order' => true, + 'phpdoc_types_order' => ['null_adjustment' => 'always_last'], + 'ternary_to_null_coalescing' => true, 'visibility_required' => ['property', 'method', 'const'], + 'void_return' => true, ]) ; diff --git a/src/AbstractUpdateAction.php b/src/AbstractUpdateAction.php index 0b3f83d217..ebf3ccae83 100644 --- a/src/AbstractUpdateAction.php +++ b/src/AbstractUpdateAction.php @@ -81,7 +81,7 @@ public function setVersion($version) /** * Returns document version. * - * @return string|int Document version + * @return int|string Document version */ public function getVersion() { @@ -112,7 +112,7 @@ public function setVersionType($versionType) /** * Returns document version type. * - * @return string|int Document version type + * @return int|string Document version type */ public function getVersionType() { @@ -356,7 +356,7 @@ public function hasReplication() } /** - * @param Document|array $data + * @param array|Document $data * * @return $this */ diff --git a/src/Aggregation/AbstractSimpleAggregation.php b/src/Aggregation/AbstractSimpleAggregation.php index b9538c829f..ad836c3ef9 100644 --- a/src/Aggregation/AbstractSimpleAggregation.php +++ b/src/Aggregation/AbstractSimpleAggregation.php @@ -21,7 +21,7 @@ public function setField(string $field): self /** * Set a script for this aggregation. * - * @param string|\Elastica\Script\AbstractScript $script + * @param \Elastica\Script\AbstractScript|string $script * * @return $this */ diff --git a/src/Aggregation/BucketScript.php b/src/Aggregation/BucketScript.php index 568809d0c4..bfdbe0d4b7 100644 --- a/src/Aggregation/BucketScript.php +++ b/src/Aggregation/BucketScript.php @@ -71,7 +71,8 @@ public function toArray(): array { if (!$this->hasParam('buckets_path')) { throw new InvalidException('Buckets path is required'); - } elseif (!$this->hasParam('script')) { + } + if (!$this->hasParam('script')) { throw new InvalidException('Script parameter is required'); } diff --git a/src/Aggregation/GeoDistance.php b/src/Aggregation/GeoDistance.php index f80810e10d..3905f87993 100644 --- a/src/Aggregation/GeoDistance.php +++ b/src/Aggregation/GeoDistance.php @@ -20,7 +20,7 @@ class GeoDistance extends AbstractAggregation /** * @param string $name the name if this aggregation * @param string $field the field on which to perform this aggregation - * @param string|array $origin the point from which distances will be calculated + * @param array|string $origin the point from which distances will be calculated */ public function __construct(string $name, string $field, $origin) { @@ -43,7 +43,7 @@ public function setField(string $field): self /** * Set the origin point from which distances will be calculated. * - * @param string|array $origin valid formats are array("lat" => 52.3760, "lon" => 4.894), "52.3760, 4.894", and array(4.894, 52.3760) + * @param array|string $origin valid formats are array("lat" => 52.3760, "lon" => 4.894), "52.3760, 4.894", and array(4.894, 52.3760) * * @return $this */ diff --git a/src/Aggregation/ParentAggregation.php b/src/Aggregation/ParentAggregation.php index 6f2704b392..daef41c98f 100644 --- a/src/Aggregation/ParentAggregation.php +++ b/src/Aggregation/ParentAggregation.php @@ -9,11 +9,6 @@ */ class ParentAggregation extends AbstractAggregation { - protected function _getBaseName() - { - return 'parent'; - } - /** * Set the child type for this aggregation. * @@ -25,4 +20,9 @@ public function setType($type): self { return $this->setParam('type', $type); } + + protected function _getBaseName() + { + return 'parent'; + } } diff --git a/src/Aggregation/Range.php b/src/Aggregation/Range.php index d66551e5b2..7d0272b40d 100644 --- a/src/Aggregation/Range.php +++ b/src/Aggregation/Range.php @@ -14,8 +14,8 @@ class Range extends AbstractSimpleAggregation /** * Add a range to this aggregation. * - * @param int|float $fromValue low end of this range, exclusive (greater than or equal to) - * @param int|float $toValue high end of this range, exclusive (less than) + * @param float|int $fromValue low end of this range, exclusive (greater than or equal to) + * @param float|int $toValue high end of this range, exclusive (less than) * @param string $key customized key value * * @throws \Elastica\Exception\InvalidException diff --git a/src/Aggregation/TopHits.php b/src/Aggregation/TopHits.php index 18edf4724a..515ffda442 100644 --- a/src/Aggregation/TopHits.php +++ b/src/Aggregation/TopHits.php @@ -58,7 +58,7 @@ public function setSort(array $sortArgs): self /** * Allows to control how the _source field is returned with every hit. * - * @param array|string|bool $params Fields to be returned or false to disable source + * @param array|bool|string $params Fields to be returned or false to disable source * * @return $this */ diff --git a/src/Bulk.php b/src/Bulk.php index e881897ec9..ba7b09db6e 100644 --- a/src/Bulk.php +++ b/src/Bulk.php @@ -45,8 +45,13 @@ public function __construct(Client $client) $this->_client = $client; } + public function __toString(): string + { + return $this->toString(); + } + /** - * @param string|Index $index + * @param Index|string $index * * @return $this */ @@ -153,6 +158,7 @@ public function addScript(AbstractScript $script, ?string $opType = null): self /** * @param Document[] $scripts + * @param mixed|null $opType * * @return $this */ @@ -166,7 +172,7 @@ public function addScripts(array $scripts, $opType = null): self } /** - * @param \Elastica\Script\AbstractScript|\Elastica\Document|array $data + * @param array|\Elastica\Document|\Elastica\Script\AbstractScript $data * * @return $this */ @@ -254,11 +260,6 @@ public function setShardTimeout(string $time): self return $this->setRequestParam('timeout', $time); } - public function __toString(): string - { - return $this->toString(); - } - public function toString(): string { $data = ''; diff --git a/src/Bulk/Action.php b/src/Bulk/Action.php index 350a4bc620..d6a435eb49 100644 --- a/src/Bulk/Action.php +++ b/src/Bulk/Action.php @@ -106,7 +106,7 @@ public function hasSource(): bool } /** - * @param string|Index $index + * @param Index|string $index * * @return $this */ @@ -131,7 +131,7 @@ public function setId(string $id): self } /** - * @param string|int $routing + * @param int|string $routing * * @return $this */ diff --git a/src/Bulk/Action/AbstractDocument.php b/src/Bulk/Action/AbstractDocument.php index 4ae9cca76c..b149657a6e 100644 --- a/src/Bulk/Action/AbstractDocument.php +++ b/src/Bulk/Action/AbstractDocument.php @@ -10,12 +10,12 @@ abstract class AbstractDocument extends Action { /** - * @var Document|AbstractScript + * @var AbstractScript|Document */ protected $_data; /** - * @param Document|AbstractScript $document + * @param AbstractScript|Document $document */ public function __construct($document) { @@ -102,21 +102,19 @@ public function getScript() } /** - * @return Document|AbstractScript + * @return AbstractScript|Document */ public function getData() { return $this->_data; } - abstract protected function _getMetadata(AbstractUpdateAction $source): array; - /** * Creates a bulk action for a document or a script. * * The action can be index, update, create or delete based on the $opType param (by default index). * - * @param Document|AbstractScript $data + * @param AbstractScript|Document $data * @param string $opType * * @return static @@ -162,4 +160,6 @@ public static function create($data, ?string $opType = null): self return $action; } + + abstract protected function _getMetadata(AbstractUpdateAction $source): array; } diff --git a/src/Bulk/ResponseSet.php b/src/Bulk/ResponseSet.php index f06af62c34..344d40f2d9 100644 --- a/src/Bulk/ResponseSet.php +++ b/src/Bulk/ResponseSet.php @@ -94,7 +94,7 @@ public function current(): Response /** * {@inheritdoc} */ - public function next() + public function next(): void { ++$this->_position; } @@ -118,7 +118,7 @@ public function valid(): bool /** * {@inheritdoc} */ - public function rewind() + public function rewind(): void { $this->_position = 0; } diff --git a/src/Client.php b/src/Client.php index c2c021d680..9a570fd53c 100644 --- a/src/Client.php +++ b/src/Client.php @@ -95,60 +95,6 @@ public function getVersion(): string return $this->_version = $data['version']['number']; } - /** - * Inits the client connections. - */ - protected function _initConnections(): void - { - $connections = []; - - foreach ($this->getConfig('connections') as $connection) { - $connections[] = Connection::create($this->_prepareConnectionParams($connection)); - } - - if ($this->_config->has('servers')) { - $servers = $this->_config->get('servers'); - foreach ($servers as $server) { - $connections[] = Connection::create($this->_prepareConnectionParams($server)); - } - } - - // If no connections set, create default connection - if (empty($connections)) { - $connections[] = Connection::create($this->_prepareConnectionParams($this->getConfig())); - } - - if (!$this->_config->has('connectionStrategy')) { - if (true === $this->getConfig('roundRobin')) { - $this->setConfigValue('connectionStrategy', 'RoundRobin'); - } else { - $this->setConfigValue('connectionStrategy', 'Simple'); - } - } - - $strategy = Connection\Strategy\StrategyFactory::create($this->getConfig('connectionStrategy')); - - $this->_connectionPool = new Connection\ConnectionPool($connections, $strategy, $this->_callback); - } - - /** - * Creates a Connection params array from a Client or server config array. - */ - protected function _prepareConnectionParams(array $config): array - { - $params = []; - $params['config'] = []; - foreach ($config as $key => $value) { - if (\in_array($key, ['bigintConversion', 'curl', 'headers', 'url'])) { - $params['config'][$key] = $value; - } else { - $params[$key] = $value; - } - } - - return $params; - } - /** * Sets specific config values (updates and keeps default values). * @@ -308,7 +254,7 @@ public function addDocuments(array $docs, array $requestParams = []): ResponseSe * Update document, using update script. Requires elasticsearch >= 0.19.0. * * @param int|string $id document id - * @param array|\Elastica\Script\AbstractScript|\Elastica\Document $data raw data for request body + * @param array|\Elastica\Document|\Elastica\Script\AbstractScript $data raw data for request body * @param string $index index to update * @param array $options array of query params to use for query. For possible options check es api * @@ -490,8 +436,8 @@ public function setConnections(array $connections) * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-bulk.html * * @param array $ids Document ids - * @param string|\Elastica\Index $index Index name - * @param string|bool $routing Optional routing key for all ids + * @param \Elastica\Index|string $index Index name + * @param bool|string $routing Optional routing key for all ids * * @throws InvalidException */ @@ -563,7 +509,7 @@ public function bulk(array $params): ResponseSet * @param array $query OPTIONAL Query params * @param string $contentType Content-Type sent with this request * - * @throws Exception\ConnectionException|Exception\ClientException + * @throws Exception\ClientException|Exception\ConnectionException */ public function request(string $path, string $method = Request::GET, $data = [], array $query = [], string $contentType = Request::DEFAULT_CONTENT_TYPE): Response { @@ -657,4 +603,58 @@ public function setLogger(LoggerInterface $logger) return $this; } + + /** + * Inits the client connections. + */ + protected function _initConnections(): void + { + $connections = []; + + foreach ($this->getConfig('connections') as $connection) { + $connections[] = Connection::create($this->_prepareConnectionParams($connection)); + } + + if ($this->_config->has('servers')) { + $servers = $this->_config->get('servers'); + foreach ($servers as $server) { + $connections[] = Connection::create($this->_prepareConnectionParams($server)); + } + } + + // If no connections set, create default connection + if (empty($connections)) { + $connections[] = Connection::create($this->_prepareConnectionParams($this->getConfig())); + } + + if (!$this->_config->has('connectionStrategy')) { + if (true === $this->getConfig('roundRobin')) { + $this->setConfigValue('connectionStrategy', 'RoundRobin'); + } else { + $this->setConfigValue('connectionStrategy', 'Simple'); + } + } + + $strategy = Connection\Strategy\StrategyFactory::create($this->getConfig('connectionStrategy')); + + $this->_connectionPool = new Connection\ConnectionPool($connections, $strategy, $this->_callback); + } + + /** + * Creates a Connection params array from a Client or server config array. + */ + protected function _prepareConnectionParams(array $config): array + { + $params = []; + $params['config'] = []; + foreach ($config as $key => $value) { + if (\in_array($key, ['bigintConversion', 'curl', 'headers', 'url'])) { + $params['config'][$key] = $value; + } else { + $params[$key] = $value; + } + } + + return $params; + } } diff --git a/src/Cluster/Health.php b/src/Cluster/Health.php index eff20979c8..1e54bcac8d 100644 --- a/src/Cluster/Health.php +++ b/src/Cluster/Health.php @@ -30,19 +30,6 @@ public function __construct(Client $client) $this->refresh(); } - /** - * Retrieves the health data from the cluster. - */ - protected function _retrieveHealthData(): array - { - $endpoint = new \Elasticsearch\Endpoints\Cluster\Health(); - $endpoint->setParams(['level' => 'shards']); - - $response = $this->_client->requestEndpoint($endpoint); - - return $response->getData(); - } - /** * Gets the health data. */ @@ -185,4 +172,17 @@ public function getIndices(): array return $indices; } + + /** + * Retrieves the health data from the cluster. + */ + protected function _retrieveHealthData(): array + { + $endpoint = new \Elasticsearch\Endpoints\Cluster\Health(); + $endpoint->setParams(['level' => 'shards']); + + $response = $this->_client->requestEndpoint($endpoint); + + return $response->getData(); + } } diff --git a/src/Connection.php b/src/Connection.php index 2d23266e23..3a155c4cf7 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -125,7 +125,7 @@ public function setProxy($proxy) } /** - * @return string|array + * @return array|string */ public function getTransport() { @@ -133,7 +133,7 @@ public function getTransport() } /** - * @param string|array $transport + * @param array|string $transport * * @return $this */ @@ -321,7 +321,7 @@ public function getConfig($key = '') } /** - * @param \Elastica\Connection|array $params Params to create a connection + * @param array|\Elastica\Connection $params Params to create a connection * * @throws Exception\InvalidException * diff --git a/src/Connection/ConnectionPool.php b/src/Connection/ConnectionPool.php index 5023385bf5..7998099f3e 100644 --- a/src/Connection/ConnectionPool.php +++ b/src/Connection/ConnectionPool.php @@ -86,7 +86,7 @@ public function getConnection(): Connection return $this->_strategy->getConnection($this->getConnections()); } - public function onFail(Connection $connection, Exception $e, Client $client) + public function onFail(Connection $connection, Exception $e, Client $client): void { $connection->setEnabled(false); diff --git a/src/Connection/Strategy/StrategyFactory.php b/src/Connection/Strategy/StrategyFactory.php index b48a68bc48..971c9492ba 100644 --- a/src/Connection/Strategy/StrategyFactory.php +++ b/src/Connection/Strategy/StrategyFactory.php @@ -12,7 +12,7 @@ class StrategyFactory { /** - * @param mixed|callable|string|StrategyInterface $strategyName + * @param callable|mixed|StrategyInterface|string $strategyName * * @throws InvalidException */ diff --git a/src/Document.php b/src/Document.php index c615c65532..9306ba639a 100644 --- a/src/Document.php +++ b/src/Document.php @@ -58,7 +58,7 @@ public function __get(string $key) /** * @param mixed $value */ - public function __set(string $key, $value) + public function __set(string $key, $value): void { $this->set($key, $value); } @@ -68,7 +68,7 @@ public function __isset(string $key): bool return $this->has($key) && null !== $this->get($key); } - public function __unset(string $key) + public function __unset(string $key): void { $this->remove($key); } @@ -76,6 +76,8 @@ public function __unset(string $key) /** * Get the value of the given field. * + * @param mixed $key + * * @throws InvalidException If the given field does not exist * * @return mixed diff --git a/src/Exception/Bulk/Response/ActionException.php b/src/Exception/Bulk/Response/ActionException.php index d69fd08846..a7d57bc603 100644 --- a/src/Exception/Bulk/Response/ActionException.php +++ b/src/Exception/Bulk/Response/ActionException.php @@ -50,6 +50,6 @@ public function getErrorMessage(BulkResponse $response): string $path .= '/'.$data['_id']; } - return "$opType: $path caused $error"; + return "{$opType}: {$path} caused {$error}"; } } diff --git a/src/Exception/Bulk/ResponseException.php b/src/Exception/Bulk/ResponseException.php index 361e7348f2..7e6b304cc9 100644 --- a/src/Exception/Bulk/ResponseException.php +++ b/src/Exception/Bulk/ResponseException.php @@ -34,17 +34,6 @@ public function __construct(ResponseSet $responseSet) parent::__construct($message); } - protected function _init(ResponseSet $responseSet) - { - $this->_responseSet = $responseSet; - - foreach ($responseSet->getBulkResponses() as $bulkResponse) { - if ($bulkResponse->hasError()) { - $this->_actionExceptions[] = new ActionException($bulkResponse); - } - } - } - /** * Returns bulk response set object. */ @@ -86,4 +75,15 @@ public function getActionExceptionsAsString(): string return $message; } + + protected function _init(ResponseSet $responseSet): void + { + $this->_responseSet = $responseSet; + + foreach ($responseSet->getBulkResponses() as $bulkResponse) { + if ($bulkResponse->hasError()) { + $this->_actionExceptions[] = new ActionException($bulkResponse); + } + } + } } diff --git a/src/Exception/ElasticsearchException.php b/src/Exception/ElasticsearchException.php index 707d6bdf21..ddb06d15ee 100644 --- a/src/Exception/ElasticsearchException.php +++ b/src/Exception/ElasticsearchException.php @@ -13,6 +13,11 @@ class ElasticsearchException extends \Exception implements ExceptionInterface { public const REMOTE_TRANSPORT_EXCEPTION = 'RemoteTransportException'; + /** + * @var array Error array + */ + protected $_error = []; + /** * @var string|null Elasticsearch exception name */ @@ -23,11 +28,6 @@ class ElasticsearchException extends \Exception implements ExceptionInterface */ private $_isRemote = false; - /** - * @var array Error array - */ - protected $_error = []; - /** * Constructs elasticsearch exception. * @@ -40,12 +40,38 @@ public function __construct(int $code, string $error) parent::__construct($error, $code); } + /** + * Returns elasticsearch exception name. + * + * @return string|null + */ + public function getExceptionName() + { + return $this->_exception; + } + + /** + * Returns whether exception was local to server node or remote. + */ + public function isRemoteTransportException(): bool + { + return $this->_isRemote; + } + + /** + * @return array Error array + */ + public function getError(): array + { + return $this->_error; + } + /** * Parse error message from elasticsearch. * * @param string $error Error message */ - protected function _parseError(string $error) + protected function _parseError(string $error): void { $errors = \explode(']; nested: ', $error); @@ -74,30 +100,4 @@ protected function _extractException(string $error) return null; } - - /** - * Returns elasticsearch exception name. - * - * @return string|null - */ - public function getExceptionName() - { - return $this->_exception; - } - - /** - * Returns whether exception was local to server node or remote. - */ - public function isRemoteTransportException(): bool - { - return $this->_isRemote; - } - - /** - * @return array Error array - */ - public function getError(): array - { - return $this->_error; - } } diff --git a/src/Index.php b/src/Index.php index ad297a03cd..02df3fddf7 100644 --- a/src/Index.php +++ b/src/Index.php @@ -154,7 +154,7 @@ public function updateDocuments(array $docs, array $options = []): ResponseSet /** * Update entries in the db based on a query. * - * @param Query|string|array $query Query object or array + * @param array|Query|string $query Query object or array * @param AbstractScript $script Script * @param array $options Optional params * @@ -299,7 +299,7 @@ public function deleteById(string $id, array $options = []): Response /** * Deletes documents matching the given query. * - * @param Query|AbstractQuery|string|array $query Query object or array + * @param AbstractQuery|array|Query|string $query Query object or array * @param array $options Optional params * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html @@ -372,7 +372,7 @@ public function refresh(): Response * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html * * @param array $args Additional arguments to pass to the Create endpoint - * @param bool|array $options OPTIONAL + * @param array|bool $options OPTIONAL * bool=> Deletes index first if already exists (default = false). * array => Associative array of options (option=>value) * @@ -423,8 +423,8 @@ public function exists(): bool } /** - * @param string|array|Query $query - * @param int|array $options + * @param array|Query|string $query + * @param array|int $options * @param BuilderInterface $builder */ public function createSearch($query = '', $options = null, ?BuilderInterface $builder = null): Search @@ -439,8 +439,8 @@ public function createSearch($query = '', $options = null, ?BuilderInterface $bu /** * Searches in this index. * - * @param string|array|Query $query Array with all query data inside or a Elastica\Query object - * @param int|array $options Limit or associative array of options (option=>value) + * @param array|Query|string $query Array with all query data inside or a Elastica\Query object + * @param array|int $options Limit or associative array of options (option=>value) * @param string $method Request method, see Request's constants * * @see \Elastica\SearchableInterface::search @@ -455,7 +455,7 @@ public function search($query = '', $options = null, string $method = Request::P /** * Counts results of query. * - * @param string|array|Query $query Array with all query data inside or a Elastica\Query object + * @param array|Query|string $query Array with all query data inside or a Elastica\Query object * @param string $method Request method, see Request's constants * * @see \Elastica\SearchableInterface::count @@ -668,7 +668,7 @@ public function analyze(array $body, $args = []): array * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html * - * @param Document|AbstractScript $data Document or Script with update data + * @param AbstractScript|Document $data Document or Script with update data * @param array $options array of query params to use for query */ public function updateDocument($data, array $options = []): Response diff --git a/src/Index/Recovery.php b/src/Index/Recovery.php index c7ba52d919..e3afb33e60 100644 --- a/src/Index/Recovery.php +++ b/src/Index/Recovery.php @@ -77,18 +77,6 @@ public function getData(): array return $this->_data; } - /** - * @return mixed - */ - protected function getRecoveryData() - { - $endpoint = new RecoveryEndpoint(); - - $this->_response = $this->getIndex()->requestEndpoint($endpoint); - - return $this->getResponse()->getData(); - } - /** * Retrieve the Recovery data. * @@ -100,4 +88,16 @@ public function refresh(): self return $this; } + + /** + * @return mixed + */ + protected function getRecoveryData() + { + $endpoint = new RecoveryEndpoint(); + + $this->_response = $this->getIndex()->requestEndpoint($endpoint); + + return $this->getResponse()->getData(); + } } diff --git a/src/Index/Stats.php b/src/Index/Stats.php index a1e2157361..99fb7d519a 100644 --- a/src/Index/Stats.php +++ b/src/Index/Stats.php @@ -100,7 +100,7 @@ public function getResponse(): Response /** * Reloads all status data of this object. */ - public function refresh() + public function refresh(): void { $this->_response = $this->getIndex()->requestEndpoint(new \Elasticsearch\Endpoints\Indices\Stats()); $this->_data = $this->getResponse()->getData(); diff --git a/src/IndexTemplate.php b/src/IndexTemplate.php index f766ad1860..3025842cfd 100644 --- a/src/IndexTemplate.php +++ b/src/IndexTemplate.php @@ -52,9 +52,7 @@ public function __construct(Client $client, $name) */ public function delete() { - $response = $this->request(Request::DELETE); - - return $response; + return $this->request(Request::DELETE); } /** diff --git a/src/Multi/ResultSet.php b/src/Multi/ResultSet.php index c3af9502a0..b216430247 100644 --- a/src/Multi/ResultSet.php +++ b/src/Multi/ResultSet.php @@ -88,7 +88,7 @@ public function current() /** * {@inheritdoc} */ - public function next() + public function next(): void { ++$this->_position; } @@ -112,7 +112,7 @@ public function valid(): bool /** * {@inheritdoc} */ - public function rewind() + public function rewind(): void { $this->_position = 0; } @@ -144,7 +144,7 @@ public function offsetGet($offset) /** * {@inheritdoc} */ - public function offsetSet($offset, $value) + public function offsetSet($offset, $value): void { if (null === $offset) { $this->_resultSets[] = $value; @@ -156,7 +156,7 @@ public function offsetSet($offset, $value) /** * {@inheritdoc} */ - public function offsetUnset($offset) + public function offsetUnset($offset): void { unset($this->_resultSets[$offset]); } diff --git a/src/Multi/Search.php b/src/Multi/Search.php index 8a4b444776..851141eac7 100644 --- a/src/Multi/Search.php +++ b/src/Multi/Search.php @@ -16,6 +16,20 @@ */ class Search { + /** + * @var Client + */ + protected $_client; + + /** + * @var array + */ + protected $_options = []; + + /** + * @var BaseSearch[] + */ + protected $_searches = []; /** * @const string[] valid header options */ @@ -32,21 +46,6 @@ class Search */ private $_builder; - /** - * @var Client - */ - protected $_client; - - /** - * @var array - */ - protected $_options = []; - - /** - * @var BaseSearch[] - */ - protected $_searches = []; - /** * Constructs search object. */ @@ -139,7 +138,7 @@ public function search(): ResultSet Request::POST, $data, $this->_options, - Request::NDJSON_CONTENT_TYPE + Request::NDJSON_CONTENT_TYPE ); return $this->_builder->buildMultiResultSet($response, $this->getSearches()); diff --git a/src/Param.php b/src/Param.php index 5fd5450ce4..705d96ac60 100644 --- a/src/Param.php +++ b/src/Param.php @@ -45,55 +45,6 @@ public function toArray() return $this->_convertArrayable($data); } - /** - * Cast objects to arrays. - * - * @return array - */ - protected function _convertArrayable(array $array) - { - $arr = []; - - foreach ($array as $key => $value) { - if ($value instanceof ArrayableInterface) { - $arr[$value instanceof NameableInterface ? $value->getName() : $key] = $value->toArray(); - } elseif (\is_array($value)) { - $arr[$key] = $this->_convertArrayable($value); - } else { - $arr[$key] = $value; - } - } - - return $arr; - } - - /** - * Param's name - * Picks the last part of the class name and makes it snake_case - * You can override this method if you want to change the name. - * - * @return string name - */ - protected function _getBaseName() - { - return Util::getParamName($this); - } - - /** - * Sets params not inside params array. - * - * @param string $key - * @param mixed $value - * - * @return $this - */ - protected function _setRawParam($key, $value) - { - $this->_rawParams[$key] = $value; - - return $this; - } - /** * Sets (overwrites) the value at the given key. * @@ -189,4 +140,53 @@ public function count() { return \count($this->_params); } + + /** + * Cast objects to arrays. + * + * @return array + */ + protected function _convertArrayable(array $array) + { + $arr = []; + + foreach ($array as $key => $value) { + if ($value instanceof ArrayableInterface) { + $arr[$value instanceof NameableInterface ? $value->getName() : $key] = $value->toArray(); + } elseif (\is_array($value)) { + $arr[$key] = $this->_convertArrayable($value); + } else { + $arr[$key] = $value; + } + } + + return $arr; + } + + /** + * Param's name + * Picks the last part of the class name and makes it snake_case + * You can override this method if you want to change the name. + * + * @return string name + */ + protected function _getBaseName() + { + return Util::getParamName($this); + } + + /** + * Sets params not inside params array. + * + * @param string $key + * @param mixed $value + * + * @return $this + */ + protected function _setRawParam($key, $value) + { + $this->_rawParams[$key] = $value; + + return $this; + } } diff --git a/src/Processor/Append.php b/src/Processor/Append.php index 06ef8248f7..54f0c74ea5 100644 --- a/src/Processor/Append.php +++ b/src/Processor/Append.php @@ -15,7 +15,7 @@ class Append extends AbstractProcessor * Append constructor. * * @param string $field field name - * @param string|array $value field values to append + * @param array|string $value field values to append */ public function __construct(string $field, $value) { @@ -36,7 +36,7 @@ public function setField(string $field): self /** * Set field value. * - * @param string|array $value + * @param array|string $value * * @return $this */ diff --git a/src/Processor/Remove.php b/src/Processor/Remove.php index a6532684e2..600a60a6c9 100644 --- a/src/Processor/Remove.php +++ b/src/Processor/Remove.php @@ -14,7 +14,7 @@ class Remove extends AbstractProcessor /** * Remove constructor. * - * @param string|array $field + * @param array|string $field */ public function __construct($field) { @@ -24,7 +24,7 @@ public function __construct($field) /** * Set field. * - * @param string|array $field + * @param array|string $field * * @return $this */ diff --git a/src/Query.php b/src/Query.php index 0fd6b38871..947954d224 100644 --- a/src/Query.php +++ b/src/Query.php @@ -30,7 +30,7 @@ class Query extends Param /** * Creates a query object. * - * @param array|AbstractQuery $query Query object (default = null) + * @param AbstractQuery|array $query Query object (default = null) */ public function __construct($query = null) { @@ -95,8 +95,8 @@ public function setQuery(AbstractQuery $query): self /** * Gets the query object. * - * @return array|AbstractQuery - **/ + * @return AbstractQuery|array + */ public function getQuery() { return $this->getParam('query'); @@ -361,7 +361,7 @@ public function setSource($params): self /** * Sets a post_filter to the current query. * - * @param array|AbstractQuery $filter + * @param AbstractQuery|array $filter * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-body.html#request-body-search-post-filter */ diff --git a/src/Query/AbstractGeoDistance.php b/src/Query/AbstractGeoDistance.php index 1a07e2721c..371e217322 100644 --- a/src/Query/AbstractGeoDistance.php +++ b/src/Query/AbstractGeoDistance.php @@ -143,6 +143,16 @@ public function setGeohash(string $geohash): self return $this; } + /** + * {@inheritdoc} + */ + public function toArray(): array + { + $this->setParam($this->_key, $this->_getLocationData()); + + return parent::toArray(); + } + /** * @throws InvalidException * @@ -172,14 +182,4 @@ protected function _getLocationData() return $location; } - - /** - * {@inheritdoc} - */ - public function toArray(): array - { - $this->setParam($this->_key, $this->_getLocationData()); - - return parent::toArray(); - } } diff --git a/src/Query/BoolQuery.php b/src/Query/BoolQuery.php index 49223c9242..2c87f53abd 100644 --- a/src/Query/BoolQuery.php +++ b/src/Query/BoolQuery.php @@ -59,25 +59,6 @@ public function addFilter(AbstractQuery $filter): self return $this->addParam('filter', $filter); } - /** - * Adds a query to the current object. - * - * @param string $type Query type - * @param AbstractQuery|array $args Query - * - * @throws InvalidException If not valid query - * - * @return $this - */ - protected function _addQuery(string $type, $args): self - { - if (!\is_array($args) && !($args instanceof AbstractQuery)) { - throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Query\AbstractQuery'); - } - - return $this->addParam($type, $args); - } - /** * Sets boost value of this query. * @@ -113,4 +94,23 @@ public function toArray(): array return parent::toArray(); } + + /** + * Adds a query to the current object. + * + * @param string $type Query type + * @param AbstractQuery|array $args Query + * + * @throws InvalidException If not valid query + * + * @return $this + */ + protected function _addQuery(string $type, $args): self + { + if (!\is_array($args) && !($args instanceof AbstractQuery)) { + throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Query\AbstractQuery'); + } + + return $this->addParam($type, $args); + } } diff --git a/src/Query/DistanceFeature.php b/src/Query/DistanceFeature.php index 58c0631856..58d7b19dcf 100644 --- a/src/Query/DistanceFeature.php +++ b/src/Query/DistanceFeature.php @@ -22,7 +22,7 @@ public function setField(string $field): self } /** - * @param string|array $origin + * @param array|string $origin */ public function setOrigin($origin): self { diff --git a/src/Query/FunctionScore.php b/src/Query/FunctionScore.php index 6c13a317ed..5b4256fb9d 100644 --- a/src/Query/FunctionScore.php +++ b/src/Query/FunctionScore.php @@ -64,7 +64,7 @@ public function setQuery(AbstractQuery $query): self * Add a function to the function_score query. * * @param string $functionType valid values are DECAY_* constants and script_score - * @param array|float|AbstractScript $functionParams the body of the function. See documentation for proper syntax. + * @param AbstractScript|array|float $functionParams the body of the function. See documentation for proper syntax. * @param AbstractQuery $filter filter to apply to the function * @param float $weight function weight * diff --git a/src/Query/HasChild.php b/src/Query/HasChild.php index 026055d171..23b6c281bb 100644 --- a/src/Query/HasChild.php +++ b/src/Query/HasChild.php @@ -16,7 +16,7 @@ class HasChild extends AbstractQuery /** * Construct HasChild Query. * - * @param string|BaseQuery|AbstractQuery $query + * @param AbstractQuery|BaseQuery|string $query * @param string $type Parent document type */ public function __construct($query, ?string $type = null) @@ -28,7 +28,7 @@ public function __construct($query, ?string $type = null) /** * Sets query object. * - * @param string|BaseQuery|AbstractQuery $query + * @param AbstractQuery|BaseQuery|string $query * * @return $this */ diff --git a/src/Query/HasParent.php b/src/Query/HasParent.php index 0c7e69b9f0..ace01427d5 100644 --- a/src/Query/HasParent.php +++ b/src/Query/HasParent.php @@ -14,7 +14,7 @@ class HasParent extends AbstractQuery /** * Construct HasChild Query. * - * @param string|BaseQuery|AbstractQuery $query + * @param AbstractQuery|BaseQuery|string $query * @param string $type Parent document type */ public function __construct($query, string $type) @@ -26,7 +26,7 @@ public function __construct($query, string $type) /** * Sets query object. * - * @param string|BaseQuery|AbstractQuery $query + * @param AbstractQuery|BaseQuery|string $query * * @return $this */ diff --git a/src/Query/MoreLikeThis.php b/src/Query/MoreLikeThis.php index 189722f779..572de612eb 100644 --- a/src/Query/MoreLikeThis.php +++ b/src/Query/MoreLikeThis.php @@ -26,7 +26,7 @@ public function setFields(array $fields): self /** * Set the "like" value. * - * @param string|self $like + * @param self|string $like * * @return $this */ @@ -169,8 +169,8 @@ public function toArray(): array } elseif (!empty($array['more_like_this']['like']['_source'])) { $doc = $array['more_like_this']['like']; $doc['doc'] = $array['more_like_this']['like']['_source']; - unset($doc['_id']); - unset($doc['_source']); + unset($doc['_id'], $doc['_source']); + $array['more_like_this']['like'] = $doc; } diff --git a/src/Query/ParentId.php b/src/Query/ParentId.php index 151cc55bc5..098b77761d 100644 --- a/src/Query/ParentId.php +++ b/src/Query/ParentId.php @@ -23,17 +23,17 @@ public function __construct(string $type, string $id, bool $ignoreUnmapped = fal $this->setIgnoreUnmapped($ignoreUnmapped); } - private function setRelationshipType(string $type) + private function setRelationshipType(string $type): void { $this->setParam('type', $type); } - private function setId(string $id) + private function setId(string $id): void { $this->setParam('id', $id); } - private function setIgnoreUnmapped(bool $ignoreUnmapped = false) + private function setIgnoreUnmapped(bool $ignoreUnmapped = false): void { $this->setParam('ignore_unmapped', $ignoreUnmapped); } diff --git a/src/Query/Percolate.php b/src/Query/Percolate.php index 97818282e8..e04217cada 100644 --- a/src/Query/Percolate.php +++ b/src/Query/Percolate.php @@ -29,7 +29,7 @@ public function setField(string $field): self /** * The source of the document being percolated. * - * @param Document|array $document + * @param array|Document $document * * @return $this */ diff --git a/src/Query/Prefix.php b/src/Query/Prefix.php index 340571d1e6..a045fbdb93 100644 --- a/src/Query/Prefix.php +++ b/src/Query/Prefix.php @@ -36,7 +36,7 @@ public function setRawPrefix(array $prefix): self * Adds a prefix to the prefix query. * * @param string $key Key to query - * @param string|array $value Values(s) for the query. Boost can be set with array + * @param array|string $value Values(s) for the query. Boost can be set with array * @param float $boost OPTIONAL Boost value (default = 1.0) * * @return $this diff --git a/src/Query/Script.php b/src/Query/Script.php index 9b38c40ec2..2328e60be6 100644 --- a/src/Query/Script.php +++ b/src/Query/Script.php @@ -17,7 +17,7 @@ class Script extends AbstractQuery /** * Construct script query. * - * @param array|string|AbstractScript $script Script + * @param AbstractScript|array|string $script Script */ public function __construct($script = null) { @@ -29,7 +29,7 @@ public function __construct($script = null) /** * Sets script object. * - * @param BaseScript|string|array $script + * @param array|BaseScript|string $script * * @return $this */ diff --git a/src/Query/SpanTerm.php b/src/Query/SpanTerm.php index 7fea1dc6dd..8a6d95c306 100644 --- a/src/Query/SpanTerm.php +++ b/src/Query/SpanTerm.php @@ -39,7 +39,7 @@ public function setRawTerm(array $term): self * Adds a term to the term query. * * @param string $key Key to query - * @param string|array $value Values(s) for the query. Boost can be set with array + * @param array|string $value Values(s) for the query. Boost can be set with array * @param float $boost OPTIONAL Boost value (default = 1.0) * * @return $this diff --git a/src/Query/Term.php b/src/Query/Term.php index 4bd30703ee..df46dfc745 100644 --- a/src/Query/Term.php +++ b/src/Query/Term.php @@ -38,7 +38,7 @@ public function setRawTerm(array $term): self * Adds a term to the term query. * * @param string $key Key to query - * @param string|array $value Values(s) for the query. Boost can be set with array + * @param array|string $value Values(s) for the query. Boost can be set with array * @param float $boost OPTIONAL Boost value (default = 1.0) * * @return $this diff --git a/src/QueryBuilder.php b/src/QueryBuilder.php index 927d135b0a..c1d885da3e 100644 --- a/src/QueryBuilder.php +++ b/src/QueryBuilder.php @@ -54,7 +54,7 @@ public function __call(string $dsl, array $arguments): Facade /** * Adds a new DSL object. */ - public function addDSL(DSL $dsl) + public function addDSL(DSL $dsl): void { $this->_facades[$dsl->getType()] = new Facade($dsl, $this->_version); } diff --git a/src/QueryBuilder/DSL/Aggregation.php b/src/QueryBuilder/DSL/Aggregation.php index a3ba1b8882..dc5f92f886 100644 --- a/src/QueryBuilder/DSL/Aggregation.php +++ b/src/QueryBuilder/DSL/Aggregation.php @@ -176,7 +176,7 @@ public function cardinality(string $name): Cardinality * * @param string $name */ - public function geo_bounds($name) + public function geo_bounds($name): void { throw new NotImplementedException(); } @@ -358,7 +358,7 @@ public function date_histogram(string $name, string $field, $interval): DateHist * * @param string $name the name if this aggregation * @param string $field the field on which to perform this aggregation - * @param string|array $origin the point from which distances will be calculated + * @param array|string $origin the point from which distances will be calculated */ public function geo_distance(string $name, string $field, $origin): GeoDistance { diff --git a/src/QueryBuilder/DSL/Query.php b/src/QueryBuilder/DSL/Query.php index 6cc8a6fff1..a4f72ca7ed 100644 --- a/src/QueryBuilder/DSL/Query.php +++ b/src/QueryBuilder/DSL/Query.php @@ -144,7 +144,7 @@ public function dis_max(): DisMax * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-distance-feature-query.html * - * @param string|array $origin + * @param array|string $origin */ public function distance_feature(string $field, $origin, string $pivot): DistanceFeature { @@ -210,7 +210,7 @@ public function geo_polygon(string $key, array $points): GeoPolygon * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-child-query.html * - * @param string|BaseQuery|AbstractQuery $query + * @param AbstractQuery|BaseQuery|string $query * @param string $type Parent document type */ public function has_child($query, ?string $type = null): HasChild @@ -223,7 +223,7 @@ public function has_child($query, ?string $type = null): HasChild * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-parent-query.html * - * @param string|BaseQuery|AbstractQuery $query + * @param AbstractQuery|BaseQuery|string $query * @param string $type Parent document type */ public function has_parent($query, string $type): HasParent @@ -265,6 +265,8 @@ public function match_none(): MatchNone * match phrase query. * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase.html + * + * @param mixed|null $values */ public function match_phrase(?string $field = null, $values = null): MatchPhrase { @@ -275,6 +277,8 @@ public function match_phrase(?string $field = null, $values = null): MatchPhrase * match phrase prefix query. * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query-phrase-prefix.html + * + * @param mixed|null $values */ public function match_phrase_prefix(?string $field = null, $values = null): MatchPhrasePrefix { diff --git a/src/QueryBuilder/Facade.php b/src/QueryBuilder/Facade.php index 7ba37fde86..0a28cb83e4 100644 --- a/src/QueryBuilder/Facade.php +++ b/src/QueryBuilder/Facade.php @@ -8,7 +8,7 @@ * Facade for a specific DSL object. * * @author Manuel Andreo Garcia - **/ + */ class Facade { /** diff --git a/src/Reindex.php b/src/Reindex.php index 17d5e7bc09..9a901f8502 100644 --- a/src/Reindex.php +++ b/src/Reindex.php @@ -73,6 +73,68 @@ public function run(): Response return $this->_lastResponse; } + public function setWaitForCompletion($value): void + { + \is_bool($value) && $value = $value ? 'true' : 'false'; + + $this->setParam(self::WAIT_FOR_COMPLETION, $value); + } + + public function setWaitForActiveShards($value): void + { + $this->setParam(self::WAIT_FOR_ACTIVE_SHARDS, $value); + } + + public function setTimeout($value): void + { + $this->setParam(self::TIMEOUT, $value); + } + + public function setScroll($value): void + { + $this->setParam(self::SCROLL, $value); + } + + public function setRequestsPerSecond($value): void + { + $this->setParam(self::REQUESTS_PER_SECOND, $value); + } + + public function setScript(Script $script): void + { + $this->setParam(self::SCRIPT, $script); + } + + public function setQuery(AbstractQuery $query): void + { + $this->setParam(self::QUERY, $query); + } + + public function setPipeline(Pipeline $pipeline): void + { + $this->setParam(self::PIPELINE, $pipeline); + } + + /** + * @param bool|string $value + */ + public function setRefresh($value): void + { + \is_bool($value) && $value = $value ? self::REFRESH_TRUE : self::REFRESH_FALSE; + + $this->setParam(self::REFRESH, $value); + } + + public function getTaskId() + { + $taskId = null; + if ($this->_lastResponse instanceof Response) { + $taskId = $this->_lastResponse->getData()['task'] ? $this->_lastResponse->getData()['task'] : null; + } + + return $taskId; + } + protected function _getBody(Index $oldIndex, Index $newIndex, array $params): array { $body = \array_merge([ @@ -80,9 +142,7 @@ protected function _getBody(Index $oldIndex, Index $newIndex, array $params): ar 'dest' => $this->_getDestPartBody($newIndex, $params), ], $this->_resolveBodyOptions($params)); - $body = $this->_setBodyScript($body); - - return $body; + return $this->_setBodyScript($body); } protected function _getSourcePartBody(Index $index, array $params): array @@ -91,9 +151,7 @@ protected function _getSourcePartBody(Index $index, array $params): array 'index' => $index->getName(), ], $this->_resolveSourceOptions($params)); - $sourceBody = $this->_setSourceQuery($sourceBody); - - return $sourceBody; + return $this->_setSourceQuery($sourceBody); } protected function _getDestPartBody(Index $index, array $params): array @@ -164,66 +222,4 @@ private function _setBodyScript(array $body): array return $body; } - - public function setWaitForCompletion($value) - { - \is_bool($value) && $value = $value ? 'true' : 'false'; - - $this->setParam(self::WAIT_FOR_COMPLETION, $value); - } - - public function setWaitForActiveShards($value) - { - $this->setParam(self::WAIT_FOR_ACTIVE_SHARDS, $value); - } - - public function setTimeout($value) - { - $this->setParam(self::TIMEOUT, $value); - } - - public function setScroll($value) - { - $this->setParam(self::SCROLL, $value); - } - - public function setRequestsPerSecond($value) - { - $this->setParam(self::REQUESTS_PER_SECOND, $value); - } - - public function setScript(Script $script) - { - $this->setParam(self::SCRIPT, $script); - } - - public function setQuery(AbstractQuery $query): void - { - $this->setParam(self::QUERY, $query); - } - - public function setPipeline(Pipeline $pipeline): void - { - $this->setParam(self::PIPELINE, $pipeline); - } - - /** - * @param bool|string $value - */ - public function setRefresh($value): void - { - \is_bool($value) && $value = $value ? self::REFRESH_TRUE : self::REFRESH_FALSE; - - $this->setParam(self::REFRESH, $value); - } - - public function getTaskId() - { - $taskId = null; - if ($this->_lastResponse instanceof Response) { - $taskId = $this->_lastResponse->getData()['task'] ? $this->_lastResponse->getData()['task'] : null; - } - - return $taskId; - } } diff --git a/src/Request.php b/src/Request.php index 8b81b21e6b..1577b9cc20 100644 --- a/src/Request.php +++ b/src/Request.php @@ -46,6 +46,14 @@ public function __construct(string $path, string $method = self::GET, $data = [] $this->setContentType($contentType); } + /** + * @return string + */ + public function __toString() + { + return $this->toString(); + } + /** * Sets the request method. Use one of the for consts. * @@ -195,12 +203,4 @@ public function toString() { return JSON::stringify($this->toArray()); } - - /** - * @return string - */ - public function __toString() - { - return $this->toString(); - } } diff --git a/src/Rescore/AbstractRescore.php b/src/Rescore/AbstractRescore.php index a753351f9b..5d6e8dd4b1 100644 --- a/src/Rescore/AbstractRescore.php +++ b/src/Rescore/AbstractRescore.php @@ -14,22 +14,22 @@ abstract class AbstractRescore extends Param { /** - * Overridden to return rescore as name. + * Sets window_size. * - * @return string name + * @return $this */ - protected function _getBaseName(): string + public function setWindowSize(int $size): AbstractRescore { - return 'rescore'; + return $this->setParam('window_size', $size); } /** - * Sets window_size. + * Overridden to return rescore as name. * - * @return $this + * @return string name */ - public function setWindowSize(int $size): AbstractRescore + protected function _getBaseName(): string { - return $this->setParam('window_size', $size); + return 'rescore'; } } diff --git a/src/Rescore/Query.php b/src/Rescore/Query.php index 8f2c9fc53d..4e50d9eb6a 100644 --- a/src/Rescore/Query.php +++ b/src/Rescore/Query.php @@ -16,7 +16,7 @@ class Query extends AbstractRescore /** * Constructor. * - * @param string|\Elastica\Query\AbstractQuery $query + * @param \Elastica\Query\AbstractQuery|string $query */ public function __construct($query = null) { @@ -50,7 +50,7 @@ public function toArray(): array /** * Sets rescoreQuery object. * - * @param string|\Elastica\Query|\Elastica\Query\AbstractQuery $rescoreQuery + * @param \Elastica\Query|\Elastica\Query\AbstractQuery|string $rescoreQuery * * @return $this */ diff --git a/src/Response.php b/src/Response.php index 487e83cb39..baeb3f0375 100644 --- a/src/Response.php +++ b/src/Response.php @@ -59,7 +59,7 @@ class Response /** * Construct. * - * @param string|array $responseString Response string (json) + * @param array|string $responseString Response string (json) * @param int $responseStatus http status code */ public function __construct($responseString, $responseStatus = null) @@ -349,7 +349,7 @@ public function getScrollId() * * @param bool $jsonBigintConversion */ - public function setJsonBigintConversion($jsonBigintConversion) + public function setJsonBigintConversion($jsonBigintConversion): void { $this->_jsonBigintConversion = $jsonBigintConversion; } diff --git a/src/Result.php b/src/Result.php index fca02e691a..1d023475dc 100644 --- a/src/Result.php +++ b/src/Result.php @@ -28,6 +28,34 @@ public function __construct(array $hit) $this->_hit = $hit; } + /** + * Magic function to directly access keys inside the result. + * + * Returns null if key does not exist + * + * @param string $key Key name + * + * @return mixed Key value + */ + public function __get($key) + { + $source = $this->getData(); + + return $source[$key] ?? null; + } + + /** + * Magic function to support isset() calls. + * + * @param string $key Key name + */ + public function __isset($key): bool + { + $source = $this->getData(); + + return \array_key_exists($key, $source) && null !== $source[$key]; + } + /** * Returns a param from the result hit array. * @@ -125,7 +153,7 @@ public function getHit(): array /** * Returns the version information from the hit. * - * @return string|int Document version + * @return int|string Document version */ public function getVersion() { @@ -198,10 +226,8 @@ public function getDocument(): Document $doc = new Document(); $doc->setData($this->getSource()); $hit = $this->getHit(); - unset($hit['_source']); - unset($hit['_explanation']); - unset($hit['highlight']); - unset($hit['_score']); + unset($hit['_source'], $hit['_explanation'], $hit['highlight'], $hit['_score']); + $doc->setParams($hit); return $doc; @@ -212,36 +238,8 @@ public function getDocument(): Document * * @param mixed $value */ - public function setParam(string $param, $value) + public function setParam(string $param, $value): void { $this->_hit[$param] = $value; } - - /** - * Magic function to directly access keys inside the result. - * - * Returns null if key does not exist - * - * @param string $key Key name - * - * @return mixed Key value - */ - public function __get($key) - { - $source = $this->getData(); - - return $source[$key] ?? null; - } - - /** - * Magic function to support isset() calls. - * - * @param string $key Key name - */ - public function __isset($key): bool - { - $source = $this->getData(); - - return \array_key_exists($key, $source) && null !== $source[$key]; - } } diff --git a/src/ResultSet/ChainProcessor.php b/src/ResultSet/ChainProcessor.php index 7fbec9dd2e..723adf6884 100644 --- a/src/ResultSet/ChainProcessor.php +++ b/src/ResultSet/ChainProcessor.php @@ -26,7 +26,7 @@ public function __construct(array $processors) /** * {@inheritdoc} */ - public function process(ResultSet $resultSet) + public function process(ResultSet $resultSet): void { foreach ($this->processors as $processor) { $processor->process($resultSet); diff --git a/src/ResultSet/DefaultBuilder.php b/src/ResultSet/DefaultBuilder.php index 3dfcdba03f..7dc8f9a3e0 100644 --- a/src/ResultSet/DefaultBuilder.php +++ b/src/ResultSet/DefaultBuilder.php @@ -15,9 +15,8 @@ class DefaultBuilder implements BuilderInterface public function buildResultSet(Response $response, Query $query): ResultSet { $results = $this->buildResults($response); - $resultSet = new ResultSet($response, $query, $results); - return $resultSet; + return new ResultSet($response, $query, $results); } /** diff --git a/src/Script/AbstractScript.php b/src/Script/AbstractScript.php index fbe6f7a61b..2025e8f6b2 100644 --- a/src/Script/AbstractScript.php +++ b/src/Script/AbstractScript.php @@ -27,10 +27,29 @@ abstract class AbstractScript extends AbstractUpdateAction */ private $_lang; + /** + * @param string|null $lang Script language, see constants + * @param string|null $documentId Document ID the script action should be performed on (only relevant in update context) + */ + public function __construct(?array $params = null, ?string $lang = null, ?string $documentId = null) + { + if ($params) { + $this->setParams($params); + } + + if (null !== $lang) { + $this->setLang($lang); + } + + if (null !== $documentId) { + $this->setId($documentId); + } + } + /** * Factory to create a script object from data structure (reverse toArray). * - * @param string|array|AbstractScript $data + * @param AbstractScript|array|string $data * * @throws InvalidException * @@ -55,53 +74,6 @@ public static function create($data) throw new InvalidException('Failed to create script. Invalid data passed.'); } - private static function _createFromArray(array $data) - { - $params = $data['script']['params'] ?? []; - $lang = $data['script']['lang'] ?? null; - - if (!\is_array($params)) { - throw new InvalidException('Script params must be an array'); - } - - if (isset($data['script']['source'])) { - return new Script( - $data['script']['source'], - $params, - $lang - ); - } - - if (isset($data['script']['id'])) { - return new ScriptId( - $data['script']['id'], - $params, - $lang - ); - } - - throw new InvalidException('Failed to create script. Invalid data passed.'); - } - - /** - * @param string|null $lang Script language, see constants - * @param string|null $documentId Document ID the script action should be performed on (only relevant in update context) - */ - public function __construct(?array $params = null, ?string $lang = null, ?string $documentId = null) - { - if ($params) { - $this->setParams($params); - } - - if (null !== $lang) { - $this->setLang($lang); - } - - if (null !== $documentId) { - $this->setId($documentId); - } - } - public function setLang(string $lang): self { $this->_lang = $lang; @@ -114,11 +86,6 @@ public function getLang(): ?string return $this->_lang; } - /** - * Returns an array with the script type as key and the script content as value. - */ - abstract protected function getScriptTypeArray(): array; - /** * {@inheritdoc} */ @@ -136,4 +103,37 @@ public function toArray(): array return ['script' => $array]; } + + /** + * Returns an array with the script type as key and the script content as value. + */ + abstract protected function getScriptTypeArray(): array; + + private static function _createFromArray(array $data) + { + $params = $data['script']['params'] ?? []; + $lang = $data['script']['lang'] ?? null; + + if (!\is_array($params)) { + throw new InvalidException('Script params must be an array'); + } + + if (isset($data['script']['source'])) { + return new Script( + $data['script']['source'], + $params, + $lang + ); + } + + if (isset($data['script']['id'])) { + return new ScriptId( + $data['script']['id'], + $params, + $lang + ); + } + + throw new InvalidException('Failed to create script. Invalid data passed.'); + } } diff --git a/src/Script/ScriptFields.php b/src/Script/ScriptFields.php index 9664daeec0..9dc9fb68d6 100644 --- a/src/Script/ScriptFields.php +++ b/src/Script/ScriptFields.php @@ -15,7 +15,7 @@ class ScriptFields extends Param { /** - * @param Script[]|array $scripts OPTIONAL + * @param array|Script[] $scripts OPTIONAL */ public function __construct(array $scripts = []) { @@ -42,7 +42,7 @@ public function addScript(string $name, AbstractScript $script): self } /** - * @param Script[]|array $scripts Associative array of string => Elastica\Script\Script + * @param array|Script[] $scripts Associative array of string => Elastica\Script\Script * * @return $this */ diff --git a/src/Scroll.php b/src/Scroll.php index d06a6d4809..c65c25d2b9 100644 --- a/src/Scroll.php +++ b/src/Scroll.php @@ -133,7 +133,7 @@ public function rewind(): void /** * Cleares the search context on ES and marks this Scroll instance as finished. */ - public function clear() + public function clear(): void { if (null !== $this->_nextScrollId) { $this->_search->getClient()->request( @@ -150,7 +150,7 @@ public function clear() /** * Prepares Scroll for next request. */ - protected function _setScrollId(ResultSet $resultSet) + protected function _setScrollId(ResultSet $resultSet): void { if (0 === $this->currentPage) { $this->totalPages = $resultSet->count() > 0 ? \ceil($resultSet->getTotalHits() / $resultSet->count()) : 0; @@ -170,7 +170,7 @@ protected function _setScrollId(ResultSet $resultSet) /** * Save all search options manipulated by Scroll. */ - protected function _saveOptions() + protected function _saveOptions(): void { if ($this->_search->hasOption(Search::OPTION_SCROLL)) { $this->_options[0] = $this->_search->getOption(Search::OPTION_SCROLL); @@ -196,7 +196,7 @@ protected function _saveOptions() /** * Revert search options to previously saved state. */ - protected function _revertOptions() + protected function _revertOptions(): void { $this->_search->setOption(Search::OPTION_SCROLL, $this->_options[0]); $this->_search->setOption(Search::OPTION_SCROLL_ID, $this->_options[1]); diff --git a/src/Search.php b/src/Search.php index b74e8923c3..ae0372663a 100644 --- a/src/Search.php +++ b/src/Search.php @@ -39,11 +39,6 @@ class Search public const OPTION_SEARCH_TYPE_SUGGEST = 'suggest'; public const OPTION_SEARCH_IGNORE_UNAVAILABLE = 'ignore_unavailable'; - /** - * @var BuilderInterface|null - */ - private $builder; - /** * Array of indices names. * @@ -68,6 +63,11 @@ class Search */ protected $_client; + /** + * @var BuilderInterface|null + */ + private $builder; + /** * Constructs search object. */ @@ -114,7 +114,7 @@ public function addIndices(array $indices = []): self } /** - * @param string|array|Query|Suggest|Query\AbstractQuery $query + * @param array|Query|Query\AbstractQuery|string|Suggest $query */ public function setQuery($query): self { @@ -189,34 +189,6 @@ public function getOptions(): array return $this->_options; } - /** - * @throws InvalidException If the given key is not a valid option - */ - protected function validateOption(string $key): void - { - switch ($key) { - case self::OPTION_SEARCH_TYPE: - case self::OPTION_ROUTING: - case self::OPTION_PREFERENCE: - case self::OPTION_VERSION: - case self::OPTION_TIMEOUT: - case self::OPTION_FROM: - case self::OPTION_SIZE: - case self::OPTION_SCROLL: - case self::OPTION_SCROLL_ID: - case self::OPTION_SEARCH_TYPE_SUGGEST: - case self::OPTION_SEARCH_IGNORE_UNAVAILABLE: - case self::OPTION_QUERY_CACHE: - case self::OPTION_TERMINATE_AFTER: - case self::OPTION_SHARD_REQUEST_CACHE: - case self::OPTION_FILTER_PATH: - case self::OPTION_TYPED_KEYS: - return; - } - - throw new InvalidException('Invalid option '.$key); - } - /** * Return client object. */ @@ -284,8 +256,8 @@ public function getPath(): string /** * Search in the set indices. * - * @param string|array|Query $query - * @param int|array $options Limit or associative array of options (option=>value) + * @param array|Query|string $query + * @param array|int $options Limit or associative array of options (option=>value) * * @throws InvalidException */ @@ -312,7 +284,7 @@ public function search($query = '', $options = null, string $method = Request::P } /** - * @param string|array|Query $query + * @param array|Query|string $query * @param bool $fullResult By default only the total hit count is returned. If set to true, the full ResultSet including aggregations is returned * * @return int|ResultSet @@ -341,7 +313,7 @@ public function count($query = '', bool $fullResult = false, string $method = Re /** * @param array|int $options - * @param string|array|Query $query + * @param array|Query|string $query */ public function setOptionsAndQuery($options = null, $query = ''): self { @@ -385,4 +357,32 @@ public function getResultSetBuilder(): BuilderInterface { return $this->builder; } + + /** + * @throws InvalidException If the given key is not a valid option + */ + protected function validateOption(string $key): void + { + switch ($key) { + case self::OPTION_SEARCH_TYPE: + case self::OPTION_ROUTING: + case self::OPTION_PREFERENCE: + case self::OPTION_VERSION: + case self::OPTION_TIMEOUT: + case self::OPTION_FROM: + case self::OPTION_SIZE: + case self::OPTION_SCROLL: + case self::OPTION_SCROLL_ID: + case self::OPTION_SEARCH_TYPE_SUGGEST: + case self::OPTION_SEARCH_IGNORE_UNAVAILABLE: + case self::OPTION_QUERY_CACHE: + case self::OPTION_TERMINATE_AFTER: + case self::OPTION_SHARD_REQUEST_CACHE: + case self::OPTION_FILTER_PATH: + case self::OPTION_TYPED_KEYS: + return; + } + + throw new InvalidException('Invalid option '.$key); + } } diff --git a/src/SearchableInterface.php b/src/SearchableInterface.php index 7dcacb870a..8494ecdca5 100644 --- a/src/SearchableInterface.php +++ b/src/SearchableInterface.php @@ -25,8 +25,8 @@ interface SearchableInterface * } * } * - * @param string|array|\Elastica\Query $query Array with all query data inside or a Elastica\Query object - * @param int|array $options Limit or associative array of options (option=>value) + * @param array|\Elastica\Query|string $query Array with all query data inside or a Elastica\Query object + * @param array|int $options Limit or associative array of options (option=>value) * @param string $method Request method, see Request's constants */ public function search($query = '', $options = null, string $method = Request::POST): ResultSet; @@ -36,7 +36,7 @@ public function search($query = '', $options = null, string $method = Request::P * * If no query is set, matchall query is created * - * @param string|array|\Elastica\Query $query Array with all query data inside or a Elastica\Query object + * @param array|\Elastica\Query|string $query Array with all query data inside or a Elastica\Query object * @param string $method Request method, see Request's constants * * @return int number of documents matching the query @@ -45,6 +45,7 @@ public function count($query = '', string $method = Request::POST); /** * @param \Elastica\Query|string $query + * @param mixed|null $options */ public function createSearch($query = '', $options = null): Search; } diff --git a/src/Status.php b/src/Status.php index 5544b6267b..2459bed784 100644 --- a/src/Status.php +++ b/src/Status.php @@ -53,7 +53,7 @@ public function __construct(Client $client) */ public function getData() { - if (\is_null($this->_data)) { + if (null === $this->_data) { $this->refresh(); } @@ -135,7 +135,7 @@ public function getIndicesWithAlias($alias) */ public function getResponse() { - if (\is_null($this->_response)) { + if (null === $this->_response) { $this->refresh(); } @@ -157,7 +157,7 @@ public function getShards() /** * Refresh status object. */ - public function refresh() + public function refresh(): void { $this->_response = $this->_client->requestEndpoint(new Stats()); $this->_data = $this->getResponse()->getData(); diff --git a/src/Suggest.php b/src/Suggest.php index e10bc664cf..d7576b60f7 100644 --- a/src/Suggest.php +++ b/src/Suggest.php @@ -39,7 +39,7 @@ public function addSuggestion(AbstractSuggest $suggestion): self } /** - * @param Suggest|AbstractSuggest $suggestion + * @param AbstractSuggest|Suggest $suggestion * * @throws Exception\NotImplementedException */ diff --git a/src/Suggest/Term.php b/src/Suggest/Term.php index 7aa27362cc..0d4b6763d6 100644 --- a/src/Suggest/Term.php +++ b/src/Suggest/Term.php @@ -103,7 +103,7 @@ public function setMaxInspections(int $max = 5): Term /** * Set the minimum number of documents in which a suggestion should appear. * - * @param int|float $min Defaults to 0. If the value is greater than 1, it must be a whole number. + * @param float|int $min Defaults to 0. If the value is greater than 1, it must be a whole number. * * @return $this */ diff --git a/src/Task.php b/src/Task.php index a4cd2d2b23..3899847bc5 100644 --- a/src/Task.php +++ b/src/Task.php @@ -64,7 +64,7 @@ public function getId() */ public function getData(): array { - if (\is_null($this->_data)) { + if (null === $this->_data) { $this->refresh(); } @@ -78,7 +78,7 @@ public function getData(): array */ public function getResponse(): Response { - if (\is_null($this->_response)) { + if (null === $this->_response) { $this->refresh(); } @@ -90,7 +90,7 @@ public function getResponse(): Response * * @param array $options Options for endpoint */ - public function refresh(array $options = []) + public function refresh(array $options = []): void { $endpoint = new \Elasticsearch\Endpoints\Tasks\Get(); $endpoint->setTaskId($this->_id); diff --git a/src/Transport/AbstractTransport.php b/src/Transport/AbstractTransport.php index f25ffc4d34..cb6b63199a 100644 --- a/src/Transport/AbstractTransport.php +++ b/src/Transport/AbstractTransport.php @@ -107,7 +107,7 @@ public static function create($transport, Connection $connection, array $params } else { $transport = \ucfirst($transport); } - $classNames = ["Elastica\\Transport\\$transport", $transport]; + $classNames = ["Elastica\\Transport\\{$transport}", $transport]; foreach ($classNames as $className) { if (\class_exists($className)) { $transport = new $className(); diff --git a/src/Transport/AwsAuthV4.php b/src/Transport/AwsAuthV4.php index 184ca54aca..b070a361c6 100755 --- a/src/Transport/AwsAuthV4.php +++ b/src/Transport/AwsAuthV4.php @@ -72,7 +72,7 @@ private function getCredentialProvider(): callable return CredentialProvider::defaultProvider(); } - private function initializePortAndScheme() + private function initializePortAndScheme(): void { $connection = $this->getConnection(); if (true === $this->isSslRequired($connection)) { diff --git a/src/Transport/Guzzle.php b/src/Transport/Guzzle.php index 327c161765..4b2c394a25 100755 --- a/src/Transport/Guzzle.php +++ b/src/Transport/Guzzle.php @@ -69,11 +69,11 @@ public function exec(Request $request, array $params): Response $proxy = $connection->getProxy(); // See: https://github.com/facebook/hhvm/issues/4875 - if (\is_null($proxy) && \defined('HHVM_VERSION')) { + if (null === $proxy && \defined('HHVM_VERSION')) { $proxy = \getenv('http_proxy') ?: null; } - if (!\is_null($proxy)) { + if (null !== $proxy) { $options['proxy'] = $proxy; } @@ -137,7 +137,8 @@ protected function _createPsr7Request(Request $request, Connection $connection) } $req = $req->withBody( - Psr7\stream_for(\is_array($data) + Psr7\stream_for( + \is_array($data) ? JSON::stringify($data, JSON_UNESCAPED_UNICODE) : $data ) @@ -202,7 +203,7 @@ protected function _getActionPath(Request $request): string if (!empty($query)) { $action .= '?'.\http_build_query( $this->sanityzeQueryStringBool($query) - ); + ); } return $action; diff --git a/src/Transport/Http.php b/src/Transport/Http.php index 126d99c334..32f2f58208 100644 --- a/src/Transport/Http.php +++ b/src/Transport/Http.php @@ -72,7 +72,7 @@ public function exec(Request $request, array $params): Response if (!empty($query)) { $baseUri .= '?'.\http_build_query( $this->sanityzeQueryStringBool($query) - ); + ); } \curl_setopt($conn, CURLOPT_URL, $baseUri); @@ -93,19 +93,19 @@ public function exec(Request $request, array $params): Response $proxy = $connection->getProxy(); // See: https://github.com/facebook/hhvm/issues/4875 - if (\is_null($proxy) && \defined('HHVM_VERSION')) { + if (null === $proxy && \defined('HHVM_VERSION')) { $proxy = \getenv('http_proxy') ?: null; } - if (!\is_null($proxy)) { + if (null !== $proxy) { \curl_setopt($conn, CURLOPT_PROXY, $proxy); } $username = $connection->getUsername(); $password = $connection->getPassword(); - if (!\is_null($username) && !\is_null($password)) { + if (null !== $username && null !== $password) { \curl_setopt($conn, CURLOPT_HTTPAUTH, CURLAUTH_ANY); - \curl_setopt($conn, CURLOPT_USERPWD, "$username:$password"); + \curl_setopt($conn, CURLOPT_USERPWD, "{$username}:{$password}"); } $this->_setupCurl($conn); @@ -198,7 +198,7 @@ public function exec(Request $request, array $params): Response * * @param resource $curlConnection Curl connection */ - protected function _setupCurl($curlConnection) + protected function _setupCurl($curlConnection): void { if ($this->getConnection()->hasConfig('curl')) { foreach ($this->getConnection()->getConfig('curl') as $key => $param) { diff --git a/src/Transport/Https.php b/src/Transport/Https.php index 996bb2153b..54b2397406 100644 --- a/src/Transport/Https.php +++ b/src/Transport/Https.php @@ -21,7 +21,7 @@ class Https extends Http * * @param resource $connection Curl connection resource */ - protected function _setupCurl($connection) + protected function _setupCurl($connection): void { parent::_setupCurl($connection); } diff --git a/src/Transport/NullTransport.php b/src/Transport/NullTransport.php index ca8b35d5d1..1e231b2095 100644 --- a/src/Transport/NullTransport.php +++ b/src/Transport/NullTransport.php @@ -22,7 +22,7 @@ class NullTransport extends AbstractTransport * * @var Response Response */ - protected $_response = null; + protected $_response; /** * Set response object the transport returns. diff --git a/src/Util.php b/src/Util.php index 5c9c8dcc94..5e3f68ed82 100644 --- a/src/Util.php +++ b/src/Util.php @@ -88,9 +88,8 @@ public static function replaceBooleanWordsAndEscapeTerm($term) { $result = $term; $result = self::replaceBooleanWords($result); - $result = self::escapeTerm($result); - return $result; + return self::escapeTerm($result); } /** @@ -137,9 +136,8 @@ public static function escapeTerm($term) public static function replaceBooleanWords($term) { $replacementMap = [' AND ' => ' && ', ' OR ' => ' || ', ' NOT ' => ' !']; - $result = \strtr($term, $replacementMap); - return $result; + return \strtr($term, $replacementMap); } /** @@ -188,9 +186,8 @@ public static function convertDate($date) } else { $timestamp = \strtotime($date); } - $string = \date('Y-m-d\TH:i:s\Z', $timestamp); - return $string; + return \date('Y-m-d\TH:i:s\Z', $timestamp); } /** @@ -203,16 +200,16 @@ public static function convertDate($date) public static function convertDateTimeObject(\DateTime $dateTime, bool $includeTimezone = true) { $formatString = 'Y-m-d\TH:i:s'.(true === $includeTimezone ? 'P' : '\Z'); - $string = $dateTime->format($formatString); - return $string; + return $dateTime->format($formatString); } /** * Tries to guess the name of the param, based on its class * Example: \Elastica\Query\MatchAll => match_all. * - * @param string|object Object or class name + * @param object|string Object or class name + * @param mixed $class * * @return string parameter name */ diff --git a/tests/Aggregation/AbstractSimpleAggregationTest.php b/tests/Aggregation/AbstractSimpleAggregationTest.php index 329a1dcd93..17e7adebaf 100644 --- a/tests/Aggregation/AbstractSimpleAggregationTest.php +++ b/tests/Aggregation/AbstractSimpleAggregationTest.php @@ -5,9 +5,12 @@ use Elastica\Aggregation\AbstractSimpleAggregation; use Elastica\Exception\InvalidException; +/** + * @internal + */ class AbstractSimpleAggregationTest extends BaseAggregationTest { - protected function setUp() + protected function setUp(): void { $this->aggregation = $this->getMockForAbstractClass( AbstractSimpleAggregation::class, @@ -15,7 +18,7 @@ protected function setUp() ); } - public function testToArrayThrowsExceptionOnUnsetParams() + public function testToArrayThrowsExceptionOnUnsetParams(): void { $this->expectException(InvalidException::class); $this->expectExceptionMessage('Either the field param or the script param should be set'); diff --git a/tests/Aggregation/AdjacencyMatrixTest.php b/tests/Aggregation/AdjacencyMatrixTest.php index 3fe9467449..d0eabc9fc6 100644 --- a/tests/Aggregation/AdjacencyMatrixTest.php +++ b/tests/Aggregation/AdjacencyMatrixTest.php @@ -10,26 +10,15 @@ use Elastica\Query\Term; use Elastica\Query\Terms; +/** + * @internal + */ class AdjacencyMatrixTest extends BaseAggregationTest { - protected function _getIndexForTest(): Index - { - $index = $this->_createIndex(); - $index->addDocuments([ - new Document(1, ['accounts' => ['hillary', 'sidney']]), - new Document(2, ['accounts' => ['hillary', 'donald']]), - new Document(3, ['accounts' => ['vladimir', 'donald']]), - ]); - - $index->refresh(); - - return $index; - } - /** * @group unit */ - public function testToArray() + public function testToArray(): void { $expected = [ 'adjacency_matrix' => [ @@ -70,7 +59,7 @@ public function testToArray() /** * @group unit */ - public function testToArraySeparator() + public function testToArraySeparator(): void { $expected = [ 'adjacency_matrix' => [ @@ -95,7 +84,7 @@ public function testToArraySeparator() /** * @group functional */ - public function testAdjacencyMatrixAggregation() + public function testAdjacencyMatrixAggregation(): void { $agg = new AdjacencyMatrix('interactions'); $agg->addFilter(new Terms('accounts', ['hillary', 'sidney']), 'grpA'); @@ -134,4 +123,18 @@ public function testAdjacencyMatrixAggregation() $this->assertEquals($expected, $results['buckets']); } + + protected function _getIndexForTest(): Index + { + $index = $this->_createIndex(); + $index->addDocuments([ + new Document(1, ['accounts' => ['hillary', 'sidney']]), + new Document(2, ['accounts' => ['hillary', 'donald']]), + new Document(3, ['accounts' => ['vladimir', 'donald']]), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/AggregationMetadataTest.php b/tests/Aggregation/AggregationMetadataTest.php index 5b79d53a46..3dc0d904e1 100644 --- a/tests/Aggregation/AggregationMetadataTest.php +++ b/tests/Aggregation/AggregationMetadataTest.php @@ -5,20 +5,15 @@ use Elastica\Aggregation\Cardinality; use Elastica\Query; +/** + * @internal + */ class AggregationMetadataTest extends BaseAggregationTest { - protected function _getIndexForTest() - { - $index = $this->_createIndex(); - $index->refresh(); - - return $index; - } - /** * @group functional */ - public function testAggregationSimpleMetadata() + public function testAggregationSimpleMetadata(): void { $aggName = 'mock'; $metadata = ['color' => 'blue']; @@ -37,7 +32,7 @@ public function testAggregationSimpleMetadata() /** * @group functional */ - public function testAggregationComplexMetadata() + public function testAggregationComplexMetadata(): void { $aggName = 'mock'; $metadata = [ @@ -59,4 +54,12 @@ public function testAggregationComplexMetadata() $this->assertEquals($metadata, $results['meta']); } + + protected function _getIndexForTest() + { + $index = $this->_createIndex(); + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/AvgBucketTest.php b/tests/Aggregation/AvgBucketTest.php index 18f1990c5f..73a4140359 100644 --- a/tests/Aggregation/AvgBucketTest.php +++ b/tests/Aggregation/AvgBucketTest.php @@ -9,27 +9,15 @@ use Elastica\Index; use Elastica\Query; +/** + * @internal + */ class AvgBucketTest extends BaseAggregationTest { - protected function _getIndexForTest(): Index - { - $index = $this->_createIndex(); - - $index->addDocuments([ - Document::create(['page' => 1, 'likes' => 180]), - Document::create(['page' => 1, 'likes' => 156]), - Document::create(['page' => 2, 'likes' => 155]), - ]); - - $index->refresh(); - - return $index; - } - /** * @group functional */ - public function testAvgBucketAggregation() + public function testAvgBucketAggregation(): void { $query = Query::create([]) ->addAggregation( @@ -44,7 +32,8 @@ public function testAvgBucketAggregation() ->addAggregation( (new AvgBucket('avg_likes_by_page')) ->setBucketsPath('pages>avg_likes') - ); + ) + ; $results = $this->_getIndexForTest()->search($query)->getAggregations(); @@ -56,14 +45,15 @@ public function testAvgBucketAggregation() /** * @group unit */ - public function testConstructThroughSetters() + public function testConstructThroughSetters(): void { $serialDiffAgg = new AvgBucket('avg_bucket'); $serialDiffAgg ->setBucketsPath('pages>avg_likes_by_page') ->setFormat('test_format') - ->setGapPolicy(10); + ->setGapPolicy(10) + ; $expected = [ 'avg_bucket' => [ @@ -79,11 +69,26 @@ public function testConstructThroughSetters() /** * @group unit */ - public function testToArrayInvalidBucketsPath() + public function testToArrayInvalidBucketsPath(): void { $this->expectException(\Elastica\Exception\InvalidException::class); $serialDiffAgg = new AvgBucket('avg_bucket'); $serialDiffAgg->toArray(); } + + protected function _getIndexForTest(): Index + { + $index = $this->_createIndex(); + + $index->addDocuments([ + Document::create(['page' => 1, 'likes' => 180]), + Document::create(['page' => 1, 'likes' => 156]), + Document::create(['page' => 2, 'likes' => 155]), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/AvgTest.php b/tests/Aggregation/AvgTest.php index fd48d1c794..65272532ab 100644 --- a/tests/Aggregation/AvgTest.php +++ b/tests/Aggregation/AvgTest.php @@ -7,28 +7,15 @@ use Elastica\Index; use Elastica\Query; +/** + * @internal + */ class AvgTest extends BaseAggregationTest { - protected function _getIndexForTest(): Index - { - $index = $this->_createIndex(); - - $index->addDocuments([ - new Document(1, ['price' => 5]), - new Document(2, ['price' => 8]), - new Document(3, ['price' => 1]), - new Document(4, ['price' => 3]), - ]); - - $index->refresh(); - - return $index; - } - /** * @group functional */ - public function testAvgAggregation() + public function testAvgAggregation(): void { $agg = new Avg('avg'); $agg->setField('price'); @@ -42,4 +29,20 @@ public function testAvgAggregation() $this->assertTrue($resultSet->hasAggregations()); $this->assertEquals((5 + 8 + 1 + 3) / 4.0, $results['avg']['value']); } + + protected function _getIndexForTest(): Index + { + $index = $this->_createIndex(); + + $index->addDocuments([ + new Document(1, ['price' => 5]), + new Document(2, ['price' => 8]), + new Document(3, ['price' => 1]), + new Document(4, ['price' => 3]), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/BucketScriptTest.php b/tests/Aggregation/BucketScriptTest.php index f5bf227ba9..241745c8a2 100644 --- a/tests/Aggregation/BucketScriptTest.php +++ b/tests/Aggregation/BucketScriptTest.php @@ -10,27 +10,15 @@ use Elastica\Index; use Elastica\Query; +/** + * @internal + */ class BucketScriptTest extends BaseAggregationTest { - protected function _getIndexForTest(): Index - { - $index = $this->_createIndex(); - - $index->addDocuments([ - Document::create(['weight' => 60, 'height' => 180, 'age' => 25]), - Document::create(['weight' => 65, 'height' => 156, 'age' => 32]), - Document::create(['weight' => 50, 'height' => 155, 'age' => 45]), - ]); - - $index->refresh(); - - return $index; - } - /** * @group functional */ - public function testBucketScriptAggregation() + public function testBucketScriptAggregation(): void { $bucketScriptAggregation = new BucketScript( 'result', @@ -46,7 +34,8 @@ public function testBucketScriptAggregation() $histogramAggregation ->addAggregation((new Max('max_weight'))->setField('weight')) ->addAggregation((new Max('max_height'))->setField('height')) - ->addAggregation($bucketScriptAggregation); + ->addAggregation($bucketScriptAggregation) + ; $query = Query::create([])->addAggregation($histogramAggregation); @@ -60,7 +49,7 @@ public function testBucketScriptAggregation() /** * @group unit */ - public function testConstructThroughSetters() + public function testConstructThroughSetters(): void { $serialDiffAgg = new BucketScript('bucket_scripted'); @@ -72,7 +61,8 @@ public function testConstructThroughSetters() 'z' => 'agg_min', ]) ->setFormat('test_format') - ->setGapPolicy(10); + ->setGapPolicy(10) + ; $expected = [ 'bucket_script' => [ @@ -93,7 +83,7 @@ public function testConstructThroughSetters() /** * @group unit */ - public function testToArrayInvalidBucketsPath() + public function testToArrayInvalidBucketsPath(): void { $this->expectException(InvalidException::class); @@ -104,11 +94,26 @@ public function testToArrayInvalidBucketsPath() /** * @group unit */ - public function testToArrayInvalidScript() + public function testToArrayInvalidScript(): void { $this->expectException(InvalidException::class); $serialDiffAgg = new BucketScript('bucket_scripted', ['path' => 'agg']); $serialDiffAgg->toArray(); } + + protected function _getIndexForTest(): Index + { + $index = $this->_createIndex(); + + $index->addDocuments([ + Document::create(['weight' => 60, 'height' => 180, 'age' => 25]), + Document::create(['weight' => 65, 'height' => 156, 'age' => 32]), + Document::create(['weight' => 50, 'height' => 155, 'age' => 45]), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/BucketSelectorTest.php b/tests/Aggregation/BucketSelectorTest.php index 8bc9a0ef7a..57dc41c5c7 100644 --- a/tests/Aggregation/BucketSelectorTest.php +++ b/tests/Aggregation/BucketSelectorTest.php @@ -8,34 +8,15 @@ use Elastica\Document; use Elastica\Query; +/** + * @internal + */ class BucketSelectorTest extends BaseAggregationTest { - protected function _getIndexForTest() - { - $index = $this->_createIndex(); - - $index->addDocuments([ - new Document(1, ['date' => '2018-12-01', 'value' => 1]), - new Document(2, ['date' => '2018-12-02', 'value' => 2]), - new Document(3, ['date' => '2018-12-03', 'value' => 5]), - new Document(4, ['date' => '2018-12-04', 'value' => 4]), - new Document(5, ['date' => '2018-12-05', 'value' => 6]), - new Document(6, ['date' => '2018-12-06', 'value' => 9]), - new Document(7, ['date' => '2018-12-07', 'value' => 11]), - new Document(8, ['date' => '2018-12-08', 'value' => 4]), - new Document(9, ['date' => '2018-12-09', 'value' => 7]), - new Document(10, ['date' => '2018-12-10', 'value' => 4]), - ]); - - $index->refresh(); - - return $index; - } - /** * @group unit */ - public function testToArray() + public function testToArray(): void { $expected = [ 'max' => [ @@ -63,7 +44,7 @@ public function testToArray() /** * @group functional */ - public function testMaxAggregation() + public function testMaxAggregation(): void { $index = $this->_getIndexForTest(); @@ -88,4 +69,26 @@ public function testMaxAggregation() $this->assertEquals(11, $dateHistogramAggResult[2]['max_agg']['value']); $this->assertEquals(7, $dateHistogramAggResult[3]['max_agg']['value']); } + + protected function _getIndexForTest() + { + $index = $this->_createIndex(); + + $index->addDocuments([ + new Document(1, ['date' => '2018-12-01', 'value' => 1]), + new Document(2, ['date' => '2018-12-02', 'value' => 2]), + new Document(3, ['date' => '2018-12-03', 'value' => 5]), + new Document(4, ['date' => '2018-12-04', 'value' => 4]), + new Document(5, ['date' => '2018-12-05', 'value' => 6]), + new Document(6, ['date' => '2018-12-06', 'value' => 9]), + new Document(7, ['date' => '2018-12-07', 'value' => 11]), + new Document(8, ['date' => '2018-12-08', 'value' => 4]), + new Document(9, ['date' => '2018-12-09', 'value' => 7]), + new Document(10, ['date' => '2018-12-10', 'value' => 4]), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/CardinalityTest.php b/tests/Aggregation/CardinalityTest.php index 826195e370..f695f1638a 100644 --- a/tests/Aggregation/CardinalityTest.php +++ b/tests/Aggregation/CardinalityTest.php @@ -8,33 +8,15 @@ use Elastica\Mapping; use Elastica\Query; +/** + * @internal + */ class CardinalityTest extends BaseAggregationTest { - protected function _getIndexForTest(): Index - { - $index = $this->_createIndex(); - - $mapping = new Mapping([ - 'color' => ['type' => 'keyword'], - ]); - $index->setMapping($mapping); - - $index->addDocuments([ - new Document(1, ['color' => 'blue']), - new Document(2, ['color' => 'blue']), - new Document(3, ['color' => 'red']), - new Document(4, ['color' => 'green']), - ]); - - $index->refresh(); - - return $index; - } - /** * @group functional */ - public function testCardinalityAggregation() + public function testCardinalityAggregation(): void { $agg = new Cardinality('cardinality'); $agg->setField('color'); @@ -60,7 +42,7 @@ public function validPrecisionThresholdProvider() * @dataProvider validPrecisionThresholdProvider * @group unit */ - public function testPrecisionThreshold(int $threshold) + public function testPrecisionThreshold(int $threshold): void { $agg = new Cardinality('threshold'); $agg->setPrecisionThreshold($threshold); @@ -75,7 +57,7 @@ public function testPrecisionThreshold(int $threshold) * * @param bool $rehash */ - public function testRehash($rehash) + public function testRehash($rehash): void { $agg = new Cardinality('rehash'); $agg->setRehash($rehash); @@ -91,4 +73,25 @@ public function validRehashProvider() 'false' => [false], ]; } + + protected function _getIndexForTest(): Index + { + $index = $this->_createIndex(); + + $mapping = new Mapping([ + 'color' => ['type' => 'keyword'], + ]); + $index->setMapping($mapping); + + $index->addDocuments([ + new Document(1, ['color' => 'blue']), + new Document(2, ['color' => 'blue']), + new Document(3, ['color' => 'red']), + new Document(4, ['color' => 'green']), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/ChildrenTest.php b/tests/Aggregation/ChildrenTest.php index 19196a2386..89ea47c226 100644 --- a/tests/Aggregation/ChildrenTest.php +++ b/tests/Aggregation/ChildrenTest.php @@ -8,8 +8,69 @@ use Elastica\Mapping; use Elastica\Query; +/** + * @internal + */ class ChildrenTest extends BaseAggregationTest { + /** + * @group functional + */ + public function testChildrenAggregation(): void + { + $agg = new Children('answer'); + $agg->setType('answer'); + + $names = new Terms('name'); + $names->setField('name'); + + $agg->addAggregation($names); + + $query = new Query(); + $query->addAggregation($agg); + + $index = $this->_getIndexForTest(); + $aggregations = $index->search($query)->getAggregations(); + + // check children aggregation exists + $this->assertArrayHasKey('answer', $aggregations); + + $childrenAggregations = $aggregations['answer']; + + // check names aggregation exists inside children aggregation + $this->assertArrayHasKey('name', $childrenAggregations); + } + + /** + * @group functional + */ + public function testChildrenAggregationCount(): void + { + $agg = new Children('answer'); + $agg->setType('answer'); + + $names = new Terms('name'); + $names->setField('name'); + + $agg->addAggregation($names); + + $query = new Query(); + $query->addAggregation($agg); + + $index = $this->_getIndexForTest(); + $aggregations = $index->search($query)->getAggregations(); + + $childrenAggregations = $aggregations['answer']; + $this->assertCount(2, $childrenAggregations['name']['buckets']); + + // check names aggregation works inside children aggregation + $names = [ + ['key' => 'fede', 'doc_count' => 2], + ['key' => 'rico', 'doc_count' => 1], + ]; + $this->assertEquals($names, $childrenAggregations['name']['buckets']); + } + protected function _getIndexForTest(): Index { $client = $this->_getClient(); @@ -78,62 +139,4 @@ protected function _getIndexForTest(): Index return $index; } - - /** - * @group functional - */ - public function testChildrenAggregation() - { - $agg = new Children('answer'); - $agg->setType('answer'); - - $names = new Terms('name'); - $names->setField('name'); - - $agg->addAggregation($names); - - $query = new Query(); - $query->addAggregation($agg); - - $index = $this->_getIndexForTest(); - $aggregations = $index->search($query)->getAggregations(); - - // check children aggregation exists - $this->assertArrayHasKey('answer', $aggregations); - - $childrenAggregations = $aggregations['answer']; - - // check names aggregation exists inside children aggregation - $this->assertArrayHasKey('name', $childrenAggregations); - } - - /** - * @group functional - */ - public function testChildrenAggregationCount() - { - $agg = new Children('answer'); - $agg->setType('answer'); - - $names = new Terms('name'); - $names->setField('name'); - - $agg->addAggregation($names); - - $query = new Query(); - $query->addAggregation($agg); - - $index = $this->_getIndexForTest(); - $aggregations = $index->search($query)->getAggregations(); - - $childrenAggregations = $aggregations['answer']; - $this->assertCount(2, $childrenAggregations['name']['buckets']); - - // check names aggregation works inside children aggregation - $names = [ - ['key' => 'fede', 'doc_count' => 2], - ['key' => 'rico', 'doc_count' => 1], - ]; - $this->assertEquals($names, $childrenAggregations['name']['buckets']); - } } diff --git a/tests/Aggregation/DateHistogramTest.php b/tests/Aggregation/DateHistogramTest.php index c16633fa15..b7b0c1fa68 100644 --- a/tests/Aggregation/DateHistogramTest.php +++ b/tests/Aggregation/DateHistogramTest.php @@ -8,30 +8,15 @@ use Elastica\Mapping; use Elastica\Query; +/** + * @internal + */ class DateHistogramTest extends BaseAggregationTest { - protected function _getIndexForTest(): Index - { - $index = $this->_createIndex(); - $index->setMapping(new Mapping([ - 'created' => ['type' => 'date'], - ])); - - $index->addDocuments([ - new Document(1, ['created' => '2014-01-29T00:20:00']), - new Document(2, ['created' => '2014-01-29T02:20:00']), - new Document(3, ['created' => '2014-01-29T03:20:00']), - ]); - - $index->refresh(); - - return $index; - } - /** * @group functional */ - public function testDateHistogramAggregation() + public function testDateHistogramAggregation(): void { $agg = new DateHistogram('hist', 'created', '1h'); @@ -57,7 +42,7 @@ public function testDateHistogramAggregation() /** * @group unit */ - public function testSetOffset() + public function testSetOffset(): void { $agg = new DateHistogram('hist', 'created', '1h'); @@ -79,7 +64,7 @@ public function testSetOffset() /** * @group functional */ - public function testSetOffsetWorks() + public function testSetOffsetWorks(): void { $this->_checkVersion('1.5'); @@ -96,7 +81,7 @@ public function testSetOffsetWorks() /** * @group unit */ - public function testSetTimezone() + public function testSetTimezone(): void { $agg = new DateHistogram('hist', 'created', '1h'); @@ -114,4 +99,22 @@ public function testSetTimezone() $this->assertInstanceOf(DateHistogram::class, $agg->setTimezone('-02:30')); } + + protected function _getIndexForTest(): Index + { + $index = $this->_createIndex(); + $index->setMapping(new Mapping([ + 'created' => ['type' => 'date'], + ])); + + $index->addDocuments([ + new Document(1, ['created' => '2014-01-29T00:20:00']), + new Document(2, ['created' => '2014-01-29T02:20:00']), + new Document(3, ['created' => '2014-01-29T03:20:00']), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/DateRangeTest.php b/tests/Aggregation/DateRangeTest.php index 10b31c50cf..2e11e8b83f 100644 --- a/tests/Aggregation/DateRangeTest.php +++ b/tests/Aggregation/DateRangeTest.php @@ -9,30 +9,15 @@ use Elastica\Mapping; use Elastica\Query; +/** + * @internal + */ class DateRangeTest extends BaseAggregationTest { - protected function _getIndexForTest(): Index - { - $index = $this->_createIndex(); - $index->setMapping(new Mapping([ - 'created' => ['type' => 'date', 'format' => 'epoch_millis'], - ])); - - $index->addDocuments([ - new Document(1, ['created' => 1390962135000]), - new Document(2, ['created' => 1390965735000]), - new Document(3, ['created' => 1390954935000]), - ]); - - $index->refresh(); - - return $index; - } - /** * @group functional */ - public function testDateRangeAggregation() + public function testDateRangeAggregation(): void { $agg = new DateRange('date'); $agg->setField('created'); @@ -54,7 +39,7 @@ public function testDateRangeAggregation() /** * @group functional */ - public function testDateRangeSetFormat() + public function testDateRangeSetFormat(): void { $agg = new DateRange('date'); $agg->setField('created'); @@ -71,7 +56,7 @@ public function testDateRangeSetFormat() /** * @group functional */ - public function testDateRangeSetFormatAccordingToFormatTargetField() + public function testDateRangeSetFormatAccordingToFormatTargetField(): void { $agg = new DateRange('date'); $agg->setField('created'); @@ -91,4 +76,22 @@ public function testDateRangeSetFormatAccordingToFormatTargetField() $this->assertContains('failed to parse date field', $error['root_cause'][0]['reason']); } } + + protected function _getIndexForTest(): Index + { + $index = $this->_createIndex(); + $index->setMapping(new Mapping([ + 'created' => ['type' => 'date', 'format' => 'epoch_millis'], + ])); + + $index->addDocuments([ + new Document(1, ['created' => 1390962135000]), + new Document(2, ['created' => 1390965735000]), + new Document(3, ['created' => 1390954935000]), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/DerivativeTest.php b/tests/Aggregation/DerivativeTest.php index 64c87e5fc8..3b451a2eec 100644 --- a/tests/Aggregation/DerivativeTest.php +++ b/tests/Aggregation/DerivativeTest.php @@ -8,29 +8,15 @@ use Elastica\Document; use Elastica\Query; +/** + * @internal + */ class DerivativeTest extends BaseAggregationTest { - protected function _getIndexForTest() - { - $index = $this->_createIndex(); - - $index->addDocuments([ - new Document(1, ['date' => '2018-12-01', 'value' => 1]), - new Document(2, ['date' => '2018-12-02', 'value' => 2]), - new Document(3, ['date' => '2018-12-03', 'value' => 2]), - new Document(4, ['date' => '2018-12-04', 'value' => 4]), - new Document(5, ['date' => '2018-12-05', 'value' => 3]), - ]); - - $index->refresh(); - - return $index; - } - /** * @group unit */ - public function testToArray() + public function testToArray(): void { $expected = [ 'max' => [ @@ -57,7 +43,7 @@ public function testToArray() /** * @group functional */ - public function testMaxAggregation() + public function testMaxAggregation(): void { $index = $this->_getIndexForTest(); @@ -82,4 +68,21 @@ public function testMaxAggregation() $this->assertEquals(2, $dateHistogramAggResult[3]['derivative_agg']['value']); $this->assertEquals(-1, $dateHistogramAggResult[4]['derivative_agg']['value']); } + + protected function _getIndexForTest() + { + $index = $this->_createIndex(); + + $index->addDocuments([ + new Document(1, ['date' => '2018-12-01', 'value' => 1]), + new Document(2, ['date' => '2018-12-02', 'value' => 2]), + new Document(3, ['date' => '2018-12-03', 'value' => 2]), + new Document(4, ['date' => '2018-12-04', 'value' => 4]), + new Document(5, ['date' => '2018-12-05', 'value' => 3]), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/DiversifiedSamplerTest.php b/tests/Aggregation/DiversifiedSamplerTest.php index a0c9f34674..35e5c5c834 100755 --- a/tests/Aggregation/DiversifiedSamplerTest.php +++ b/tests/Aggregation/DiversifiedSamplerTest.php @@ -9,43 +9,15 @@ use Elastica\Mapping; use Elastica\Query; +/** + * @internal + */ class DiversifiedSamplerTest extends BaseAggregationTest { - protected function _getIndexForTest(): Index - { - $index = $this->_createIndex(null, true, 2); - - $mapping = new Mapping([ - 'price' => ['type' => 'integer'], - 'color' => ['type' => 'keyword'], - ]); - $index->setMapping($mapping); - - $routing1 = 'first_routing'; - $routing2 = 'second_routing'; - - $index->addDocuments([ - (new Document(1, ['price' => 5, 'color' => 'blue']))->setRouting($routing1), - (new Document(2, ['price' => 8, 'color' => 'blue']))->setRouting($routing1), - (new Document(3, ['price' => 1, 'color' => 'blue']))->setRouting($routing1), - (new Document(4, ['price' => 3, 'color' => 'red']))->setRouting($routing1), - (new Document(5, ['price' => 1.5, 'color' => 'red']))->setRouting($routing1), - (new Document(6, ['price' => 2, 'color' => 'green']))->setRouting($routing1), - (new Document(7, ['price' => 5, 'color' => 'blue']))->setRouting($routing2), - (new Document(8, ['price' => 8, 'color' => 'blue']))->setRouting($routing2), - (new Document(9, ['price' => 1, 'color' => 'red']))->setRouting($routing2), - (new Document(10, ['price' => 3, 'color' => 'red']))->setRouting($routing2), - ]); - - $index->refresh(); - - return $index; - } - /** * @group unit */ - public function testToArray() + public function testToArray(): void { $expected = [ 'diversified_sampler' => [ @@ -82,7 +54,7 @@ public function testToArray() * @dataProvider shardSizeAndMaxDocPerValueProvider * @group functional */ - public function testSamplerAggregation(int $shardSize, int $maxDocPerValue, int $docCount) + public function testSamplerAggregation(int $shardSize, int $maxDocPerValue, int $docCount): void { $agg = new DiversifiedSampler('price_diversified_sampler'); $agg->setField('color'); @@ -117,4 +89,35 @@ public function shardSizeAndMaxDocPerValueProvider() [6, 2, 9], ]; } + + protected function _getIndexForTest(): Index + { + $index = $this->_createIndex(null, true, 2); + + $mapping = new Mapping([ + 'price' => ['type' => 'integer'], + 'color' => ['type' => 'keyword'], + ]); + $index->setMapping($mapping); + + $routing1 = 'first_routing'; + $routing2 = 'second_routing'; + + $index->addDocuments([ + (new Document(1, ['price' => 5, 'color' => 'blue']))->setRouting($routing1), + (new Document(2, ['price' => 8, 'color' => 'blue']))->setRouting($routing1), + (new Document(3, ['price' => 1, 'color' => 'blue']))->setRouting($routing1), + (new Document(4, ['price' => 3, 'color' => 'red']))->setRouting($routing1), + (new Document(5, ['price' => 1.5, 'color' => 'red']))->setRouting($routing1), + (new Document(6, ['price' => 2, 'color' => 'green']))->setRouting($routing1), + (new Document(7, ['price' => 5, 'color' => 'blue']))->setRouting($routing2), + (new Document(8, ['price' => 8, 'color' => 'blue']))->setRouting($routing2), + (new Document(9, ['price' => 1, 'color' => 'red']))->setRouting($routing2), + (new Document(10, ['price' => 3, 'color' => 'red']))->setRouting($routing2), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/ExtendedStatsTest.php b/tests/Aggregation/ExtendedStatsTest.php index 84a3f116c1..1f7cb3e719 100644 --- a/tests/Aggregation/ExtendedStatsTest.php +++ b/tests/Aggregation/ExtendedStatsTest.php @@ -7,28 +7,15 @@ use Elastica\Index; use Elastica\Query; +/** + * @internal + */ class ExtendedStatsTest extends BaseAggregationTest { - protected function _getIndexForTest(): Index - { - $index = $this->_createIndex(); - - $index->addDocuments([ - new Document(1, ['price' => 5]), - new Document(2, ['price' => 8]), - new Document(3, ['price' => 1]), - new Document(4, ['price' => 3]), - ]); - - $index->refresh(); - - return $index; - } - /** * @group functional */ - public function testExtendedStatsAggregation() + public function testExtendedStatsAggregation(): void { $agg = new ExtendedStats('stats'); $agg->setField('price'); @@ -44,4 +31,20 @@ public function testExtendedStatsAggregation() $this->assertEquals((5 + 8 + 1 + 3), $results['sum']); $this->assertArrayHasKey('sum_of_squares', $results); } + + protected function _getIndexForTest(): Index + { + $index = $this->_createIndex(); + + $index->addDocuments([ + new Document(1, ['price' => 5]), + new Document(2, ['price' => 8]), + new Document(3, ['price' => 1]), + new Document(4, ['price' => 3]), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/FilterTest.php b/tests/Aggregation/FilterTest.php index 96aaae6417..eec6fe6cf5 100644 --- a/tests/Aggregation/FilterTest.php +++ b/tests/Aggregation/FilterTest.php @@ -10,28 +10,15 @@ use Elastica\Query\Range; use Elastica\Query\Term; +/** + * @internal + */ class FilterTest extends BaseAggregationTest { - protected function _getIndexForTest(): Index - { - $index = $this->_createIndex(); - - $index->addDocuments([ - new Document(1, ['price' => 5, 'color' => 'blue']), - new Document(2, ['price' => 8, 'color' => 'blue']), - new Document(3, ['price' => 1, 'color' => 'red']), - new Document(4, ['price' => 3, 'color' => 'green']), - ]); - - $index->refresh(); - - return $index; - } - /** * @group unit */ - public function testToArray() + public function testToArray(): void { $expected = [ 'filter' => ['range' => ['stock' => ['gt' => 0]]], @@ -52,7 +39,7 @@ public function testToArray() /** * @group functional */ - public function testFilterAggregation() + public function testFilterAggregation(): void { $agg = new Filter('filter'); $agg->setFilter(new Term(['color' => 'blue'])); @@ -72,7 +59,7 @@ public function testFilterAggregation() /** * @group functional */ - public function testFilterNoSubAggregation() + public function testFilterNoSubAggregation(): void { $agg = new Avg('price'); $agg->setField('price'); @@ -89,7 +76,7 @@ public function testFilterNoSubAggregation() /** * @group unit */ - public function testConstruct() + public function testConstruct(): void { $agg = new Filter('foo', new Term(['color' => 'blue'])); @@ -107,9 +94,25 @@ public function testConstruct() /** * @group unit */ - public function testConstructWithoutFilter() + public function testConstructWithoutFilter(): void { $agg = new Filter('foo'); $this->assertEquals('foo', $agg->getName()); } + + protected function _getIndexForTest(): Index + { + $index = $this->_createIndex(); + + $index->addDocuments([ + new Document(1, ['price' => 5, 'color' => 'blue']), + new Document(2, ['price' => 8, 'color' => 'blue']), + new Document(3, ['price' => 1, 'color' => 'red']), + new Document(4, ['price' => 3, 'color' => 'green']), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/FiltersTest.php b/tests/Aggregation/FiltersTest.php index 663404469b..8ecd88c229 100644 --- a/tests/Aggregation/FiltersTest.php +++ b/tests/Aggregation/FiltersTest.php @@ -9,28 +9,15 @@ use Elastica\Query; use Elastica\Query\Term; +/** + * @internal + */ class FiltersTest extends BaseAggregationTest { - protected function _getIndexForTest(): Index - { - $index = $this->_createIndex('filter'); - - $index->addDocuments([ - new Document(1, ['price' => 5, 'color' => 'blue']), - new Document(2, ['price' => 8, 'color' => 'blue']), - new Document(3, ['price' => 1, 'color' => 'red']), - new Document(4, ['price' => 3, 'color' => 'green']), - ]); - - $index->refresh(); - - return $index; - } - /** * @group unit */ - public function testToArrayUsingNamedFilters() + public function testToArrayUsingNamedFilters(): void { $expected = [ 'filters' => [ @@ -71,7 +58,7 @@ public function testToArrayUsingNamedFilters() /** * @group unit */ - public function testMixNamedAndAnonymousFilters() + public function testMixNamedAndAnonymousFilters(): void { $this->expectException(\Elastica\Exception\InvalidException::class); $this->expectExceptionMessage('Mix named and anonymous keys are not allowed'); @@ -84,7 +71,7 @@ public function testMixNamedAndAnonymousFilters() /** * @group unit */ - public function testMixAnonymousAndNamedFilters() + public function testMixAnonymousAndNamedFilters(): void { $this->expectException(\Elastica\Exception\InvalidException::class); $this->expectExceptionMessage('Mix named and anonymous keys are not allowed'); @@ -98,7 +85,7 @@ public function testMixAnonymousAndNamedFilters() /** * @group unit */ - public function testToArrayUsingAnonymousFilters() + public function testToArrayUsingAnonymousFilters(): void { $expected = [ 'filters' => [ @@ -131,7 +118,7 @@ public function testToArrayUsingAnonymousFilters() /** * @group unit */ - public function testToArrayUsingOtherBucket() + public function testToArrayUsingOtherBucket(): void { $expected = [ 'filters' => [ @@ -158,7 +145,7 @@ public function testToArrayUsingOtherBucket() /** * @group functional */ - public function testFilterAggregation() + public function testFilterAggregation(): void { $agg = new Filters('by_color'); $agg->addFilter(new Term(['color' => 'blue']), 'blue'); @@ -186,7 +173,7 @@ public function testFilterAggregation() /** * @group functional */ - public function testSetOtherBucket() + public function testSetOtherBucket(): void { $agg = new Filters('by_color'); $agg->addFilter(new Term(['color' => 'red']), 'red'); @@ -214,7 +201,7 @@ public function testSetOtherBucket() /** * @group functional */ - public function testSetOtherBucketKey() + public function testSetOtherBucketKey(): void { $agg = new Filters('by_color'); $agg->addFilter(new Term(['color' => 'red']), 'red'); @@ -239,4 +226,20 @@ public function testSetOtherBucketKey() $this->assertEquals(1, $resultsForRed['avg_price']['value']); $this->assertEquals((5 + 8 + 3) / 3, $resultsForOtherBucket['avg_price']['value']); } + + protected function _getIndexForTest(): Index + { + $index = $this->_createIndex('filter'); + + $index->addDocuments([ + new Document(1, ['price' => 5, 'color' => 'blue']), + new Document(2, ['price' => 8, 'color' => 'blue']), + new Document(3, ['price' => 1, 'color' => 'red']), + new Document(4, ['price' => 3, 'color' => 'green']), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/GeoBoundsTest.php b/tests/Aggregation/GeoBoundsTest.php index 9184b0903c..ecb16d9c6d 100644 --- a/tests/Aggregation/GeoBoundsTest.php +++ b/tests/Aggregation/GeoBoundsTest.php @@ -8,8 +8,28 @@ use Elastica\Mapping; use Elastica\Query; +/** + * @internal + */ class GeoBoundsTest extends BaseAggregationTest { + /** + * @group functional + */ + public function testGeoBoundsAggregation(): void + { + $agg = new GeoBounds('viewport', 'location'); + + $query = new Query(); + $query->addAggregation($agg); + $results = $this->getIndexForTest()->search($query)->getAggregation('viewport'); + + $this->assertEquals(37.782438984141, $results['bounds']['top_left']['lat']); + $this->assertEquals(-122.39256000146, $results['bounds']['top_left']['lon']); + $this->assertEquals(32.798319971189, $results['bounds']['bottom_right']['lat']); + $this->assertEquals(-117.24664804526, $results['bounds']['bottom_right']['lon']); + } + private function getIndexForTest(): Index { $index = $this->_createIndex(); @@ -27,21 +47,4 @@ private function getIndexForTest(): Index return $index; } - - /** - * @group functional - */ - public function testGeoBoundsAggregation() - { - $agg = new GeoBounds('viewport', 'location'); - - $query = new Query(); - $query->addAggregation($agg); - $results = $this->getIndexForTest()->search($query)->getAggregation('viewport'); - - $this->assertEquals(37.782438984141, $results['bounds']['top_left']['lat']); - $this->assertEquals(-122.39256000146, $results['bounds']['top_left']['lon']); - $this->assertEquals(32.798319971189, $results['bounds']['bottom_right']['lat']); - $this->assertEquals(-117.24664804526, $results['bounds']['bottom_right']['lon']); - } } diff --git a/tests/Aggregation/GeoCentroidTest.php b/tests/Aggregation/GeoCentroidTest.php index eabd678e62..b7220c9bc1 100644 --- a/tests/Aggregation/GeoCentroidTest.php +++ b/tests/Aggregation/GeoCentroidTest.php @@ -8,8 +8,25 @@ use Elastica\Mapping; use Elastica\Query; +/** + * @internal + */ class GeoCentroidTest extends BaseAggregationTest { + /** + * @group functional + */ + public function testGeohashGridAggregation(): void + { + $agg = new GeoCentroid('centroid', 'location'); + + $query = new Query(); + $query->addAggregation($agg); + $results = $this->_getIndexForTest()->search($query)->getAggregation('centroid'); + + $this->assertEquals(3, $results['count']); + } + protected function _getIndexForTest(): Index { $index = $this->_createIndex(); @@ -27,18 +44,4 @@ protected function _getIndexForTest(): Index return $index; } - - /** - * @group functional - */ - public function testGeohashGridAggregation() - { - $agg = new GeoCentroid('centroid', 'location'); - - $query = new Query(); - $query->addAggregation($agg); - $results = $this->_getIndexForTest()->search($query)->getAggregation('centroid'); - - $this->assertEquals(3, $results['count']); - } } diff --git a/tests/Aggregation/GeoDistanceTest.php b/tests/Aggregation/GeoDistanceTest.php index f86b5e215f..82d84f4904 100644 --- a/tests/Aggregation/GeoDistanceTest.php +++ b/tests/Aggregation/GeoDistanceTest.php @@ -8,8 +8,27 @@ use Elastica\Mapping; use Elastica\Query; +/** + * @internal + */ class GeoDistanceTest extends BaseAggregationTest { + /** + * @group functional + */ + public function testGeoDistanceAggregation(): void + { + $agg = new GeoDistance('geo', 'location', ['lat' => 32.804654, 'lon' => -117.242594]); + $agg->addRange(null, 100); + $agg->setUnit('mi'); + + $query = new Query(); + $query->addAggregation($agg); + $results = $this->_getIndexForTest()->search($query)->getAggregation('geo'); + + $this->assertEquals(2, $results['buckets'][0]['doc_count']); + } + protected function _getIndexForTest(): Index { $index = $this->_createIndex(); @@ -27,20 +46,4 @@ protected function _getIndexForTest(): Index return $index; } - - /** - * @group functional - */ - public function testGeoDistanceAggregation() - { - $agg = new GeoDistance('geo', 'location', ['lat' => 32.804654, 'lon' => -117.242594]); - $agg->addRange(null, 100); - $agg->setUnit('mi'); - - $query = new Query(); - $query->addAggregation($agg); - $results = $this->_getIndexForTest()->search($query)->getAggregation('geo'); - - $this->assertEquals(2, $results['buckets'][0]['doc_count']); - } } diff --git a/tests/Aggregation/GeohashGridTest.php b/tests/Aggregation/GeohashGridTest.php index 756fa1b824..897686a22d 100644 --- a/tests/Aggregation/GeohashGridTest.php +++ b/tests/Aggregation/GeohashGridTest.php @@ -8,8 +8,27 @@ use Elastica\Mapping; use Elastica\Query; +/** + * @internal + */ class GeohashGridTest extends BaseAggregationTest { + /** + * @group functional + */ + public function testGeohashGridAggregation(): void + { + $agg = new GeohashGrid('hash', 'location'); + $agg->setPrecision(3); + + $query = new Query(); + $query->addAggregation($agg); + $results = $this->_getIndexForTest()->search($query)->getAggregation('hash'); + + $this->assertEquals(2, $results['buckets'][0]['doc_count']); + $this->assertEquals(1, $results['buckets'][1]['doc_count']); + } + protected function _getIndexForTest(): Index { $index = $this->_createIndex(); @@ -27,20 +46,4 @@ protected function _getIndexForTest(): Index return $index; } - - /** - * @group functional - */ - public function testGeohashGridAggregation() - { - $agg = new GeohashGrid('hash', 'location'); - $agg->setPrecision(3); - - $query = new Query(); - $query->addAggregation($agg); - $results = $this->_getIndexForTest()->search($query)->getAggregation('hash'); - - $this->assertEquals(2, $results['buckets'][0]['doc_count']); - $this->assertEquals(1, $results['buckets'][1]['doc_count']); - } } diff --git a/tests/Aggregation/GlobalAggregationTest.php b/tests/Aggregation/GlobalAggregationTest.php index e6027930f3..5d5f007947 100644 --- a/tests/Aggregation/GlobalAggregationTest.php +++ b/tests/Aggregation/GlobalAggregationTest.php @@ -5,12 +5,15 @@ use Elastica\Aggregation\Avg; use Elastica\Aggregation\GlobalAggregation; +/** + * @internal + */ class GlobalAggregationTest extends BaseAggregationTest { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $expected = [ 'global' => new \stdClass(), diff --git a/tests/Aggregation/HistogramTest.php b/tests/Aggregation/HistogramTest.php index fc7b25e53d..e1cd66c584 100644 --- a/tests/Aggregation/HistogramTest.php +++ b/tests/Aggregation/HistogramTest.php @@ -7,8 +7,29 @@ use Elastica\Index; use Elastica\Query; +/** + * @internal + */ class HistogramTest extends BaseAggregationTest { + /** + * @group functional + */ + public function testHistogramAggregation(): void + { + $agg = new Histogram('hist', 'price', 10); + $agg->setMinimumDocumentCount(0); // should return empty buckets + + $query = new Query(); + $query->addAggregation($agg); + $results = $this->_getIndexForTest()->search($query)->getAggregation('hist'); + + $buckets = $results['buckets']; + $this->assertCount(5, $buckets); + $this->assertEquals(30, $buckets[3]['key']); + $this->assertEquals(2, $buckets[3]['doc_count']); + } + protected function _getIndexForTest(): Index { $index = $this->_createIndex(); @@ -28,22 +49,4 @@ protected function _getIndexForTest(): Index return $index; } - - /** - * @group functional - */ - public function testHistogramAggregation() - { - $agg = new Histogram('hist', 'price', 10); - $agg->setMinimumDocumentCount(0); // should return empty buckets - - $query = new Query(); - $query->addAggregation($agg); - $results = $this->_getIndexForTest()->search($query)->getAggregation('hist'); - - $buckets = $results['buckets']; - $this->assertCount(5, $buckets); - $this->assertEquals(30, $buckets[3]['key']); - $this->assertEquals(2, $buckets[3]['doc_count']); - } } diff --git a/tests/Aggregation/IpRangeTest.php b/tests/Aggregation/IpRangeTest.php index ddd4e80a33..abb25b485b 100644 --- a/tests/Aggregation/IpRangeTest.php +++ b/tests/Aggregation/IpRangeTest.php @@ -8,30 +8,15 @@ use Elastica\Mapping; use Elastica\Query; +/** + * @internal + */ class IpRangeTest extends BaseAggregationTest { - protected function _getIndexForTest(): Index - { - $index = $this->_createIndex(); - $index->setMapping(new Mapping([ - 'address' => ['type' => 'ip'], - ])); - - $index->addDocuments([ - new Document(1, ['address' => '192.168.1.100']), - new Document(2, ['address' => '192.168.1.150']), - new Document(3, ['address' => '192.168.1.200']), - ]); - - $index->refresh(); - - return $index; - } - /** * @group functional */ - public function testIpRangeAggregation() + public function testIpRangeAggregation(): void { $agg = new IpRange('ip', 'address'); $agg->addRange('192.168.1.101'); @@ -54,4 +39,22 @@ public function testIpRangeAggregation() } } } + + protected function _getIndexForTest(): Index + { + $index = $this->_createIndex(); + $index->setMapping(new Mapping([ + 'address' => ['type' => 'ip'], + ])); + + $index->addDocuments([ + new Document(1, ['address' => '192.168.1.100']), + new Document(2, ['address' => '192.168.1.150']), + new Document(3, ['address' => '192.168.1.200']), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/MaxTest.php b/tests/Aggregation/MaxTest.php index df51ed8b89..40a68c1e21 100644 --- a/tests/Aggregation/MaxTest.php +++ b/tests/Aggregation/MaxTest.php @@ -8,30 +8,17 @@ use Elastica\Query; use Elastica\Script\Script; +/** + * @internal + */ class MaxTest extends BaseAggregationTest { private const MAX_PRICE = 8; - protected function _getIndexForTest(): Index - { - $index = $this->_createIndex(); - - $index->addDocuments([ - new Document(1, ['price' => 5]), - new Document(2, ['price' => self::MAX_PRICE]), - new Document(3, ['price' => 1]), - new Document(4, ['price' => 3]), - ]); - - $index->refresh(); - - return $index; - } - /** * @group unit */ - public function testToArray() + public function testToArray(): void { $expected = [ 'max' => [ @@ -61,7 +48,7 @@ public function testToArray() /** * @group functional */ - public function testMaxAggregation() + public function testMaxAggregation(): void { $index = $this->_getIndexForTest(); @@ -82,4 +69,20 @@ public function testMaxAggregation() $this->assertEquals(self::MAX_PRICE * 1.2, $results['value']); } + + protected function _getIndexForTest(): Index + { + $index = $this->_createIndex(); + + $index->addDocuments([ + new Document(1, ['price' => 5]), + new Document(2, ['price' => self::MAX_PRICE]), + new Document(3, ['price' => 1]), + new Document(4, ['price' => 3]), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/MinTest.php b/tests/Aggregation/MinTest.php index 57fc9ec439..3cfa9d83e3 100644 --- a/tests/Aggregation/MinTest.php +++ b/tests/Aggregation/MinTest.php @@ -7,10 +7,28 @@ use Elastica\Index; use Elastica\Query; +/** + * @internal + */ class MinTest extends BaseAggregationTest { private const MIN_PRICE = 1; + /** + * @group functional + */ + public function testMinAggregation(): void + { + $agg = new Min('min_price'); + $agg->setField('price'); + + $query = new Query(); + $query->addAggregation($agg); + $results = $this->_getIndexForTest()->search($query)->getAggregation('min_price'); + + $this->assertEquals(self::MIN_PRICE, $results['value']); + } + protected function _getIndexForTest(): Index { $index = $this->_createIndex(); @@ -26,19 +44,4 @@ protected function _getIndexForTest(): Index return $index; } - - /** - * @group functional - */ - public function testMinAggregation() - { - $agg = new Min('min_price'); - $agg->setField('price'); - - $query = new Query(); - $query->addAggregation($agg); - $results = $this->_getIndexForTest()->search($query)->getAggregation('min_price'); - - $this->assertEquals(self::MIN_PRICE, $results['value']); - } } diff --git a/tests/Aggregation/MissingTest.php b/tests/Aggregation/MissingTest.php index 2a4a151c13..a4abc5bccf 100644 --- a/tests/Aggregation/MissingTest.php +++ b/tests/Aggregation/MissingTest.php @@ -8,8 +8,25 @@ use Elastica\Mapping; use Elastica\Query; +/** + * @internal + */ class MissingTest extends BaseAggregationTest { + /** + * @group functional + */ + public function testMissingAggregation(): void + { + $agg = new Missing('missing', 'color'); + + $query = new Query(); + $query->addAggregation($agg); + $results = $this->_getIndexForTest()->search($query)->getAggregation('missing'); + + $this->assertEquals(1, $results['doc_count']); + } + protected function _getIndexForTest(): Index { $index = $this->_createIndex(); @@ -30,18 +47,4 @@ protected function _getIndexForTest(): Index return $index; } - - /** - * @group functional - */ - public function testMissingAggregation() - { - $agg = new Missing('missing', 'color'); - - $query = new Query(); - $query->addAggregation($agg); - $results = $this->_getIndexForTest()->search($query)->getAggregation('missing'); - - $this->assertEquals(1, $results['doc_count']); - } } diff --git a/tests/Aggregation/NestedTest.php b/tests/Aggregation/NestedTest.php index 9f7ea47f7d..e069388f0e 100644 --- a/tests/Aggregation/NestedTest.php +++ b/tests/Aggregation/NestedTest.php @@ -9,8 +9,29 @@ use Elastica\Mapping; use Elastica\Query; +/** + * @internal + */ class NestedTest extends BaseAggregationTest { + /** + * @group functional + */ + public function testNestedAggregation(): void + { + $agg = new Nested('resellers', 'resellers'); + $min = new Min('min_price'); + $min->setField('resellers.price'); + $agg->addAggregation($min); + + $query = new Query(); + $query->addAggregation($agg); + + $results = $this->_getIndexForTest()->search($query)->getAggregation('resellers'); + + $this->assertEquals(4.98, $results['min_price']['value']); + } + protected function _getIndexForTest(): Index { $index = $this->_createIndex(); @@ -44,22 +65,4 @@ protected function _getIndexForTest(): Index return $index; } - - /** - * @group functional - */ - public function testNestedAggregation() - { - $agg = new Nested('resellers', 'resellers'); - $min = new Min('min_price'); - $min->setField('resellers.price'); - $agg->addAggregation($min); - - $query = new Query(); - $query->addAggregation($agg); - - $results = $this->_getIndexForTest()->search($query)->getAggregation('resellers'); - - $this->assertEquals(4.98, $results['min_price']['value']); - } } diff --git a/tests/Aggregation/ParentAggregationTest.php b/tests/Aggregation/ParentAggregationTest.php index d47a1089c1..7ab73a1908 100644 --- a/tests/Aggregation/ParentAggregationTest.php +++ b/tests/Aggregation/ParentAggregationTest.php @@ -7,8 +7,85 @@ use Elastica\Mapping; use Elastica\Query; +/** + * @internal + */ class ParentAggregationTest extends BaseAggregationTest { + /** + * @group functional + */ + public function testParentAggregation(): void + { + $agg = new ParentAggregation('question'); + $agg->setType('answer'); + + $tags = new Terms('tags'); + $tags->setField('tags'); + + $agg->addAggregation($tags); + + $query = new Query(); + $query->addAggregation($agg); + + $index = $this->_getIndexForTest(); + $aggregations = $index->search($query)->getAggregations(); + + // check parent aggregation exists + $this->assertArrayHasKey('question', $aggregations); + + $parentAggregations = $aggregations['question']; + + // check tags aggregation exists inside parent aggregation + $this->assertArrayHasKey('tags', $parentAggregations); + } + + /** + * @group functional + */ + public function testParentAggregationCount(): void + { + $topNames = new Terms('top-names'); + $topNames->setField('owner') + ->setSize(10) + ; + + $toQuestions = new ParentAggregation('to-questions'); + $toQuestions->setType('answer'); + + $topTags = new Terms('top-tags'); + $topTags->setField('tags') + ->setSize(10) + ; + + $toQuestions->addAggregation($topTags); + $topNames->addAggregation($toQuestions); + + $query = new Query(); + $query->addAggregation($topNames); + + $index = $this->_getIndexForTest(); + $aggregations = $index->search($query)->getAggregations(); + + $topNamesAggregation = $aggregations['top-names']; + $this->assertCount(2, $topNamesAggregation['buckets']); + $this->assertEquals(2, $topNamesAggregation['buckets'][0]['to-questions']['doc_count']); + $this->assertEquals(1, $topNamesAggregation['buckets'][1]['to-questions']['doc_count']); + + $samTags = [ + ['key' => 'file-transfer', 'doc_count' => 2], + ['key' => 'windows-server-2008', 'doc_count' => 2], + ['key' => 'windows-server-2003', 'doc_count' => 1], + ]; + $this->assertEquals($samTags, $topNamesAggregation['buckets'][0]['to-questions']['top-tags']['buckets']); + + $samTags = [ + ['key' => 'file-transfer', 'doc_count' => 1], + ['key' => 'windows-server-2008', 'doc_count' => 1], + ]; + $this->assertEquals($samTags, $topNamesAggregation['buckets'][1]['to-questions']['top-tags']['buckets']); + } + protected function _getIndexForTest() { $client = $this->_getClient(); @@ -88,76 +165,4 @@ protected function _getIndexForTest() return $index; } - - /** - * @group functional - */ - public function testParentAggregation() - { - $agg = new ParentAggregation('question'); - $agg->setType('answer'); - - $tags = new Terms('tags'); - $tags->setField('tags'); - - $agg->addAggregation($tags); - - $query = new Query(); - $query->addAggregation($agg); - - $index = $this->_getIndexForTest(); - $aggregations = $index->search($query)->getAggregations(); - - // check parent aggregation exists - $this->assertArrayHasKey('question', $aggregations); - - $parentAggregations = $aggregations['question']; - - // check tags aggregation exists inside parent aggregation - $this->assertArrayHasKey('tags', $parentAggregations); - } - - /** - * @group functional - */ - public function testParentAggregationCount() - { - $topNames = new Terms('top-names'); - $topNames->setField('owner') - ->setSize(10); - - $toQuestions = new ParentAggregation('to-questions'); - $toQuestions->setType('answer'); - - $topTags = new Terms('top-tags'); - $topTags->setField('tags') - ->setSize(10); - - $toQuestions->addAggregation($topTags); - $topNames->addAggregation($toQuestions); - - $query = new Query(); - $query->addAggregation($topNames); - - $index = $this->_getIndexForTest(); - $aggregations = $index->search($query)->getAggregations(); - - $topNamesAggregation = $aggregations['top-names']; - $this->assertCount(2, $topNamesAggregation['buckets']); - $this->assertEquals(2, $topNamesAggregation['buckets'][0]['to-questions']['doc_count']); - $this->assertEquals(1, $topNamesAggregation['buckets'][1]['to-questions']['doc_count']); - - $samTags = [ - ['key' => 'file-transfer', 'doc_count' => 2], - ['key' => 'windows-server-2008', 'doc_count' => 2], - ['key' => 'windows-server-2003', 'doc_count' => 1], - ]; - $this->assertEquals($samTags, $topNamesAggregation['buckets'][0]['to-questions']['top-tags']['buckets']); - - $samTags = [ - ['key' => 'file-transfer', 'doc_count' => 1], - ['key' => 'windows-server-2008', 'doc_count' => 1], - ]; - $this->assertEquals($samTags, $topNamesAggregation['buckets'][1]['to-questions']['top-tags']['buckets']); - } } diff --git a/tests/Aggregation/PercentilesTest.php b/tests/Aggregation/PercentilesTest.php index 4c1505cd13..c7114c4d03 100644 --- a/tests/Aggregation/PercentilesTest.php +++ b/tests/Aggregation/PercentilesTest.php @@ -6,12 +6,15 @@ use Elastica\Document; use Elastica\Query; +/** + * @internal + */ class PercentilesTest extends BaseAggregationTest { /** * @group functional */ - public function testConstruct() + public function testConstruct(): void { $aggr = new Percentiles('price_percentile'); $this->assertEquals('price_percentile', $aggr->getName()); @@ -23,7 +26,7 @@ public function testConstruct() /** * @group functional */ - public function testSetField() + public function testSetField(): void { $aggr = new Percentiles('price_percentile'); $aggr->setField('price'); @@ -35,7 +38,7 @@ public function testSetField() /** * @group unit */ - public function testCompression() + public function testCompression(): void { $expected = [ 'percentiles' => [ @@ -57,7 +60,7 @@ public function testCompression() /** * @group unit */ - public function testHdr() + public function testHdr(): void { $expected = [ 'percentiles' => [ @@ -79,7 +82,7 @@ public function testHdr() /** * @group functional */ - public function testSetPercents() + public function testSetPercents(): void { $percents = [1, 2, 3]; $aggr = new Percentiles('price_percentile'); @@ -91,7 +94,7 @@ public function testSetPercents() /** * @group functional */ - public function testAddPercent() + public function testAddPercent(): void { $percents = [1, 2, 3]; $aggr = new Percentiles('price_percentile'); @@ -106,7 +109,7 @@ public function testAddPercent() /** * @group functional */ - public function testSetScript() + public function testSetScript(): void { $script = 'doc["load_time"].value / 20'; $aggr = new Percentiles('price_percentile'); @@ -118,7 +121,7 @@ public function testSetScript() /** * @group functional */ - public function testActualWork() + public function testActualWork(): void { // prepare $index = $this->_createIndex(); @@ -158,7 +161,7 @@ public function testActualWork() /** * @group functional */ - public function testKeyed() + public function testKeyed(): void { $expected = [ 'values' => [ @@ -226,7 +229,7 @@ public function testKeyed() /** * @group unit */ - public function testMissing() + public function testMissing(): void { $expected = [ 'percentiles' => [ diff --git a/tests/Aggregation/RangeTest.php b/tests/Aggregation/RangeTest.php index 0caef375c8..a7b484a746 100644 --- a/tests/Aggregation/RangeTest.php +++ b/tests/Aggregation/RangeTest.php @@ -7,30 +7,15 @@ use Elastica\Index; use Elastica\Query; +/** + * @internal + */ class RangeTest extends BaseAggregationTest { - protected function _getIndexForTest(): Index - { - $index = $this->_createIndex(); - - $index->addDocuments([ - new Document(1, ['price' => 5]), - new Document(2, ['price' => 8]), - new Document(3, ['price' => 1]), - new Document(4, ['price' => 3]), - new Document(5, ['price' => 1.5]), - new Document(6, ['price' => 2]), - ]); - - $index->refresh(); - - return $index; - } - /** * @group functional */ - public function testRangeAggregation() + public function testRangeAggregation(): void { $agg = new Range('range'); $agg->setField('price'); @@ -46,7 +31,7 @@ public function testRangeAggregation() /** * @group unit */ - public function testRangeAggregationWithKey() + public function testRangeAggregationWithKey(): void { $agg = new Range('range'); $agg->setField('price'); @@ -77,4 +62,22 @@ public function testRangeAggregationWithKey() $this->assertEquals($expected, $agg->toArray()); } + + protected function _getIndexForTest(): Index + { + $index = $this->_createIndex(); + + $index->addDocuments([ + new Document(1, ['price' => 5]), + new Document(2, ['price' => 8]), + new Document(3, ['price' => 1]), + new Document(4, ['price' => 3]), + new Document(5, ['price' => 1.5]), + new Document(6, ['price' => 2]), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/ReverseNestedTest.php b/tests/Aggregation/ReverseNestedTest.php index 3a5c30f26d..693c11df2c 100644 --- a/tests/Aggregation/ReverseNestedTest.php +++ b/tests/Aggregation/ReverseNestedTest.php @@ -10,63 +10,15 @@ use Elastica\Mapping; use Elastica\Query; +/** + * @internal + */ class ReverseNestedTest extends BaseAggregationTest { - protected function _getIndexForTest(): Index - { - $index = $this->_createIndex(); - $mapping = new Mapping(); - $mapping->setProperties([ - 'comments' => [ - 'type' => 'nested', - 'properties' => [ - 'name' => ['type' => 'keyword'], - 'body' => ['type' => 'text'], - ], - ], - 'tags' => ['type' => 'keyword'], - ]); - - $index->setMapping($mapping); - - $index->addDocuments([ - new Document(1, [ - 'comments' => [ - [ - 'name' => 'bob', - 'body' => 'this is bobs comment', - ], - [ - 'name' => 'john', - 'body' => 'this is johns comment', - ], - ], - 'tags' => ['foo', 'bar'], - ]), - new Document(2, [ - 'comments' => [ - [ - 'name' => 'bob', - 'body' => 'this is another comment from bob', - ], - [ - 'name' => 'susan', - 'body' => 'this is susans comment', - ], - ], - 'tags' => ['foo', 'baz'], - ]), - ]); - - $index->refresh(); - - return $index; - } - /** * @group unit */ - public function testPathNotSetIfNull() + public function testPathNotSetIfNull(): void { $agg = new ReverseNested('nested'); $this->assertFalse($agg->hasParam('path')); @@ -75,7 +27,7 @@ public function testPathNotSetIfNull() /** * @group unit */ - public function testPathSetIfNotNull() + public function testPathSetIfNotNull(): void { $agg = new ReverseNested('nested', 'some_field'); $this->assertEquals('some_field', $agg->getParam('path')); @@ -84,7 +36,7 @@ public function testPathSetIfNotNull() /** * @group functional */ - public function testReverseNestedAggregation() + public function testReverseNestedAggregation(): void { $agg = new Nested('comments', 'comments'); $names = new Terms('name'); @@ -134,4 +86,55 @@ public function testReverseNestedAggregation() ]; $this->assertEquals($tags, $nameResults['buckets'][2]['main']['tags']['buckets']); } + + protected function _getIndexForTest(): Index + { + $index = $this->_createIndex(); + $mapping = new Mapping(); + $mapping->setProperties([ + 'comments' => [ + 'type' => 'nested', + 'properties' => [ + 'name' => ['type' => 'keyword'], + 'body' => ['type' => 'text'], + ], + ], + 'tags' => ['type' => 'keyword'], + ]); + + $index->setMapping($mapping); + + $index->addDocuments([ + new Document(1, [ + 'comments' => [ + [ + 'name' => 'bob', + 'body' => 'this is bobs comment', + ], + [ + 'name' => 'john', + 'body' => 'this is johns comment', + ], + ], + 'tags' => ['foo', 'bar'], + ]), + new Document(2, [ + 'comments' => [ + [ + 'name' => 'bob', + 'body' => 'this is another comment from bob', + ], + [ + 'name' => 'susan', + 'body' => 'this is susans comment', + ], + ], + 'tags' => ['foo', 'baz'], + ]), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/SamplerTest.php b/tests/Aggregation/SamplerTest.php index 14b2d13c65..dc3bd01b46 100644 --- a/tests/Aggregation/SamplerTest.php +++ b/tests/Aggregation/SamplerTest.php @@ -8,32 +8,15 @@ use Elastica\Index; use Elastica\Query; +/** + * @internal + */ class SamplerTest extends BaseAggregationTest { - protected function _getIndexForTest(): Index - { - $index = $this->_createIndex(null, true, 2); - - $routing1 = 'first_routing'; - $routing2 = 'second_routing'; - - $index->addDocuments([ - (new Document(1, ['price' => 5]))->setRouting($routing1), - (new Document(2, ['price' => 8]))->setRouting($routing1), - (new Document(3, ['price' => 1]))->setRouting($routing1), - (new Document(4, ['price' => 3]))->setRouting($routing2), - (new Document(5, ['price' => 1.5]))->setRouting($routing2), - ]); - - $index->refresh(); - - return $index; - } - /** * @group unit */ - public function testToArray() + public function testToArray(): void { $expected = [ 'sampler' => [ @@ -63,7 +46,7 @@ public function testToArray() * @dataProvider shardSizeProvider * @group functional */ - public function testSamplerAggregation(int $shardSize, int $docCount) + public function testSamplerAggregation(int $shardSize, int $docCount): void { $agg = new Sampler('price_sampler'); $agg->setShardSize($shardSize); @@ -88,4 +71,24 @@ public function shardSizeProvider() [3, 5], ]; } + + protected function _getIndexForTest(): Index + { + $index = $this->_createIndex(null, true, 2); + + $routing1 = 'first_routing'; + $routing2 = 'second_routing'; + + $index->addDocuments([ + (new Document(1, ['price' => 5]))->setRouting($routing1), + (new Document(2, ['price' => 8]))->setRouting($routing1), + (new Document(3, ['price' => 1]))->setRouting($routing1), + (new Document(4, ['price' => 3]))->setRouting($routing2), + (new Document(5, ['price' => 1.5]))->setRouting($routing2), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/ScriptTest.php b/tests/Aggregation/ScriptTest.php index 1fdf898481..0b0ad23ba8 100644 --- a/tests/Aggregation/ScriptTest.php +++ b/tests/Aggregation/ScriptTest.php @@ -8,28 +8,15 @@ use Elastica\Query; use Elastica\Script\Script; +/** + * @internal + */ class ScriptTest extends BaseAggregationTest { - protected function _getIndexForTest(): Index - { - $index = $this->_createIndex(); - - $index->addDocuments([ - new Document('1', ['price' => 5]), - new Document('2', ['price' => 8]), - new Document('3', ['price' => 1]), - new Document('4', ['price' => 3]), - ]); - - $index->refresh(); - - return $index; - } - /** * @group functional */ - public function testAggregationScript() + public function testAggregationScript(): void { $agg = new Sum('sum'); $script = new Script("return doc['price'].value", null, Script::LANG_PAINLESS); @@ -45,7 +32,7 @@ public function testAggregationScript() /** * @group functional */ - public function testAggregationScriptAsString() + public function testAggregationScriptAsString(): void { $agg = new Sum('sum'); $agg->setScript(new Script("doc['price'].value", null, Script::LANG_PAINLESS)); @@ -60,7 +47,7 @@ public function testAggregationScriptAsString() /** * @group unit */ - public function testSetScript() + public function testSetScript(): void { $aggregation = 'sum'; $string = "doc['price'].value"; @@ -87,4 +74,20 @@ public function testSetScript() ]; $this->assertEquals($expected, $array); } + + protected function _getIndexForTest(): Index + { + $index = $this->_createIndex(); + + $index->addDocuments([ + new Document('1', ['price' => 5]), + new Document('2', ['price' => 8]), + new Document('3', ['price' => 1]), + new Document('4', ['price' => 3]), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/ScriptedMetricTest.php b/tests/Aggregation/ScriptedMetricTest.php index b1a602a4dd..4152c02b14 100644 --- a/tests/Aggregation/ScriptedMetricTest.php +++ b/tests/Aggregation/ScriptedMetricTest.php @@ -8,32 +8,15 @@ use Elastica\Mapping; use Elastica\Query; +/** + * @internal + */ class ScriptedMetricTest extends BaseAggregationTest { - protected function _getIndexForTest(): Index - { - $index = $this->_createIndex(); - - $index->setMapping(new Mapping([ - 'start' => ['type' => 'long'], - 'end' => ['type' => 'long'], - ])); - - $index->addDocuments([ - new Document(1, ['start' => 100, 'end' => 200]), - new Document(2, ['start' => 200, 'end' => 250]), - new Document(3, ['start' => 300, 'end' => 450]), - ]); - - $index->refresh(); - - return $index; - } - /** * @group functional */ - public function testScriptedMetricAggregation() + public function testScriptedMetricAggregation(): void { $agg = new ScriptedMetric( 'scripted', @@ -50,4 +33,24 @@ public function testScriptedMetricAggregation() $this->assertEquals([100, 50, 150], $results['value'][0]); } + + protected function _getIndexForTest(): Index + { + $index = $this->_createIndex(); + + $index->setMapping(new Mapping([ + 'start' => ['type' => 'long'], + 'end' => ['type' => 'long'], + ])); + + $index->addDocuments([ + new Document(1, ['start' => 100, 'end' => 200]), + new Document(2, ['start' => 200, 'end' => 250]), + new Document(3, ['start' => 300, 'end' => 450]), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/SerialDiffTest.php b/tests/Aggregation/SerialDiffTest.php index 33c28d2cc2..cd29d5cbba 100644 --- a/tests/Aggregation/SerialDiffTest.php +++ b/tests/Aggregation/SerialDiffTest.php @@ -10,39 +10,22 @@ use Elastica\Mapping; use Elastica\Query; +/** + * @internal + */ class SerialDiffTest extends BaseAggregationTest { - protected function _getIndexForTest(): Index - { - $index = $this->_createIndex(); - - $index->setMapping(Mapping::create([ - 'value' => ['type' => 'long'], - 'measured_at' => ['type' => 'date'], - ])); - - $index->addDocuments([ - Document::create(['value' => 100, 'measured_at' => '2016-08-23T15:00:00+0200']), - Document::create(['value' => 266, 'measured_at' => '2016-08-23T16:00:00+0200']), - Document::create(['value' => 350, 'measured_at' => '2016-08-23T17:00:00+0200']), - Document::create(['value' => 471, 'measured_at' => '2016-08-23T18:00:00+0200']), - ]); - - $index->refresh(); - - return $index; - } - /** * @group functional */ - public function testSerialDiffAggregation() + public function testSerialDiffAggregation(): void { $dateHistogramAggregation = new DateHistogram('measurements', 'measured_at', 'hour'); $dateHistogramAggregation ->addAggregation((new Max('max_value'))->setField('value')) - ->addAggregation(new SerialDiff('result', 'max_value')); + ->addAggregation(new SerialDiff('result', 'max_value')) + ; $query = Query::create([])->addAggregation($dateHistogramAggregation); @@ -57,7 +40,7 @@ public function testSerialDiffAggregation() /** * @group unit */ - public function testConstructThroughSetters() + public function testConstructThroughSetters(): void { $serialDiffAgg = new SerialDiff('difference'); @@ -65,7 +48,8 @@ public function testConstructThroughSetters() ->setBucketsPath('nested_agg') ->setFormat('test_format') ->setGapPolicy(10) - ->setLag(5); + ->setLag(5) + ; $expected = [ 'serial_diff' => [ @@ -82,11 +66,32 @@ public function testConstructThroughSetters() /** * @group unit */ - public function testToArrayInvalidBucketsPath() + public function testToArrayInvalidBucketsPath(): void { $this->expectException(\Elastica\Exception\InvalidException::class); $serialDiffAgg = new SerialDiff('difference'); $serialDiffAgg->toArray(); } + + protected function _getIndexForTest(): Index + { + $index = $this->_createIndex(); + + $index->setMapping(Mapping::create([ + 'value' => ['type' => 'long'], + 'measured_at' => ['type' => 'date'], + ])); + + $index->addDocuments([ + Document::create(['value' => 100, 'measured_at' => '2016-08-23T15:00:00+0200']), + Document::create(['value' => 266, 'measured_at' => '2016-08-23T16:00:00+0200']), + Document::create(['value' => 350, 'measured_at' => '2016-08-23T17:00:00+0200']), + Document::create(['value' => 471, 'measured_at' => '2016-08-23T18:00:00+0200']), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/SignificantTermsTest.php b/tests/Aggregation/SignificantTermsTest.php index ce941310ed..cb9b19f598 100644 --- a/tests/Aggregation/SignificantTermsTest.php +++ b/tests/Aggregation/SignificantTermsTest.php @@ -9,34 +9,15 @@ use Elastica\Query; use Elastica\Query\Terms; +/** + * @internal + */ class SignificantTermsTest extends BaseAggregationTest { - protected function _getIndexForTest(): Index - { - $index = $this->_createIndex(); - $colors = ['blue', 'blue', 'red', 'red', 'green', 'yellow', 'white', 'cyan', 'magenta']; - $temperatures = [1500, 1500, 1500, 1500, 2500, 3500, 4500, 5500, 6500, 7500, 7500, 8500, 9500]; - - $mapping = new Mapping([ - 'color' => ['type' => 'keyword'], - 'temperature' => ['type' => 'keyword'], - ]); - $index->setMapping($mapping); - - $docs = []; - for ($i = 0; $i < 250; ++$i) { - $docs[] = new Document($i, ['color' => $colors[$i % \count($colors)], 'temperature' => $temperatures[$i % \count($temperatures)]]); - } - $index->addDocuments($docs); - $index->refresh(); - - return $index; - } - /** * @group functional */ - public function testSignificantTermsAggregation() + public function testSignificantTermsAggregation(): void { $agg = new SignificantTerms('significantTerms'); $agg->setField('temperature'); @@ -58,7 +39,7 @@ public function testSignificantTermsAggregation() /** * @group functional */ - public function testSignificantTermsAggregationWithBackgroundFilter() + public function testSignificantTermsAggregationWithBackgroundFilter(): void { $agg = new SignificantTerms('significantTerms'); $agg->setField('temperature'); @@ -82,7 +63,7 @@ public function testSignificantTermsAggregationWithBackgroundFilter() /** * @group functional */ - public function testSignificantTermsAggregationWithBackgroundFilterWithLegacyFilter() + public function testSignificantTermsAggregationWithBackgroundFilterWithLegacyFilter(): void { $agg = new SignificantTerms('significantTerms'); $agg->setField('temperature'); @@ -102,4 +83,26 @@ public function testSignificantTermsAggregationWithBackgroundFilterWithLegacyFil $this->assertEquals(12, $results['buckets'][0]['bg_count']); $this->assertEquals('4500', $results['buckets'][0]['key']); } + + protected function _getIndexForTest(): Index + { + $index = $this->_createIndex(); + $colors = ['blue', 'blue', 'red', 'red', 'green', 'yellow', 'white', 'cyan', 'magenta']; + $temperatures = [1500, 1500, 1500, 1500, 2500, 3500, 4500, 5500, 6500, 7500, 7500, 8500, 9500]; + + $mapping = new Mapping([ + 'color' => ['type' => 'keyword'], + 'temperature' => ['type' => 'keyword'], + ]); + $index->setMapping($mapping); + + $docs = []; + for ($i = 0; $i < 250; ++$i) { + $docs[] = new Document($i, ['color' => $colors[$i % \count($colors)], 'temperature' => $temperatures[$i % \count($temperatures)]]); + } + $index->addDocuments($docs); + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/StatsBucketTest.php b/tests/Aggregation/StatsBucketTest.php index 01458605e8..81cab3eee3 100644 --- a/tests/Aggregation/StatsBucketTest.php +++ b/tests/Aggregation/StatsBucketTest.php @@ -9,27 +9,15 @@ use Elastica\Index; use Elastica\Query; +/** + * @internal + */ class StatsBucketTest extends BaseAggregationTest { - protected function _getIndexForTest(): Index - { - $index = $this->_createIndex(); - - $index->addDocuments([ - Document::create(['weight' => 60, 'height' => 180, 'age' => 25]), - Document::create(['weight' => 70, 'height' => 156, 'age' => 32]), - Document::create(['weight' => 50, 'height' => 155, 'age' => 45]), - ]); - - $index->refresh(); - - return $index; - } - /** * @group functional */ - public function testStatBucketAggregation() + public function testStatBucketAggregation(): void { $bucketScriptAggregation = new StatsBucket('result', 'age_groups>max_weight'); @@ -39,7 +27,8 @@ public function testStatBucketAggregation() $query = Query::create([]) ->addAggregation($histogramAggregation) - ->addAggregation($bucketScriptAggregation); + ->addAggregation($bucketScriptAggregation) + ; $results = $this->_getIndexForTest()->search($query)->getAggregation('result'); @@ -53,14 +42,15 @@ public function testStatBucketAggregation() /** * @group unit */ - public function testConstructThroughSetters() + public function testConstructThroughSetters(): void { $serialDiffAgg = new StatsBucket('bucket_part'); $serialDiffAgg ->setBucketsPath('age_groups>max_weight') ->setFormat('test_format') - ->setGapPolicy(10); + ->setGapPolicy(10) + ; $expected = [ 'stats_bucket' => [ @@ -76,11 +66,26 @@ public function testConstructThroughSetters() /** * @group unit */ - public function testToArrayInvalidBucketsPath() + public function testToArrayInvalidBucketsPath(): void { $this->expectException(\Elastica\Exception\InvalidException::class); $serialDiffAgg = new StatsBucket('bucket_part'); $serialDiffAgg->toArray(); } + + protected function _getIndexForTest(): Index + { + $index = $this->_createIndex(); + + $index->addDocuments([ + Document::create(['weight' => 60, 'height' => 180, 'age' => 25]), + Document::create(['weight' => 70, 'height' => 156, 'age' => 32]), + Document::create(['weight' => 50, 'height' => 155, 'age' => 45]), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/StatsTest.php b/tests/Aggregation/StatsTest.php index 09492bf256..0aa2a5b1b5 100644 --- a/tests/Aggregation/StatsTest.php +++ b/tests/Aggregation/StatsTest.php @@ -7,28 +7,15 @@ use Elastica\Index; use Elastica\Query; +/** + * @internal + */ class StatsTest extends BaseAggregationTest { - protected function _getIndexForTest(): Index - { - $index = $this->_createIndex(); - - $index->addDocuments([ - new Document(1, ['price' => 5]), - new Document(2, ['price' => 8]), - new Document(3, ['price' => 1]), - new Document(4, ['price' => 3]), - ]); - - $index->refresh(); - - return $index; - } - /** * @group functional */ - public function testStatsAggregation() + public function testStatsAggregation(): void { $agg = new Stats('stats'); $agg->setField('price'); @@ -43,4 +30,20 @@ public function testStatsAggregation() $this->assertEquals((5 + 8 + 1 + 3) / 4.0, $results['avg']); $this->assertEquals((5 + 8 + 1 + 3), $results['sum']); } + + protected function _getIndexForTest(): Index + { + $index = $this->_createIndex(); + + $index->addDocuments([ + new Document(1, ['price' => 5]), + new Document(2, ['price' => 8]), + new Document(3, ['price' => 1]), + new Document(4, ['price' => 3]), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/SumBucketTest.php b/tests/Aggregation/SumBucketTest.php index 552b8d3fd3..dc24c690a5 100644 --- a/tests/Aggregation/SumBucketTest.php +++ b/tests/Aggregation/SumBucketTest.php @@ -9,27 +9,15 @@ use Elastica\Index; use Elastica\Query; +/** + * @internal + */ class SumBucketTest extends BaseAggregationTest { - protected function _getIndexForTest(): Index - { - $index = $this->_createIndex(); - - $index->addDocuments([ - Document::create(['page' => 1, 'likes' => 180]), - Document::create(['page' => 1, 'likes' => 156]), - Document::create(['page' => 2, 'likes' => 155]), - ]); - - $index->refresh(); - - return $index; - } - /** * @group functional */ - public function testSumBucketAggregation() + public function testSumBucketAggregation(): void { $query = Query::create([]) ->addAggregation( @@ -44,7 +32,8 @@ public function testSumBucketAggregation() ->addAggregation( (new SumBucket('sum_likes_by_page')) ->setBucketsPath('pages>sum_likes') - ); + ) + ; $results = $this->_getIndexForTest()->search($query)->getAggregations(); @@ -56,14 +45,15 @@ public function testSumBucketAggregation() /** * @group unit */ - public function testConstructThroughSetters() + public function testConstructThroughSetters(): void { $serialDiffAgg = new SumBucket('sum_bucket'); $serialDiffAgg ->setBucketsPath('pages>sum_likes_by_page') ->setFormat('test_format') - ->setGapPolicy(10); + ->setGapPolicy(10) + ; $expected = [ 'sum_bucket' => [ @@ -79,11 +69,26 @@ public function testConstructThroughSetters() /** * @group unit */ - public function testToArrayInvalidBucketsPath() + public function testToArrayInvalidBucketsPath(): void { $this->expectException(\Elastica\Exception\InvalidException::class); $serialDiffAgg = new SumBucket('sum_bucket'); $serialDiffAgg->toArray(); } + + protected function _getIndexForTest(): Index + { + $index = $this->_createIndex(); + + $index->addDocuments([ + Document::create(['page' => 1, 'likes' => 180]), + Document::create(['page' => 1, 'likes' => 156]), + Document::create(['page' => 2, 'likes' => 155]), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/SumTest.php b/tests/Aggregation/SumTest.php index a43a079e84..376e754a3a 100644 --- a/tests/Aggregation/SumTest.php +++ b/tests/Aggregation/SumTest.php @@ -7,8 +7,26 @@ use Elastica\Index; use Elastica\Query; +/** + * @internal + */ class SumTest extends BaseAggregationTest { + /** + * @group functional + */ + public function testSumAggregation(): void + { + $agg = new Sum('sum'); + $agg->setField('price'); + + $query = new Query(); + $query->addAggregation($agg); + $results = $this->_getIndexForTest()->search($query)->getAggregation('sum'); + + $this->assertEquals(5 + 8 + 1 + 3, $results['value']); + } + protected function _getIndexForTest(): Index { $index = $this->_createIndex(); @@ -24,19 +42,4 @@ protected function _getIndexForTest(): Index return $index; } - - /** - * @group functional - */ - public function testSumAggregation() - { - $agg = new Sum('sum'); - $agg->setField('price'); - - $query = new Query(); - $query->addAggregation($agg); - $results = $this->_getIndexForTest()->search($query)->getAggregation('sum'); - - $this->assertEquals(5 + 8 + 1 + 3, $results['value']); - } } diff --git a/tests/Aggregation/TermsTest.php b/tests/Aggregation/TermsTest.php index 7185a0a68f..87d8342391 100644 --- a/tests/Aggregation/TermsTest.php +++ b/tests/Aggregation/TermsTest.php @@ -8,33 +8,15 @@ use Elastica\Mapping; use Elastica\Query; +/** + * @internal + */ class TermsTest extends BaseAggregationTest { - protected function _getIndexForTest(): Index - { - $index = $this->_createIndex(); - - $mapping = new Mapping([ - 'color' => ['type' => 'keyword'], - ]); - $index->setMapping($mapping); - - $index->addDocuments([ - new Document(1, ['color' => 'blue']), - new Document(2, ['color' => 'blue']), - new Document(3, ['color' => 'red']), - new Document(4, ['color' => 'green']), - ]); - - $index->refresh(); - - return $index; - } - /** * @group functional */ - public function testTermsAggregation() + public function testTermsAggregation(): void { $agg = new Terms('terms'); $agg->setField('color'); @@ -50,7 +32,7 @@ public function testTermsAggregation() /** * @group functional */ - public function testTermsSetOrder() + public function testTermsSetOrder(): void { $agg = new Terms('terms'); $agg->setField('color'); @@ -66,7 +48,7 @@ public function testTermsSetOrder() /** * @group functional */ - public function testTermsSetOrders() + public function testTermsSetOrders(): void { $agg = new Terms('terms'); $agg->setField('color'); @@ -83,4 +65,25 @@ public function testTermsSetOrders() $this->assertSame('red', $results['buckets'][1]['key']); $this->assertSame('blue', $results['buckets'][2]['key']); } + + protected function _getIndexForTest(): Index + { + $index = $this->_createIndex(); + + $mapping = new Mapping([ + 'color' => ['type' => 'keyword'], + ]); + $index->setMapping($mapping); + + $index->addDocuments([ + new Document(1, ['color' => 'blue']), + new Document(2, ['color' => 'blue']), + new Document(3, ['color' => 'red']), + new Document(4, ['color' => 'green']), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Aggregation/TopHitsTest.php b/tests/Aggregation/TopHitsTest.php index 410b5c3a2b..a6c76192c2 100644 --- a/tests/Aggregation/TopHitsTest.php +++ b/tests/Aggregation/TopHitsTest.php @@ -13,60 +13,15 @@ use Elastica\Script\Script; use Elastica\Script\ScriptFields; +/** + * @internal + */ class TopHitsTest extends BaseAggregationTest { - protected function _getIndexForTest(): Index - { - $index = $this->_createIndex(); - $mapping = new Mapping([ - 'tags' => ['type' => 'keyword'], - 'title' => ['type' => 'keyword'], - 'my_join_field' => [ - 'type' => 'join', - 'relations' => [ - 'question' => 'answer', - ], - ], - ]); - $index->setMapping($mapping); - - $index->addDocuments([ - new Document(1, [ - 'tags' => ['linux'], - 'last_activity_date' => '2015-01-05', - 'title' => 'Question about linux #1', - ]), - new Document(2, [ - 'tags' => ['linux'], - 'last_activity_date' => '2014-12-23', - 'title' => 'Question about linux #2', - ]), - new Document(3, [ - 'tags' => ['windows'], - 'last_activity_date' => '2015-01-05', - 'title' => 'Question about windows #1', - ]), - new Document(4, [ - 'tags' => ['windows'], - 'last_activity_date' => '2014-12-23', - 'title' => 'Question about windows #2', - ]), - new Document(5, [ - 'tags' => ['osx', 'apple'], - 'last_activity_date' => '2014-12-23', - 'title' => 'Question about osx', - ]), - ]); - - $index->refresh(); - - return $index; - } - /** * @group unit */ - public function testSetSize() + public function testSetSize(): void { $agg = new TopHits('agg_name'); $returnValue = $agg->setSize(12); @@ -77,7 +32,7 @@ public function testSetSize() /** * @group unit */ - public function testSetFrom() + public function testSetFrom(): void { $agg = new TopHits('agg_name'); $returnValue = $agg->setFrom(12); @@ -88,7 +43,7 @@ public function testSetFrom() /** * @group unit */ - public function testSetSort() + public function testSetSort(): void { $sort = ['last_activity_date' => ['order' => 'desc']]; $agg = new TopHits('agg_name'); @@ -100,7 +55,7 @@ public function testSetSort() /** * @group unit */ - public function testSetSource() + public function testSetSource(): void { $fields = ['title', 'tags']; $agg = new TopHits('agg_name'); @@ -112,7 +67,7 @@ public function testSetSource() /** * @group unit */ - public function testSetVersion() + public function testSetVersion(): void { $agg = new TopHits('agg_name'); $returnValue = $agg->setVersion(true); @@ -126,7 +81,7 @@ public function testSetVersion() /** * @group unit */ - public function testSetExplain() + public function testSetExplain(): void { $agg = new TopHits('agg_name'); $returnValue = $agg->setExplain(true); @@ -140,7 +95,7 @@ public function testSetExplain() /** * @group unit */ - public function testSetHighlight() + public function testSetHighlight(): void { $highlight = [ 'fields' => [ @@ -156,7 +111,7 @@ public function testSetHighlight() /** * @group unit */ - public function testSetFieldDataFields() + public function testSetFieldDataFields(): void { $fields = ['title', 'tags']; $agg = new TopHits('agg_name'); @@ -168,7 +123,7 @@ public function testSetFieldDataFields() /** * @group unit */ - public function testSetScriptFields() + public function testSetScriptFields(): void { $script = new Script('1 + 2'); $scriptFields = new ScriptFields(['three' => $script]); @@ -182,7 +137,7 @@ public function testSetScriptFields() /** * @group unit */ - public function testAddScriptField() + public function testAddScriptField(): void { $script = new Script('2+3'); $agg = new TopHits('agg_name'); @@ -191,23 +146,10 @@ public function testAddScriptField() $this->assertInstanceOf(TopHits::class, $returnValue); } - protected function getOuterAggregationResult($innerAggr) - { - $outerAggr = new Terms('top_tags'); - $outerAggr->setField('tags'); - $outerAggr->setMinimumDocumentCount(2); - $outerAggr->addAggregation($innerAggr); - - $query = new Query(new MatchAll()); - $query->addAggregation($outerAggr); - - return $this->_getIndexForTest()->search($query)->getAggregation('top_tags'); - } - /** * @group functional */ - public function testAggregateUpdatedRecently() + public function testAggregateUpdatedRecently(): void { $aggr = new TopHits('top_tag_hits'); $aggr->setSize(1); @@ -226,7 +168,7 @@ public function testAggregateUpdatedRecently() /** * @group functional */ - public function testAggregateUpdatedFarAgo() + public function testAggregateUpdatedFarAgo(): void { $aggr = new TopHits('top_tag_hits'); $aggr->setSize(1); @@ -245,7 +187,7 @@ public function testAggregateUpdatedFarAgo() /** * @group functional */ - public function testAggregateTwoDocumentPerTag() + public function testAggregateTwoDocumentPerTag(): void { $aggr = new TopHits('top_tag_hits'); $aggr->setSize(2); @@ -263,7 +205,7 @@ public function testAggregateTwoDocumentPerTag() /** * @group functional */ - public function testAggregateTwoDocumentPerTagWithOffset() + public function testAggregateTwoDocumentPerTagWithOffset(): void { $aggr = new TopHits('top_tag_hits'); $aggr->setSize(2); @@ -291,8 +233,10 @@ public function limitedSourceProvider() /** * @group functional * @dataProvider limitedSourceProvider + * + * @param mixed $source */ - public function testAggregateWithLimitedSource($source) + public function testAggregateWithLimitedSource($source): void { $aggr = new TopHits('top_tag_hits'); $aggr->setSource($source); @@ -311,7 +255,7 @@ public function testAggregateWithLimitedSource($source) /** * @group functional */ - public function testAggregateWithVersion() + public function testAggregateWithVersion(): void { $aggr = new TopHits('top_tag_hits'); $aggr->setVersion(true); @@ -328,7 +272,7 @@ public function testAggregateWithVersion() /** * @group functional */ - public function testAggregateWithExplain() + public function testAggregateWithExplain(): void { $aggr = new TopHits('top_tag_hits'); $aggr->setExplain(true); @@ -345,7 +289,7 @@ public function testAggregateWithExplain() /** * @group functional */ - public function testAggregateWithScriptFields() + public function testAggregateWithScriptFields(): void { $aggr = new TopHits('top_tag_hits'); $aggr->setSize(1); @@ -365,7 +309,7 @@ public function testAggregateWithScriptFields() /** * @group functional */ - public function testAggregateWithHighlight() + public function testAggregateWithHighlight(): void { $queryString = new SimpleQueryString('linux', ['title']); @@ -387,7 +331,7 @@ public function testAggregateWithHighlight() /** * @group functional */ - public function testAggregateWithFieldData() + public function testAggregateWithFieldData(): void { $aggr = new TopHits('top_tag_hits'); $aggr->setFieldDataFields(['title']); @@ -405,4 +349,65 @@ public function testAggregateWithFieldData() $this->assertArrayNotHasKey('last_activity_date', $doc['fields']); } } + + protected function _getIndexForTest(): Index + { + $index = $this->_createIndex(); + $mapping = new Mapping([ + 'tags' => ['type' => 'keyword'], + 'title' => ['type' => 'keyword'], + 'my_join_field' => [ + 'type' => 'join', + 'relations' => [ + 'question' => 'answer', + ], + ], + ]); + $index->setMapping($mapping); + + $index->addDocuments([ + new Document(1, [ + 'tags' => ['linux'], + 'last_activity_date' => '2015-01-05', + 'title' => 'Question about linux #1', + ]), + new Document(2, [ + 'tags' => ['linux'], + 'last_activity_date' => '2014-12-23', + 'title' => 'Question about linux #2', + ]), + new Document(3, [ + 'tags' => ['windows'], + 'last_activity_date' => '2015-01-05', + 'title' => 'Question about windows #1', + ]), + new Document(4, [ + 'tags' => ['windows'], + 'last_activity_date' => '2014-12-23', + 'title' => 'Question about windows #2', + ]), + new Document(5, [ + 'tags' => ['osx', 'apple'], + 'last_activity_date' => '2014-12-23', + 'title' => 'Question about osx', + ]), + ]); + + $index->refresh(); + + return $index; + } + + protected function getOuterAggregationResult($innerAggr) + { + $outerAggr = new Terms('top_tags'); + $outerAggr->setField('tags'); + $outerAggr->setMinimumDocumentCount(2); + $outerAggr->addAggregation($innerAggr); + + $query = new Query(new MatchAll()); + $query->addAggregation($outerAggr); + + return $this->_getIndexForTest()->search($query)->getAggregation('top_tags'); + } } diff --git a/tests/Aggregation/ValueCountTest.php b/tests/Aggregation/ValueCountTest.php index 1893f8dd49..9a51ada1a7 100644 --- a/tests/Aggregation/ValueCountTest.php +++ b/tests/Aggregation/ValueCountTest.php @@ -7,8 +7,25 @@ use Elastica\Index; use Elastica\Query; +/** + * @internal + */ class ValueCountTest extends BaseAggregationTest { + /** + * @group functional + */ + public function testValueCountAggregation(): void + { + $agg = new ValueCount('count', 'price'); + + $query = new Query(); + $query->addAggregation($agg); + $results = $this->_getIndexForTest()->search($query)->getAggregation('count'); + + $this->assertEquals(5, $results['value']); + } + protected function _getIndexForTest(): Index { $index = $this->_createIndex(); @@ -25,18 +42,4 @@ protected function _getIndexForTest(): Index return $index; } - - /** - * @group functional - */ - public function testValueCountAggregation() - { - $agg = new ValueCount('count', 'price'); - - $query = new Query(); - $query->addAggregation($agg); - $results = $this->_getIndexForTest()->search($query)->getAggregation('count'); - - $this->assertEquals(5, $results['value']); - } } diff --git a/tests/Base.php b/tests/Base.php index f38a41456d..3ce2da766d 100644 --- a/tests/Base.php +++ b/tests/Base.php @@ -10,14 +10,36 @@ use PHPUnit\Util\Test as TestUtil; use Psr\Log\LoggerInterface; +/** + * @internal + */ class Base extends TestCase { - protected static function hideDeprecated() + protected function setUp(): void + { + parent::setUp(); + + $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(): void + { + if ($this->_isFunctionalGroup()) { + $this->_getClient()->getIndex('_all')->delete(); + $this->_getClient()->getIndex('_all')->clearCache(); + } + + parent::tearDown(); + } + + protected static function hideDeprecated(): void { \error_reporting(\error_reporting() & ~E_USER_DEPRECATED); } - protected static function showDeprecated() + protected static function showDeprecated(): void { \error_reporting(\error_reporting() | E_USER_DEPRECATED); } @@ -84,7 +106,7 @@ protected static function buildUniqueId(): string return \preg_replace('/[^a-z]/i', '', \strtolower(static::class).\uniqid()); } - protected function _createRenamePipeline() + protected function _createRenamePipeline(): void { $client = $this->_getClient(); @@ -105,7 +127,7 @@ protected function _createRenamePipeline() $client->requestEndpoint($endpoint); } - protected function _checkPlugin($plugin) + protected function _checkPlugin($plugin): void { $nodes = $this->_getClient()->getCluster()->getNodes(); if (!$nodes[0]->getInfo()->hasPlugin($plugin)) { @@ -120,7 +142,7 @@ protected function _getVersion() return \substr($data['version']['number'], 0, 1); } - protected function _checkVersion($version) + protected function _checkVersion($version): void { $data = $this->_getClient()->request('/')->getData(); $installedVersion = $data['version']['number']; @@ -130,7 +152,7 @@ protected function _checkVersion($version) } } - protected function _checkConnection($host, $port) + protected function _checkConnection($host, $port): void { $fp = @\pfsockopen($host, $port); @@ -139,7 +161,7 @@ protected function _checkConnection($host, $port) } } - protected function _waitForAllocation(Index $index) + protected function _waitForAllocation(Index $index): void { do { $state = $index->getClient()->getCluster()->getState(); @@ -154,25 +176,6 @@ protected function _waitForAllocation(Index $index) } while (!$allocated); } - protected function setUp() - { - parent::setUp(); - - $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() - { - if ($this->_isFunctionalGroup()) { - $this->_getClient()->getIndex('_all')->delete(); - $this->_getClient()->getIndex('_all')->clearCache(); - } - - parent::tearDown(); - } - protected function _isUnitGroup() { $groups = TestUtil::getGroups(\get_class($this), $this->getName(false)); diff --git a/tests/BasePipeline.php b/tests/BasePipeline.php index 02ba77454f..beac80f36c 100644 --- a/tests/BasePipeline.php +++ b/tests/BasePipeline.php @@ -5,8 +5,17 @@ use Elastica\Pipeline; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class BasePipeline extends BaseTest { + protected function tearDown(): void + { + $this->_createPipeline()->deletePipeline('*'); + parent::tearDown(); + } + protected function _createPipeline(?string $id = null, string $description = ''): Pipeline { $id = $id ?: static::buildUniqueId(); @@ -17,10 +26,4 @@ protected function _createPipeline(?string $id = null, string $description = '') return $pipeline; } - - protected function tearDown() - { - $this->_createPipeline()->deletePipeline('*'); - parent::tearDown(); - } } diff --git a/tests/Bulk/Action/AbstractDocumentTest.php b/tests/Bulk/Action/AbstractDocumentTest.php index f2e6bc45cc..d468f8ff0e 100644 --- a/tests/Bulk/Action/AbstractDocumentTest.php +++ b/tests/Bulk/Action/AbstractDocumentTest.php @@ -6,12 +6,15 @@ use Elastica\Script\Script; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class AbstractDocumentTest extends BaseTest { /** * @group unit */ - public function testCreateAbstractDocumentWithInvalidParameter() + public function testCreateAbstractDocumentWithInvalidParameter(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('The data needs to be a Document or a Script.'); @@ -22,7 +25,7 @@ public function testCreateAbstractDocumentWithInvalidParameter() /** * @group unit */ - public function testCreateAbstractDocumentWithScript() + public function testCreateAbstractDocumentWithScript(): void { $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('Scripts can only be used with the update operation type.'); diff --git a/tests/Bulk/Action/UpdateDocumentTest.php b/tests/Bulk/Action/UpdateDocumentTest.php index 12c64ab42e..17a406d3c9 100644 --- a/tests/Bulk/Action/UpdateDocumentTest.php +++ b/tests/Bulk/Action/UpdateDocumentTest.php @@ -7,12 +7,15 @@ use Elastica\Index; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class UpdateDocumentTest extends BaseTest { /** * @group unit */ - public function testUpdateDocument() + public function testUpdateDocument(): void { $document = new Document(null, ['foo' => 'bar']); $action = new UpdateDocument($document); @@ -53,7 +56,7 @@ public function testUpdateDocument() /** * @group unit */ - public function testUpdateDocumentAsUpsert() + public function testUpdateDocumentAsUpsert(): void { $document = new Document('1', ['foo' => 'bar'], 'index'); $document->setDocAsUpsert(true); diff --git a/tests/Bulk/ActionTest.php b/tests/Bulk/ActionTest.php index def9518ac8..65e2b3a91e 100644 --- a/tests/Bulk/ActionTest.php +++ b/tests/Bulk/ActionTest.php @@ -6,12 +6,15 @@ use Elastica\Index; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class ActionTest extends BaseTest { /** * @group unit */ - public function testAction() + public function testAction(): void { $action = new Action(); $this->assertEquals('index', $action->getOpType()); diff --git a/tests/Bulk/ResponseSetTest.php b/tests/Bulk/ResponseSetTest.php index f3b5398658..50631781d1 100644 --- a/tests/Bulk/ResponseSetTest.php +++ b/tests/Bulk/ResponseSetTest.php @@ -11,13 +11,16 @@ use Elastica\Response; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class ResponseSetTest extends BaseTest { /** * @group unit * @dataProvider isOkDataProvider */ - public function testIsOk(array $responseData, array $actions, bool $expected) + public function testIsOk(array $responseData, array $actions, bool $expected): void { $responseSet = $this->_createResponseSet($responseData, $actions); $this->assertEquals($expected, $responseSet->isOk()); @@ -26,7 +29,7 @@ public function testIsOk(array $responseData, array $actions, bool $expected) /** * @group unit */ - public function testGetError() + public function testGetError(): void { list($responseData, $actions) = $this->_getFixture(); $responseData['items'][1]['index']['ok'] = false; @@ -64,7 +67,7 @@ public function testGetError() /** * @group unit */ - public function testGetBulkResponses() + public function testGetBulkResponses(): void { list($responseData, $actions) = $this->_getFixture(); @@ -88,7 +91,7 @@ public function testGetBulkResponses() /** * @group unit */ - public function testIterator() + public function testIterator(): void { list($responseData, $actions) = $this->_getFixture(); diff --git a/tests/BulkTest.php b/tests/BulkTest.php index 38978c9828..7ec4c4298a 100644 --- a/tests/BulkTest.php +++ b/tests/BulkTest.php @@ -16,12 +16,15 @@ use Elastica\Script\Script; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class BulkTest extends BaseTest { /** * @group functional */ - public function testSend() + public function testSend(): void { $index = $this->_createIndex(); $indexName = $index->getName(); @@ -135,7 +138,7 @@ public function testSend() /** * @group functional */ - public function testUnicodeBulkSend() + public function testUnicodeBulkSend(): void { $index = $this->_createIndex(); $client = $index->getClient(); @@ -164,7 +167,7 @@ public function testUnicodeBulkSend() /** * @group functional */ - public function testSetIndex() + public function testSetIndex(): void { $client = $this->_getClient(); $index = $client->getIndex('index'); @@ -191,7 +194,7 @@ public function testSetIndex() /** * @group unit */ - public function testAddActions() + public function testAddActions(): void { $client = $this->_getClient(); $bulk = new Bulk($client); @@ -221,7 +224,7 @@ public function testAddActions() /** * @group unit */ - public function testAddRawData() + public function testAddRawData(): void { $bulk = new Bulk($this->_getClient()); @@ -273,8 +276,11 @@ public function testAddRawData() /** * @group unit * @dataProvider invalidRawDataProvider + * + * @param mixed $rawData + * @param mixed $failMessage */ - public function testInvalidRawData($rawData, $failMessage) + public function testInvalidRawData($rawData, $failMessage): void { $this->expectException(\Elastica\Exception\InvalidException::class); @@ -328,7 +334,7 @@ public function invalidRawDataProvider() /** * @group functional */ - public function testErrorRequest() + public function testErrorRequest(): void { $index = $this->_createIndex(); $client = $index->getClient(); @@ -359,7 +365,7 @@ public function testErrorRequest() /** * @group functional */ - public function testRawDocumentDataRequest() + public function testRawDocumentDataRequest(): void { $index = $this->_createIndex(); $client = $index->getClient(); @@ -401,7 +407,7 @@ public function testRawDocumentDataRequest() /** * @group functional */ - public function testUpdate() + public function testUpdate(): void { $index = $this->_createIndex(); $client = $index->getClient(); @@ -535,7 +541,7 @@ public function testUpdate() /** * @group functional */ - public function testUpsert() + public function testUpsert(): void { $index = $this->_createIndex(); $client = $index->getClient(); @@ -583,7 +589,7 @@ public function testUpsert() /** * @group unit */ - public function testGetPath() + public function testGetPath(): void { $client = $this->_getClient(); $bulk = new Bulk($client); @@ -599,7 +605,7 @@ public function testGetPath() /** * @group functional */ - public function testRetry() + public function testRetry(): void { $index = $this->_createIndex(); $client = $index->getClient(); @@ -631,7 +637,7 @@ public function testRetry() /** * @group unit */ - public function testSetShardTimeout() + public function testSetShardTimeout(): void { $bulk = new Bulk($this->_getClient()); $this->assertInstanceOf(Bulk::class, $bulk->setShardTimeout(10)); @@ -640,7 +646,7 @@ public function testSetShardTimeout() /** * @group unit */ - public function testSetRequestParam() + public function testSetRequestParam(): void { $bulk = new Bulk($this->_getClient()); $this->assertInstanceOf(Bulk::class, $bulk->setRequestParam('key', 'value')); @@ -649,7 +655,7 @@ public function testSetRequestParam() /** * @group benchmark */ - public function testMemoryUsage() + public function testMemoryUsage(): void { $index = $this->_createIndex(); @@ -682,7 +688,7 @@ public function testMemoryUsage() /** * @group unit */ - public function testHasIndex() + public function testHasIndex(): void { $client = $this->_getClient(); $bulk = new Bulk($client); diff --git a/tests/ClientConfigurationTest.php b/tests/ClientConfigurationTest.php index 4fc9754f3b..44d7459d9a 100644 --- a/tests/ClientConfigurationTest.php +++ b/tests/ClientConfigurationTest.php @@ -7,10 +7,12 @@ /** * @group unit + * + * @internal */ class ClientConfigurationTest extends TestCase { - public function testInvalidDsn() + public function testInvalidDsn(): void { $this->expectException(\Elastica\Exception\InvalidException::class); $this->expectExceptionMessage("DSN 'test:0' is invalid."); @@ -18,7 +20,7 @@ public function testInvalidDsn() ClientConfiguration::fromDsn('test:0'); } - public function testFromSimpleDsn() + public function testFromSimpleDsn(): void { $configuration = ClientConfiguration::fromDsn('192.168.1.1:9201'); @@ -42,7 +44,7 @@ public function testFromSimpleDsn() $this->assertEquals($expected, $configuration->getAll()); } - public function testFromDsnWithParameters() + public function testFromDsnWithParameters(): void { $configuration = ClientConfiguration::fromDsn('https://user:p4ss@foo.com:9201/my-path?proxy=https://proxy.com&persistent=false&timeout=45&roundRobin=true&retryOnConflict=2&bigintConversion=true&extra=abc'); $expected = [ @@ -66,7 +68,7 @@ public function testFromDsnWithParameters() $this->assertEquals($expected, $configuration->getAll()); } - public function testFromEmptyArray() + public function testFromEmptyArray(): void { $configuration = ClientConfiguration::fromArray([]); @@ -90,7 +92,7 @@ public function testFromEmptyArray() $this->assertEquals($expected, $configuration->getAll()); } - public function testFromArray() + public function testFromArray(): void { $configuration = ClientConfiguration::fromArray([ 'username' => 'Jdoe', @@ -118,14 +120,14 @@ public function testFromArray() $this->assertEquals($expected, $configuration->getAll()); } - public function testHas() + public function testHas(): void { $configuration = new ClientConfiguration(); $this->assertTrue($configuration->has('host')); $this->assertFalse($configuration->has('inexistantKey')); } - public function testGet() + public function testGet(): void { $configuration = new ClientConfiguration(); $this->assertTrue($configuration->get('persistent')); @@ -153,7 +155,7 @@ public function testGet() $configuration->get('invalidKey'); } - public function testAdd() + public function testAdd(): void { $keyName = 'myKey'; diff --git a/tests/ClientFunctionalTest.php b/tests/ClientFunctionalTest.php index 54df8caa61..136ce58ff2 100644 --- a/tests/ClientFunctionalTest.php +++ b/tests/ClientFunctionalTest.php @@ -22,6 +22,8 @@ /** * @group functional + * + * @internal */ class ClientFunctionalTest extends BaseTest { @@ -63,17 +65,20 @@ public function testConnectionsArray(): void $index->create([], true); // Adds 1 document to the index - $doc1 = new Document(1, + $doc1 = new Document( + 1, ['username' => 'hans', 'test' => ['2', '3', '5']] ); $index->addDocument($doc1); // Adds a list of documents with _bulk upload to the index $docs = []; - $docs[] = new Document(2, + $docs[] = new Document( + 2, ['username' => 'john', 'test' => ['1', '3', '6']] ); - $docs[] = new Document(3, + $docs[] = new Document( + 3, ['username' => 'rolf', 'test' => ['2', '3', '7']] ); $index->addDocuments($docs); @@ -95,17 +100,20 @@ public function testTwoServersSame(): void $index->create([], true); // Adds 1 document to the index - $doc1 = new Document(1, + $doc1 = new Document( + 1, ['username' => 'hans', 'test' => ['2', '3', '5']] ); $index->addDocument($doc1); // Adds a list of documents with _bulk upload to the index $docs = []; - $docs[] = new Document(2, + $docs[] = new Document( + 2, ['username' => 'john', 'test' => ['1', '3', '6']] ); - $docs[] = new Document(3, + $docs[] = new Document( + 3, ['username' => 'rolf', 'test' => ['2', '3', '7']] ); $index->addDocuments($docs); @@ -376,7 +384,7 @@ public function testCallback(): void $count = 0; // Callback function which verifies that disabled connection objects are returned - $callback = function (Connection $connection, \Exception $exception, Client $client) use (&$count) { + $callback = function (Connection $connection, \Exception $exception, Client $client) use (&$count): void { $this->assertInstanceOf(Connection::class, $connection); $this->assertInstanceOf(ConnectionException::class, $exception); $this->assertInstanceOf(Client::class, $client); @@ -853,7 +861,8 @@ public function testLogger(): void $this->arrayHasKey('response'), $this->arrayHasKey('responseStatus') ) - ); + ) + ; $client->request('_stats', Request::GET); } @@ -878,7 +887,8 @@ public function testLoggerOnFailure(): void $this->arrayHasKey('retry'), $this->logicalNot($this->arrayHasKey('response')) ) - ); + ) + ; $client->request('_stats', Request::GET); } @@ -949,6 +959,9 @@ public function testEndpointParamsRequest(): void /** * @dataProvider endpointQueryRequestDataProvider + * + * @param mixed $query + * @param mixed $totalHits */ public function testEndpointQueryRequest($query, $totalHits): void { diff --git a/tests/ClientTest.php b/tests/ClientTest.php index c622e23618..41f6c1347f 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -9,6 +9,8 @@ /** * @group unit + * + * @internal */ class ClientTest extends BaseTest { diff --git a/tests/Cluster/Health/IndexTest.php b/tests/Cluster/Health/IndexTest.php index 779d45ebeb..092cd83157 100644 --- a/tests/Cluster/Health/IndexTest.php +++ b/tests/Cluster/Health/IndexTest.php @@ -6,6 +6,9 @@ use Elastica\Cluster\Health\Shard; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class IndexTest extends BaseTest { /** @@ -13,7 +16,7 @@ class IndexTest extends BaseTest */ protected $_index; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -60,7 +63,7 @@ protected function setUp() /** * @group unit */ - public function testGetName() + public function testGetName(): void { $this->assertEquals('test', $this->_index->getName()); } @@ -68,7 +71,7 @@ public function testGetName() /** * @group unit */ - public function testGetStatus() + public function testGetStatus(): void { $this->assertEquals('yellow', $this->_index->getStatus()); } @@ -76,7 +79,7 @@ public function testGetStatus() /** * @group unit */ - public function testGetNumberOfShards() + public function testGetNumberOfShards(): void { $this->assertEquals(1, $this->_index->getNumberOfShards()); } @@ -84,7 +87,7 @@ public function testGetNumberOfShards() /** * @group unit */ - public function testGetNumberOfReplicas() + public function testGetNumberOfReplicas(): void { $this->assertEquals(2, $this->_index->getNumberOfReplicas()); } @@ -92,7 +95,7 @@ public function testGetNumberOfReplicas() /** * @group unit */ - public function testGetActivePrimaryShards() + public function testGetActivePrimaryShards(): void { $this->assertEquals(3, $this->_index->getActivePrimaryShards()); } @@ -100,7 +103,7 @@ public function testGetActivePrimaryShards() /** * @group unit */ - public function testGetActiveShards() + public function testGetActiveShards(): void { $this->assertEquals(4, $this->_index->getActiveShards()); } @@ -108,7 +111,7 @@ public function testGetActiveShards() /** * @group unit */ - public function testGetRelocatingShards() + public function testGetRelocatingShards(): void { $this->assertEquals(5, $this->_index->getRelocatingShards()); } @@ -116,7 +119,7 @@ public function testGetRelocatingShards() /** * @group unit */ - public function testGetInitializingShards() + public function testGetInitializingShards(): void { $this->assertEquals(6, $this->_index->getInitializingShards()); } @@ -124,7 +127,7 @@ public function testGetInitializingShards() /** * @group unit */ - public function testGetUnassignedShards() + public function testGetUnassignedShards(): void { $this->assertEquals(7, $this->_index->getUnassignedShards()); } @@ -132,7 +135,7 @@ public function testGetUnassignedShards() /** * @group unit */ - public function testGetShards() + public function testGetShards(): void { $shards = $this->_index->getShards(); diff --git a/tests/Cluster/Health/ShardTest.php b/tests/Cluster/Health/ShardTest.php index 9f1b5cc877..26fc5ac400 100644 --- a/tests/Cluster/Health/ShardTest.php +++ b/tests/Cluster/Health/ShardTest.php @@ -5,6 +5,9 @@ use Elastica\Cluster\Health\Shard; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class ShardTest extends BaseTest { /** @@ -12,7 +15,7 @@ class ShardTest extends BaseTest */ protected $_shard; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -31,7 +34,7 @@ protected function setUp() /** * @group unit */ - public function testGetShardNumber() + public function testGetShardNumber(): void { $this->assertEquals(2, $this->_shard->getShardNumber()); } @@ -39,7 +42,7 @@ public function testGetShardNumber() /** * @group unit */ - public function testGetStatus() + public function testGetStatus(): void { $this->assertEquals('red', $this->_shard->getStatus()); } @@ -47,7 +50,7 @@ public function testGetStatus() /** * @group unit */ - public function testisPrimaryActive() + public function testisPrimaryActive(): void { $this->assertTrue($this->_shard->isPrimaryActive()); } @@ -55,7 +58,7 @@ public function testisPrimaryActive() /** * @group unit */ - public function testIsActive() + public function testIsActive(): void { $this->assertTrue($this->_shard->isActive()); } @@ -63,7 +66,7 @@ public function testIsActive() /** * @group unit */ - public function testIsRelocating() + public function testIsRelocating(): void { $this->assertFalse($this->_shard->isRelocating()); } @@ -71,7 +74,7 @@ public function testIsRelocating() /** * @group unit */ - public function testIsInitialized() + public function testIsInitialized(): void { $this->assertFalse($this->_shard->isInitialized()); } @@ -79,7 +82,7 @@ public function testIsInitialized() /** * @group unit */ - public function testIsUnassigned() + public function testIsUnassigned(): void { $this->assertTrue($this->_shard->isUnassigned()); } diff --git a/tests/Cluster/HealthTest.php b/tests/Cluster/HealthTest.php index d87819ab47..b4346ceec5 100644 --- a/tests/Cluster/HealthTest.php +++ b/tests/Cluster/HealthTest.php @@ -6,6 +6,9 @@ use Elastica\Cluster\Health\Index; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class HealthTest extends BaseTest { /** @@ -13,7 +16,7 @@ class HealthTest extends BaseTest */ protected $_health; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -46,12 +49,14 @@ protected function setUp() ->getMockBuilder(Health::class) ->setConstructorArgs([$this->_getClient()]) ->setMethods(['_retrieveHealthData']) - ->getMock(); + ->getMock() + ; $health ->expects($this->any()) ->method('_retrieveHealthData') - ->will($this->returnValue($data)); + ->will($this->returnValue($data)) + ; // need to explicitly refresh because the mocking won't refresh the data in the constructor $health->refresh(); @@ -62,7 +67,7 @@ protected function setUp() /** * @group unit */ - public function testGetClusterName() + public function testGetClusterName(): void { $this->assertEquals('test_cluster', $this->_health->getClusterName()); } @@ -70,7 +75,7 @@ public function testGetClusterName() /** * @group unit */ - public function testGetStatus() + public function testGetStatus(): void { $this->assertEquals('green', $this->_health->getStatus()); } @@ -78,7 +83,7 @@ public function testGetStatus() /** * @group unit */ - public function testGetTimedOut() + public function testGetTimedOut(): void { $this->assertFalse($this->_health->getTimedOut()); } @@ -86,7 +91,7 @@ public function testGetTimedOut() /** * @group unit */ - public function testGetNumberOfNodes() + public function testGetNumberOfNodes(): void { $this->assertEquals(10, $this->_health->getNumberOfNodes()); } @@ -94,7 +99,7 @@ public function testGetNumberOfNodes() /** * @group unit */ - public function testGetNumberOfDataNodes() + public function testGetNumberOfDataNodes(): void { $this->assertEquals(8, $this->_health->getNumberOfDataNodes()); } @@ -102,7 +107,7 @@ public function testGetNumberOfDataNodes() /** * @group unit */ - public function testGetActivePrimaryShards() + public function testGetActivePrimaryShards(): void { $this->assertEquals(3, $this->_health->getActivePrimaryShards()); } @@ -110,7 +115,7 @@ public function testGetActivePrimaryShards() /** * @group unit */ - public function testGetActiveShards() + public function testGetActiveShards(): void { $this->assertEquals(4, $this->_health->getActiveShards()); } @@ -118,7 +123,7 @@ public function testGetActiveShards() /** * @group unit */ - public function testGetRelocatingShards() + public function testGetRelocatingShards(): void { $this->assertEquals(2, $this->_health->getRelocatingShards()); } @@ -126,7 +131,7 @@ public function testGetRelocatingShards() /** * @group unit */ - public function testGetInitializingShards() + public function testGetInitializingShards(): void { $this->assertEquals(7, $this->_health->getInitializingShards()); } @@ -134,7 +139,7 @@ public function testGetInitializingShards() /** * @group unit */ - public function testGetUnassignedShards() + public function testGetUnassignedShards(): void { $this->assertEquals(5, $this->_health->getUnassignedShards()); } @@ -142,7 +147,7 @@ public function testGetUnassignedShards() /** * @group unit */ - public function testGetDelayedUnassignedShards() + public function testGetDelayedUnassignedShards(): void { $this->assertEquals(4, $this->_health->getDelayedUnassignedShards()); } @@ -150,7 +155,7 @@ public function testGetDelayedUnassignedShards() /** * @group unit */ - public function testNumberOfPendingTasks() + public function testNumberOfPendingTasks(): void { $this->assertEquals(1, $this->_health->getNumberOfPendingTasks()); } @@ -158,7 +163,7 @@ public function testNumberOfPendingTasks() /** * @group unit */ - public function testNumberOfInFlightFetch() + public function testNumberOfInFlightFetch(): void { $this->assertEquals(2, $this->_health->getNumberOfInFlightFetch()); } @@ -166,7 +171,7 @@ public function testNumberOfInFlightFetch() /** * @group unit */ - public function testTaskMaxWaitingInQueueMillis() + public function testTaskMaxWaitingInQueueMillis(): void { $this->assertEquals(634, $this->_health->getTaskMaxWaitingInQueueMillis()); } @@ -174,7 +179,7 @@ public function testTaskMaxWaitingInQueueMillis() /** * @group unit */ - public function testActiveShardsPercentAsNumber() + public function testActiveShardsPercentAsNumber(): void { $this->assertEquals(50, $this->_health->getActiveShardsPercentAsNumber()); } @@ -182,7 +187,7 @@ public function testActiveShardsPercentAsNumber() /** * @group unit */ - public function testGetIndices() + public function testGetIndices(): void { $indices = $this->_health->getIndices(); diff --git a/tests/Cluster/SettingsTest.php b/tests/Cluster/SettingsTest.php index eb39a8e9e3..d86cb03fde 100644 --- a/tests/Cluster/SettingsTest.php +++ b/tests/Cluster/SettingsTest.php @@ -7,12 +7,15 @@ use Elastica\Exception\ResponseException; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class SettingsTest extends BaseTest { /** * @group functional */ - public function testSetTransient() + public function testSetTransient(): void { $index = $this->_createIndex(); @@ -34,7 +37,7 @@ public function testSetTransient() /** * @group functional */ - public function testSetPersistent() + public function testSetPersistent(): void { $index = $this->_createIndex(); @@ -56,7 +59,7 @@ public function testSetPersistent() /** * @group functional */ - public function testSetReadOnly() + public function testSetReadOnly(): void { // Create two indices to check that the complete cluster is read only $settings = new Settings($this->_getClient()); diff --git a/tests/ClusterTest.php b/tests/ClusterTest.php index 6f8a7c0c57..66cdd528be 100644 --- a/tests/ClusterTest.php +++ b/tests/ClusterTest.php @@ -8,6 +8,8 @@ /** * @group functional + * + * @internal */ class ClusterTest extends BaseTest { diff --git a/tests/Collapse/CollapseTest.php b/tests/Collapse/CollapseTest.php index a7c94d0968..564cca1061 100644 --- a/tests/Collapse/CollapseTest.php +++ b/tests/Collapse/CollapseTest.php @@ -9,73 +9,15 @@ use Elastica\Query; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class CollapseTest extends BaseTest { - private function _getIndexForCollapseTest() - { - $index = $this->_createIndex(); - $index->setMapping(new Mapping([ - 'user' => ['type' => 'keyword'], - 'message' => ['type' => 'text'], - 'date' => ['type' => 'date'], - 'likes' => ['type' => 'integer'], - 'zip' => ['type' => 'keyword'], - ])); - - $index->addDocuments([ - new Document(1, [ - 'user' => 'Veronica', - 'message' => 'Always keeping an eye on elasticsearch.', - 'date' => '2019-08-15', - 'likes' => 10, - 'zip' => '07', - ]), - new Document(2, [ - 'user' => 'Wallace', - 'message' => 'Elasticsearch DevOps is awesome!', - 'date' => '2019-08-05', - 'likes' => 50, - 'zip' => '06', - ]), - new Document(3, [ - 'user' => 'Logan', - 'message' => 'Can I find my lost stuff on elasticsearch?', - 'date' => '2019-08-02', - 'likes' => 1, - 'zip' => '09', - ]), - new Document(4, [ - 'user' => 'Keith', - 'message' => 'Investigating again.', - 'date' => '2019-08-10', - 'likes' => 30, - 'zip' => '07', - ]), - new Document(5, [ - 'user' => 'Veronica', - 'message' => 'Finding out new stuff.', - 'date' => '2019-08-01', - 'likes' => 20, - 'zip' => '07', - ]), - new Document(6, [ - 'user' => 'Wallace', - 'message' => 'Baller.', - 'date' => '2019-08-15', - 'likes' => 20, - 'zip' => '06', - ]), - ]); - - $index->refresh(); - - return $index; - } - /** * @group unit */ - public function testSetFieldName() + public function testSetFieldName(): void { $collapse = new Collapse(); $returnValue = $collapse->setFieldname('some_name'); @@ -86,7 +28,7 @@ public function testSetFieldName() /** * @group unit */ - public function testSetInnerHits() + public function testSetInnerHits(): void { $collapse = new Collapse(); $innerHits = new InnerHits(); @@ -99,7 +41,7 @@ public function testSetInnerHits() /** * @group unit */ - public function testSetMaxConcurrentGroupSearches() + public function testSetMaxConcurrentGroupSearches(): void { $collapse = new Collapse(); $returnValue = $collapse->setMaxConcurrentGroupSearches(5); @@ -110,7 +52,7 @@ public function testSetMaxConcurrentGroupSearches() /** * @group unit */ - public function testAddInnerHits() + public function testAddInnerHits(): void { $collapse = new Collapse(); @@ -132,7 +74,7 @@ public function testAddInnerHits() /** * @group unit */ - public function testSetThenAddInnerHits() + public function testSetThenAddInnerHits(): void { $collapse = new Collapse(); @@ -154,7 +96,7 @@ public function testSetThenAddInnerHits() /** * @group unit */ - public function testSetInnerHitsOverridesExistingValue() + public function testSetInnerHitsOverridesExistingValue(): void { $collapse = new Collapse(); @@ -184,7 +126,7 @@ public function testSetInnerHitsOverridesExistingValue() /** * @group functional */ - public function testCollapseField() + public function testCollapseField(): void { $query = new Query(); $query->setSource(false); @@ -215,7 +157,7 @@ public function testCollapseField() /** * @group functional */ - public function testCollapseWithInnerHits() + public function testCollapseWithInnerHits(): void { $query = new Query(); $query->setSource(false); @@ -238,16 +180,20 @@ public function testCollapseWithInnerHits() $this->assertEquals('1', $results->getResults()[0]->getId()); $this->assertEquals('Veronica', $results->getResults()[0]->getData()['user'][0]); $this->assertEquals('2', $results->getResults()[0]->getInnerHits()['last_tweets']['hits']['total']['value']); - $this->assertEquals('Finding out new stuff.', - $results->getResults()[0]->getInnerHits()['last_tweets']['hits']['hits'][0]['_source']['message']); - $this->assertEquals('Always keeping an eye on elasticsearch.', - $results->getResults()[0]->getInnerHits()['last_tweets']['hits']['hits'][1]['_source']['message']); + $this->assertEquals( + 'Finding out new stuff.', + $results->getResults()[0]->getInnerHits()['last_tweets']['hits']['hits'][0]['_source']['message'] + ); + $this->assertEquals( + 'Always keeping an eye on elasticsearch.', + $results->getResults()[0]->getInnerHits()['last_tweets']['hits']['hits'][1]['_source']['message'] + ); } /** * @group functional */ - public function testCollapseWithMultipleInnerHits() + public function testCollapseWithMultipleInnerHits(): void { $query = new Query(); $query->setSource(false); @@ -277,22 +223,30 @@ public function testCollapseWithMultipleInnerHits() $this->assertEquals('Veronica', $results->getResults()[0]->getData()['user'][0]); $this->assertEquals('2', $results->getResults()[0]->getInnerHits()['most_liked']['hits']['total']['value']); - $this->assertEquals('Always keeping an eye on elasticsearch.', - $results->getResults()[0]->getInnerHits()['most_liked']['hits']['hits'][0]['_source']['message']); - $this->assertEquals('Finding out new stuff.', - $results->getResults()[0]->getInnerHits()['most_liked']['hits']['hits'][1]['_source']['message']); + $this->assertEquals( + 'Always keeping an eye on elasticsearch.', + $results->getResults()[0]->getInnerHits()['most_liked']['hits']['hits'][0]['_source']['message'] + ); + $this->assertEquals( + 'Finding out new stuff.', + $results->getResults()[0]->getInnerHits()['most_liked']['hits']['hits'][1]['_source']['message'] + ); $this->assertEquals('2', $results->getResults()[0]->getInnerHits()['most_recent']['hits']['total']['value']); - $this->assertEquals('Finding out new stuff.', - $results->getResults()[0]->getInnerHits()['most_recent']['hits']['hits'][0]['_source']['message']); - $this->assertEquals('Always keeping an eye on elasticsearch.', - $results->getResults()[0]->getInnerHits()['most_recent']['hits']['hits'][1]['_source']['message']); + $this->assertEquals( + 'Finding out new stuff.', + $results->getResults()[0]->getInnerHits()['most_recent']['hits']['hits'][0]['_source']['message'] + ); + $this->assertEquals( + 'Always keeping an eye on elasticsearch.', + $results->getResults()[0]->getInnerHits()['most_recent']['hits']['hits'][1]['_source']['message'] + ); } /** * @group functional */ - public function testSecondLevelCollapsing() + public function testSecondLevelCollapsing(): void { $query = new Query(); $query->setSource(false); @@ -323,6 +277,67 @@ public function testSecondLevelCollapsing() $this->assertEquals('Keith', $results->getResults()[0]->getInnerHits()['by_zip']['hits']['hits'][1]['fields']['user'][0]); } + private function _getIndexForCollapseTest() + { + $index = $this->_createIndex(); + $index->setMapping(new Mapping([ + 'user' => ['type' => 'keyword'], + 'message' => ['type' => 'text'], + 'date' => ['type' => 'date'], + 'likes' => ['type' => 'integer'], + 'zip' => ['type' => 'keyword'], + ])); + + $index->addDocuments([ + new Document(1, [ + 'user' => 'Veronica', + 'message' => 'Always keeping an eye on elasticsearch.', + 'date' => '2019-08-15', + 'likes' => 10, + 'zip' => '07', + ]), + new Document(2, [ + 'user' => 'Wallace', + 'message' => 'Elasticsearch DevOps is awesome!', + 'date' => '2019-08-05', + 'likes' => 50, + 'zip' => '06', + ]), + new Document(3, [ + 'user' => 'Logan', + 'message' => 'Can I find my lost stuff on elasticsearch?', + 'date' => '2019-08-02', + 'likes' => 1, + 'zip' => '09', + ]), + new Document(4, [ + 'user' => 'Keith', + 'message' => 'Investigating again.', + 'date' => '2019-08-10', + 'likes' => 30, + 'zip' => '07', + ]), + new Document(5, [ + 'user' => 'Veronica', + 'message' => 'Finding out new stuff.', + 'date' => '2019-08-01', + 'likes' => 20, + 'zip' => '07', + ]), + new Document(6, [ + 'user' => 'Wallace', + 'message' => 'Baller.', + 'date' => '2019-08-15', + 'likes' => 20, + 'zip' => '06', + ]), + ]); + + $index->refresh(); + + return $index; + } + /** * @return \Elastica\ResultSet */ diff --git a/tests/Connection/ConnectionPoolTest.php b/tests/Connection/ConnectionPoolTest.php index 3cdbb18051..aa09b92bf6 100644 --- a/tests/Connection/ConnectionPoolTest.php +++ b/tests/Connection/ConnectionPoolTest.php @@ -9,13 +9,15 @@ /** * @author chabior + * + * @internal */ class ConnectionPoolTest extends BaseTest { /** * @group unit */ - public function testConstruct() + public function testConstruct(): void { $pool = $this->createPool(); @@ -25,7 +27,7 @@ public function testConstruct() /** * @group unit */ - public function testSetConnections() + public function testSetConnections(): void { $pool = $this->createPool(); @@ -41,7 +43,7 @@ public function testSetConnections() /** * @group unit */ - public function testAddConnection() + public function testAddConnection(): void { $pool = $this->createPool(); $pool->setConnections([]); @@ -60,7 +62,7 @@ public function testAddConnection() /** * @group unit */ - public function testHasConnection() + public function testHasConnection(): void { $pool = $this->createPool(); @@ -70,7 +72,7 @@ public function testHasConnection() /** * @group unit */ - public function testFailHasConnections() + public function testFailHasConnections(): void { $pool = $this->createPool(); diff --git a/tests/Connection/Strategy/CallbackStrategyTest.php b/tests/Connection/Strategy/CallbackStrategyTest.php index ad50f608a9..ccac761777 100644 --- a/tests/Connection/Strategy/CallbackStrategyTest.php +++ b/tests/Connection/Strategy/CallbackStrategyTest.php @@ -10,13 +10,15 @@ * Description of CallbackStrategyTest. * * @author chabior + * + * @internal */ class CallbackStrategyTest extends Base { /** * @group unit */ - public function testInvoke() + public function testInvoke(): void { $count = 0; @@ -36,7 +38,7 @@ public function testInvoke() /** * @group functional */ - public function testConnection() + public function testConnection(): void { $count = 0; diff --git a/tests/Connection/Strategy/RoundRobinTest.php b/tests/Connection/Strategy/RoundRobinTest.php index f9f8c788b0..b15d661ed0 100644 --- a/tests/Connection/Strategy/RoundRobinTest.php +++ b/tests/Connection/Strategy/RoundRobinTest.php @@ -13,6 +13,8 @@ * Description of RoundRobinTest. * * @author chabior + * + * @internal */ class RoundRobinTest extends Base { @@ -24,7 +26,7 @@ class RoundRobinTest extends Base /** * @group functional */ - public function testConnection() + public function testConnection(): void { $config = ['connectionStrategy' => 'RoundRobin']; $client = $this->_getClient($config); @@ -39,7 +41,7 @@ public function testConnection() /** * @group unit */ - public function testOldStrategySet() + public function testOldStrategySet(): void { $config = ['roundRobin' => true]; $client = $this->_getClient($config); @@ -50,7 +52,7 @@ public function testOldStrategySet() /** * @group functional */ - public function testFailConnection() + public function testFailConnection(): void { $this->expectException(\Elastica\Exception\ConnectionException::class); @@ -65,7 +67,7 @@ public function testFailConnection() /** * @group functional */ - public function testWithOneFailConnection() + public function testWithOneFailConnection(): void { $connections = [ new Connection(['host' => '255.255.255.0', 'timeout' => $this->_timeout]), @@ -73,7 +75,7 @@ public function testWithOneFailConnection() ]; $count = 0; - $callback = function ($connection, $exception, $client) use (&$count) { + $callback = function ($connection, $exception, $client) use (&$count): void { ++$count; }; @@ -93,7 +95,7 @@ public function testWithOneFailConnection() /** * @group functional */ - public function testWithNoValidConnection() + public function testWithNoValidConnection(): void { $connections = [ new Connection(['host' => '255.255.255.0', 'timeout' => $this->_timeout]), @@ -102,7 +104,7 @@ public function testWithNoValidConnection() ]; $count = 0; - $client = $this->_getClient(['roundRobin' => true], function () use (&$count) { + $client = $this->_getClient(['roundRobin' => true], function () use (&$count): void { ++$count; }); @@ -117,14 +119,14 @@ public function testWithNoValidConnection() } } - protected function _checkStrategy(Client $client) + protected function _checkStrategy(Client $client): void { $strategy = $client->getConnectionStrategy(); $this->assertInstanceOf(RoundRobin::class, $strategy); } - protected function _checkResponse(Response $response) + protected function _checkResponse(Response $response): void { $this->assertTrue($response->isOk()); } diff --git a/tests/Connection/Strategy/SimpleTest.php b/tests/Connection/Strategy/SimpleTest.php index a3a52fa2dd..40b5035daa 100644 --- a/tests/Connection/Strategy/SimpleTest.php +++ b/tests/Connection/Strategy/SimpleTest.php @@ -13,6 +13,8 @@ * Description of SimplyTest. * * @author chabior + * + * @internal */ class SimpleTest extends Base { @@ -24,7 +26,7 @@ class SimpleTest extends Base /** * @group functional */ - public function testConnection() + public function testConnection(): void { $client = $this->_getClient(); $response = $client->request('_aliases'); @@ -37,7 +39,7 @@ public function testConnection() /** * @group functional */ - public function testFailConnection() + public function testFailConnection(): void { $this->expectException(\Elastica\Exception\ConnectionException::class); @@ -52,7 +54,7 @@ public function testFailConnection() /** * @group functional */ - public function testWithOneFailConnection() + public function testWithOneFailConnection(): void { $connections = [ new Connection(['host' => '255.255.255.0', 'timeout' => $this->_timeout]), @@ -60,7 +62,7 @@ public function testWithOneFailConnection() ]; $count = 0; - $callback = function ($connection, $exception, $client) use (&$count) { + $callback = function ($connection, $exception, $client) use (&$count): void { ++$count; }; @@ -80,7 +82,7 @@ public function testWithOneFailConnection() /** * @group functional */ - public function testWithNoValidConnection() + public function testWithNoValidConnection(): void { $connections = [ new Connection(['host' => '255.255.255.0', 'timeout' => $this->_timeout]), @@ -89,7 +91,7 @@ public function testWithNoValidConnection() ]; $count = 0; - $client = $this->_getClient([], function () use (&$count) { + $client = $this->_getClient([], function () use (&$count): void { ++$count; }); @@ -103,14 +105,14 @@ public function testWithNoValidConnection() } } - protected function _checkStrategy(Client $client) + protected function _checkStrategy(Client $client): void { $strategy = $client->getConnectionStrategy(); $this->assertInstanceOf(Simple::class, $strategy); } - protected function _checkResponse(Response $response) + protected function _checkResponse(Response $response): void { $this->assertTrue($response->isOk()); } diff --git a/tests/Connection/Strategy/StrategyFactoryTest.php b/tests/Connection/Strategy/StrategyFactoryTest.php index 019cbdd088..3deccb99a0 100644 --- a/tests/Connection/Strategy/StrategyFactoryTest.php +++ b/tests/Connection/Strategy/StrategyFactoryTest.php @@ -11,15 +11,17 @@ * Description of StrategyFactoryTest. * * @author chabior + * + * @internal */ class StrategyFactoryTest extends Base { /** * @group unit */ - public function testCreateCallbackStrategy() + public function testCreateCallbackStrategy(): void { - $callback = function ($connections) { + $callback = function ($connections): void { }; $strategy = StrategyFactory::create($callback); @@ -30,7 +32,7 @@ public function testCreateCallbackStrategy() /** * @group unit */ - public function testCreateByName() + public function testCreateByName(): void { $strategyName = 'Simple'; @@ -42,7 +44,7 @@ public function testCreateByName() /** * @group unit */ - public function testCreateByClass() + public function testCreateByClass(): void { $strategy = new EmptyStrategy(); @@ -52,7 +54,7 @@ public function testCreateByClass() /** * @group unit */ - public function testCreateByClassName() + public function testCreateByClassName(): void { $strategy = StrategyFactory::create(EmptyStrategy::class); @@ -62,7 +64,7 @@ public function testCreateByClassName() /** * @group unit */ - public function testFailCreate() + public function testFailCreate(): void { $this->expectException(\InvalidArgumentException::class); @@ -74,7 +76,7 @@ public function testFailCreate() /** * @group unit */ - public function testNoCollisionWithGlobalNamespace() + public function testNoCollisionWithGlobalNamespace(): void { // create collision if (!\class_exists('Simple')) { diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index f2fe62e072..1c00f6d7e4 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -9,12 +9,15 @@ use Elastica\Transport\AbstractTransport; use Elastica\Transport\Http; +/** + * @internal + */ class ConnectionTest extends BaseTest { /** * @group unit */ - public function testEmptyConstructor() + public function testEmptyConstructor(): void { $connection = new Connection(); $this->assertEquals(Connection::DEFAULT_HOST, $connection->getHost()); @@ -30,7 +33,7 @@ public function testEmptyConstructor() /** * @group unit */ - public function testEnabledDisable() + public function testEnabledDisable(): void { $connection = new Connection(); $this->assertTrue($connection->isEnabled()); @@ -43,7 +46,7 @@ public function testEnabledDisable() /** * @group unit */ - public function testInvalidConnection() + public function testInvalidConnection(): void { $this->expectException(\Elastica\Exception\ConnectionException::class); @@ -59,7 +62,7 @@ public function testInvalidConnection() /** * @group unit */ - public function testCreate() + public function testCreate(): void { $connection = Connection::create(); $this->assertInstanceOf(Connection::class, $connection); @@ -76,7 +79,7 @@ public function testCreate() /** * @group unit */ - public function testCreateInvalid() + public function testCreateInvalid(): void { $this->expectException(\Elastica\Exception\InvalidException::class); @@ -86,7 +89,7 @@ public function testCreateInvalid() /** * @group unit */ - public function testGetConfig() + public function testGetConfig(): void { $url = 'test'; $connection = new Connection(['config' => ['url' => $url]]); @@ -97,7 +100,7 @@ public function testGetConfig() /** * @group unit */ - public function testGetConfigWithArrayUsedForTransport() + public function testGetConfigWithArrayUsedForTransport(): void { $connection = new Connection(['transport' => ['type' => 'Http']]); $this->assertInstanceOf(Http::class, $connection->getTransportObject()); @@ -106,7 +109,7 @@ public function testGetConfigWithArrayUsedForTransport() /** * @group unit */ - public function testGetInvalidConfigWithArrayUsedForTransport() + public function testGetInvalidConfigWithArrayUsedForTransport(): void { $this->expectException(\Elastica\Exception\InvalidException::class); $this->expectExceptionMessage('Invalid transport'); @@ -118,7 +121,7 @@ public function testGetInvalidConfigWithArrayUsedForTransport() /** * @group unit */ - public function testGetConfigInvalidValue() + public function testGetConfigInvalidValue(): void { $this->expectException(\Elastica\Exception\InvalidException::class); @@ -129,7 +132,7 @@ public function testGetConfigInvalidValue() /** * @group unit */ - public function testCompression() + public function testCompression(): void { $connection = new Connection(); @@ -141,7 +144,7 @@ public function testCompression() /** * @group unit */ - public function testCompressionDefaultWithClient() + public function testCompressionDefaultWithClient(): void { $client = new Client(); $connection = $client->getConnection(); @@ -151,7 +154,7 @@ public function testCompressionDefaultWithClient() /** * @group unit */ - public function testCompressionEnabledWithClient() + public function testCompressionEnabledWithClient(): void { $client = new Client(['connections' => [['compression' => true]]]); $connection = $client->getConnection(); @@ -162,7 +165,7 @@ public function testCompressionEnabledWithClient() /** * @group unit */ - public function testUsernameFromClient() + public function testUsernameFromClient(): void { $username = 'foo'; $client = new Client(['username' => $username]); @@ -173,7 +176,7 @@ public function testUsernameFromClient() /** * @group unit */ - public function testPasswordFromClient() + public function testPasswordFromClient(): void { $password = 'bar'; $client = new Client(['password' => $password]); diff --git a/tests/DeprecatedClassBase.php b/tests/DeprecatedClassBase.php index 45f9ddb432..483d13a88d 100644 --- a/tests/DeprecatedClassBase.php +++ b/tests/DeprecatedClassBase.php @@ -9,13 +9,13 @@ */ class DeprecatedClassBase extends Base { - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->hideDeprecated(); } - protected function tearDown() + protected function tearDown(): void { $this->showDeprecated(); parent::tearDown(); diff --git a/tests/DocumentTest.php b/tests/DocumentTest.php index 1dc1bc82db..b18e1406a9 100644 --- a/tests/DocumentTest.php +++ b/tests/DocumentTest.php @@ -7,12 +7,15 @@ use Elastica\Index; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class DocumentTest extends BaseTest { /** * @group unit */ - public function testAddFile() + public function testAddFile(): void { $fileName = '/dev/null'; if (!\file_exists($fileName)) { @@ -26,7 +29,7 @@ public function testAddFile() /** * @group unit */ - public function testAddGeoPoint() + public function testAddGeoPoint(): void { $doc = new Document(); $returnValue = $doc->addGeoPoint('point', 38.89859, -77.035971); @@ -36,7 +39,7 @@ public function testAddGeoPoint() /** * @group unit */ - public function testSetData() + public function testSetData(): void { $doc = new Document(); $returnValue = $doc->setData(['data']); @@ -46,7 +49,7 @@ public function testSetData() /** * @group unit */ - public function testToArray() + public function testToArray(): void { $id = '17'; $data = ['hello' => 'world']; @@ -65,7 +68,7 @@ public function testToArray() /** * @group unit */ - public function testSetIndex() + public function testSetIndex(): void { $document = new Document(); $document->setIndex('index2'); @@ -81,7 +84,7 @@ public function testSetIndex() /** * @group unit */ - public function testHasId() + public function testHasId(): void { $document = new Document(); $this->assertFalse($document->hasId()); @@ -96,7 +99,7 @@ public function testHasId() /** * @group unit */ - public function testGetSetHasRefresh() + public function testGetSetHasRefresh(): void { $document = new Document(); $this->assertFalse($document->hasRefresh()); @@ -120,7 +123,7 @@ public function testGetSetHasRefresh() /** * @group unit */ - public function testGetOptions() + public function testGetOptions(): void { $document = new Document(); $document->setIndex('index'); @@ -146,7 +149,7 @@ public function testGetOptions() /** * @group unit */ - public function testGetSetHasRemove() + public function testGetSetHasRemove(): void { $document = new Document(1, ['field1' => 'value1', 'field2' => 'value2', 'field3' => 'value3', 'field4' => null]); @@ -200,7 +203,7 @@ public function testGetSetHasRemove() /** * @group unit */ - public function testDataPropertiesOverloading() + public function testDataPropertiesOverloading(): void { $document = new Document(1, ['field1' => 'value1', 'field2' => 'value2', 'field3' => 'value3', 'field4' => null]); @@ -252,7 +255,7 @@ public function testDataPropertiesOverloading() /** * @group unit */ - public function testSerializedData() + public function testSerializedData(): void { $data = '{"user":"rolf"}'; $document = new Document(1, $data); @@ -284,7 +287,7 @@ public function testSerializedData() /** * @group unit */ - public function testUpsert() + public function testUpsert(): void { $document = new Document(); @@ -302,7 +305,7 @@ public function testUpsert() /** * @group unit */ - public function testDocAsUpsert() + public function testDocAsUpsert(): void { $document = new Document(); diff --git a/tests/ErrorsCollector.php b/tests/ErrorsCollector.php index c2bc0d62c4..3716d32724 100644 --- a/tests/ErrorsCollector.php +++ b/tests/ErrorsCollector.php @@ -23,7 +23,7 @@ public function __construct(?TestCase $testCase = null) $this->testCase = $testCase; } - public function add($error) + public function add($error): void { $this->errors[] = $error; } @@ -33,14 +33,14 @@ public function getCount() return \count($this->errors); } - public function assertOnlyOneDeprecatedError($deprecationMessage) + public function assertOnlyOneDeprecatedError($deprecationMessage): void { $this->testCase->assertSame(1, $this->getCount()); $this->testCase->assertSame(1, $this->getDeprecatedCount()); $this->testCase->assertSame($deprecationMessage, $this->getMessage(0)); } - public function assertOnlyDeprecatedErrors(array $deprecationMessages) + public function assertOnlyDeprecatedErrors(array $deprecationMessages): void { $this->testCase->assertSame(\count($deprecationMessages), $this->getCount()); $this->testCase->assertSame(\count($deprecationMessages), $this->getDeprecatedCount()); diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php index b46f79d47c..c45957561a 100644 --- a/tests/ExampleTest.php +++ b/tests/ExampleTest.php @@ -7,13 +7,15 @@ /** * Tests the example code. + * + * @internal */ class ExampleTest extends BaseTest { /** * @group functional */ - public function testBasicGettingStarted() + public function testBasicGettingStarted(): void { $client = $this->_getClient(); $index = $client->getIndex('ruflin'); @@ -28,7 +30,7 @@ public function testBasicGettingStarted() /** * @group functional */ - public function testExample() + public function testExample(): void { // Creates a new index 'xodoa' and a type 'user' inside this index $client = $this->_getClient(); diff --git a/tests/Exception/AbstractExceptionTest.php b/tests/Exception/AbstractExceptionTest.php index e57372d3ff..bba69c8782 100644 --- a/tests/Exception/AbstractExceptionTest.php +++ b/tests/Exception/AbstractExceptionTest.php @@ -7,27 +7,25 @@ abstract class AbstractExceptionTest extends BaseTest { - protected function _getExceptionClass() - { - $reflection = new \ReflectionObject($this); - - // Elastica\Test\Exception\RuntimeExceptionTest => Elastica\Exception\RuntimeExceptionTest - $name = \preg_replace('/^Elastica\\\\Test/', 'Elastica', $reflection->getName()); - - // Elastica\Exception\RuntimeExceptionTest => Elastica\Exception\RuntimeException - $name = \preg_replace('/Test$/', '', $name); - - return $name; - } - /** * @group unit */ - public function testInheritance() + public function testInheritance(): void { $className = $this->_getExceptionClass(); $reflection = new \ReflectionClass($className); $this->assertTrue($reflection->isSubclassOf(\Exception::class)); $this->assertTrue($reflection->implementsInterface(ExceptionInterface::class)); } + + protected function _getExceptionClass() + { + $reflection = new \ReflectionObject($this); + + // Elastica\Test\Exception\RuntimeExceptionTest => Elastica\Exception\RuntimeExceptionTest + $name = \preg_replace('/^Elastica\\\\Test/', 'Elastica', $reflection->getName()); + + // Elastica\Exception\RuntimeExceptionTest => Elastica\Exception\RuntimeException + return \preg_replace('/Test$/', '', $name); + } } diff --git a/tests/Exception/Bulk/Response/ActionExceptionTest.php b/tests/Exception/Bulk/Response/ActionExceptionTest.php index 184e1ba207..4d3a45aa56 100644 --- a/tests/Exception/Bulk/Response/ActionExceptionTest.php +++ b/tests/Exception/Bulk/Response/ActionExceptionTest.php @@ -4,6 +4,9 @@ use Elastica\Test\Exception\AbstractExceptionTest; +/** + * @internal + */ class ActionExceptionTest extends AbstractExceptionTest { } diff --git a/tests/Exception/Bulk/ResponseExceptionTest.php b/tests/Exception/Bulk/ResponseExceptionTest.php index 7da6657b07..3b5d6b3ecc 100644 --- a/tests/Exception/Bulk/ResponseExceptionTest.php +++ b/tests/Exception/Bulk/ResponseExceptionTest.php @@ -4,6 +4,9 @@ use Elastica\Test\Exception\AbstractExceptionTest; +/** + * @internal + */ class ResponseExceptionTest extends AbstractExceptionTest { } diff --git a/tests/Exception/BulkExceptionTest.php b/tests/Exception/BulkExceptionTest.php index 0374eb42a6..703e2d87f6 100644 --- a/tests/Exception/BulkExceptionTest.php +++ b/tests/Exception/BulkExceptionTest.php @@ -2,6 +2,9 @@ namespace Elastica\Test\Exception; +/** + * @internal + */ class BulkExceptionTest extends AbstractExceptionTest { } diff --git a/tests/Exception/ClientExceptionTest.php b/tests/Exception/ClientExceptionTest.php index 06e8d45b11..95fe0c644d 100644 --- a/tests/Exception/ClientExceptionTest.php +++ b/tests/Exception/ClientExceptionTest.php @@ -2,6 +2,9 @@ namespace Elastica\Test\Exception; +/** + * @internal + */ class ClientExceptionTest extends AbstractExceptionTest { } diff --git a/tests/Exception/Connection/GuzzleExceptionTest.php b/tests/Exception/Connection/GuzzleExceptionTest.php index c4c15816ce..3416df8f38 100644 --- a/tests/Exception/Connection/GuzzleExceptionTest.php +++ b/tests/Exception/Connection/GuzzleExceptionTest.php @@ -4,9 +4,12 @@ use Elastica\Test\Exception\AbstractExceptionTest; +/** + * @internal + */ class GuzzleExceptionTest extends AbstractExceptionTest { - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { if (!\class_exists('GuzzleHttp\\Client')) { self::markTestSkipped('guzzlehttp/guzzle package should be installed to run guzzle transport tests'); diff --git a/tests/Exception/Connection/HttpExceptionTest.php b/tests/Exception/Connection/HttpExceptionTest.php index 701d6770c8..5b3747316b 100644 --- a/tests/Exception/Connection/HttpExceptionTest.php +++ b/tests/Exception/Connection/HttpExceptionTest.php @@ -4,6 +4,9 @@ use Elastica\Test\Exception\AbstractExceptionTest; +/** + * @internal + */ class HttpExceptionTest extends AbstractExceptionTest { } diff --git a/tests/Exception/ConnectionExceptionTest.php b/tests/Exception/ConnectionExceptionTest.php index e7aeb61fba..895d29ae91 100644 --- a/tests/Exception/ConnectionExceptionTest.php +++ b/tests/Exception/ConnectionExceptionTest.php @@ -2,6 +2,9 @@ namespace Elastica\Test\Exception; +/** + * @internal + */ class ConnectionExceptionTest extends AbstractExceptionTest { } diff --git a/tests/Exception/InvalidExceptionTest.php b/tests/Exception/InvalidExceptionTest.php index 0b35a579fb..b29732ef38 100644 --- a/tests/Exception/InvalidExceptionTest.php +++ b/tests/Exception/InvalidExceptionTest.php @@ -2,6 +2,9 @@ namespace Elastica\Test\Exception; +/** + * @internal + */ class InvalidExceptionTest extends AbstractExceptionTest { } diff --git a/tests/Exception/JSONParseExceptionTest.php b/tests/Exception/JSONParseExceptionTest.php index c6ba7d825d..3d36de7622 100644 --- a/tests/Exception/JSONParseExceptionTest.php +++ b/tests/Exception/JSONParseExceptionTest.php @@ -2,6 +2,9 @@ namespace Elastica\Test\Exception; +/** + * @internal + */ class JSONParseExceptionTest extends AbstractExceptionTest { } diff --git a/tests/Exception/NotFoundExceptionTest.php b/tests/Exception/NotFoundExceptionTest.php index c85bdb7a43..4461729d5d 100644 --- a/tests/Exception/NotFoundExceptionTest.php +++ b/tests/Exception/NotFoundExceptionTest.php @@ -2,6 +2,9 @@ namespace Elastica\Test\Exception; +/** + * @internal + */ class NotFoundExceptionTest extends AbstractExceptionTest { } diff --git a/tests/Exception/NotImplementedExceptionTest.php b/tests/Exception/NotImplementedExceptionTest.php index c04dc3c6ba..a8db701b64 100644 --- a/tests/Exception/NotImplementedExceptionTest.php +++ b/tests/Exception/NotImplementedExceptionTest.php @@ -4,12 +4,15 @@ use Elastica\Exception\NotImplementedException; +/** + * @internal + */ class NotImplementedExceptionTest extends AbstractExceptionTest { /** * @group unit */ - public function testInstance() + public function testInstance(): void { $code = 4; $message = 'Hello world'; diff --git a/tests/Exception/PartialShardFailureExceptionTest.php b/tests/Exception/PartialShardFailureExceptionTest.php index cab2bda564..5b4c21f8b7 100644 --- a/tests/Exception/PartialShardFailureExceptionTest.php +++ b/tests/Exception/PartialShardFailureExceptionTest.php @@ -8,12 +8,15 @@ use Elastica\Query; use Elastica\ResultSet\DefaultBuilder; +/** + * @internal + */ class PartialShardFailureExceptionTest extends AbstractExceptionTest { /** * @group functional */ - public function testPartialFailure() + public function testPartialFailure(): void { $client = $this->_getClient(); $index = $client->getIndex('elastica_partial_failure'); @@ -23,9 +26,11 @@ public function testPartialFailure() 'index' => [ 'number_of_shards' => 5, 'number_of_replicas' => 0, - ], ], - ], true); + ], + ], + true + ); $index->addDocument(new Document('', ['name' => 'ruflin'])); $index->addDocument(new Document('', ['name' => 'bobrik'])); diff --git a/tests/Exception/QueryBuilderExceptionTest.php b/tests/Exception/QueryBuilderExceptionTest.php index e38afa2230..168e766d89 100644 --- a/tests/Exception/QueryBuilderExceptionTest.php +++ b/tests/Exception/QueryBuilderExceptionTest.php @@ -2,6 +2,9 @@ namespace Elastica\Test\Exception; +/** + * @internal + */ class QueryBuilderExceptionTest extends AbstractExceptionTest { } diff --git a/tests/Exception/ResponseExceptionTest.php b/tests/Exception/ResponseExceptionTest.php index 4150075428..50ea32e65a 100644 --- a/tests/Exception/ResponseExceptionTest.php +++ b/tests/Exception/ResponseExceptionTest.php @@ -6,12 +6,15 @@ use Elastica\Exception\ResponseException; use Elastica\Mapping; +/** + * @internal + */ class ResponseExceptionTest extends AbstractExceptionTest { /** * @group functional */ - public function testCreateExistingIndex() + public function testCreateExistingIndex(): void { $this->_createIndex('woo', true); @@ -30,7 +33,7 @@ public function testCreateExistingIndex() /** * @group functional */ - public function testBadType() + public function testBadType(): void { $index = $this->_createIndex(); @@ -55,7 +58,7 @@ public function testBadType() /** * @group functional */ - public function testWhatever() + public function testWhatever(): void { $index = $this->_createIndex(); $index->delete(); diff --git a/tests/Exception/RuntimeExceptionTest.php b/tests/Exception/RuntimeExceptionTest.php index 2f08a3818d..fd5c3cd5f7 100644 --- a/tests/Exception/RuntimeExceptionTest.php +++ b/tests/Exception/RuntimeExceptionTest.php @@ -2,6 +2,9 @@ namespace Elastica\Test\Exception; +/** + * @internal + */ class RuntimeExceptionTest extends AbstractExceptionTest { } diff --git a/tests/Index/RecoveryTest.php b/tests/Index/RecoveryTest.php index bb6b6d5710..b7d015f5bf 100644 --- a/tests/Index/RecoveryTest.php +++ b/tests/Index/RecoveryTest.php @@ -5,12 +5,15 @@ use Elastica\Index\Recovery; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class RecoveryTest extends BaseTest { /** * @group functional */ - public function testGetSettings() + public function testGetSettings(): void { $indexName = 'test'; diff --git a/tests/Index/SettingsTest.php b/tests/Index/SettingsTest.php index b2690ecfb9..226b759f5e 100644 --- a/tests/Index/SettingsTest.php +++ b/tests/Index/SettingsTest.php @@ -9,12 +9,15 @@ use Elastica\Response; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class SettingsTest extends BaseTest { /** * @group functional */ - public function testGet() + public function testGet(): void { $indexName = 'elasticatest'; @@ -35,7 +38,7 @@ public function testGet() /** * @group functional */ - public function testGetWithAlias() + public function testGetWithAlias(): void { $indexName = 'elasticatest'; $aliasName = 'elasticatest_alias'; @@ -61,7 +64,7 @@ public function testGetWithAlias() /** * @group functional */ - public function testDeleteAliasWithException() + public function testDeleteAliasWithException(): void { $indexName = 'deletetestaliasexception'; $aliasName = 'deletetestaliasexception_alias'; @@ -88,7 +91,7 @@ public function testDeleteAliasWithException() /** * @group functional */ - public function testSetGetNumberOfReplicas() + public function testSetGetNumberOfReplicas(): void { $index = $this->_createIndex(); $index->create([], true); @@ -112,7 +115,7 @@ public function testSetGetNumberOfReplicas() /** * @group functional */ - public function testGetNumberOfReplicas() + public function testGetNumberOfReplicas(): void { $index = $this->_createIndex(); $index->create([], true); @@ -129,7 +132,7 @@ public function testGetNumberOfReplicas() /** * @group functional */ - public function testGetNumberOfShards() + public function testGetNumberOfShards(): void { $index = $this->_createIndex(); $index->create([], true); @@ -146,7 +149,7 @@ public function testGetNumberOfShards() /** * @group functional */ - public function testGetDefaultNumberOfShards() + public function testGetDefaultNumberOfShards(): void { $index = $this->_createIndex(); $index->create([], true); @@ -164,7 +167,7 @@ public function testGetDefaultNumberOfShards() /** * @group functional */ - public function testSetRefreshInterval() + public function testSetRefreshInterval(): void { $index = $this->_createIndex(); $index->create([], true); @@ -185,7 +188,7 @@ public function testSetRefreshInterval() /** * @group functional */ - public function testGetRefreshInterval() + public function testGetRefreshInterval(): void { $index = $this->_createIndex(); $index->create([], true); @@ -206,7 +209,7 @@ public function testGetRefreshInterval() /** * @group functional */ - public function testSetMergePolicy() + public function testSetMergePolicy(): void { $index = $this->_createIndex(); $index->create([], true); @@ -227,7 +230,7 @@ public function testSetMergePolicy() /** * @group functional */ - public function testSetMaxMergeAtOnce() + public function testSetMaxMergeAtOnce(): void { $index = $this->_createIndex(); $index->create([], true); @@ -251,7 +254,7 @@ public function testSetMaxMergeAtOnce() /** * @group functional */ - public function testSetReadOnly() + public function testSetReadOnly(): void { $index = $this->_createIndex(); //wait for the shards to be allocated @@ -296,7 +299,7 @@ public function testSetReadOnly() /** * @group functional */ - public function testGetSetBlocksRead() + public function testGetSetBlocksRead(): void { $index = $this->_createIndex(); $index->refresh(); @@ -319,7 +322,7 @@ public function testGetSetBlocksRead() /** * @group functional */ - public function testGetSetBlocksWrite() + public function testGetSetBlocksWrite(): void { $index = $this->_createIndex(); $index->refresh(); @@ -342,7 +345,7 @@ public function testGetSetBlocksWrite() /** * @group functional */ - public function testGetSetBlocksMetadata() + public function testGetSetBlocksMetadata(): void { $index = $this->_createIndex(); $index->refresh(); @@ -367,7 +370,7 @@ public function testGetSetBlocksMetadata() /** * @group functional */ - public function testNotFoundIndex() + public function testNotFoundIndex(): void { $client = $this->_getClient(); $index = $client->getIndex('not_found_index'); @@ -385,7 +388,7 @@ public function testNotFoundIndex() /** * @group functional */ - public function testSetMultiple() + public function testSetMultiple(): void { $index = $this->_createIndex(); $index->create([], true); diff --git a/tests/Index/StatsTest.php b/tests/Index/StatsTest.php index ccda2d7959..1236ce6936 100644 --- a/tests/Index/StatsTest.php +++ b/tests/Index/StatsTest.php @@ -5,12 +5,15 @@ use Elastica\Index\Stats; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class StatsTest extends BaseTest { /** * @group functional */ - public function testGetSettings() + public function testGetSettings(): void { $indexName = 'test'; diff --git a/tests/IndexTemplateTest.php b/tests/IndexTemplateTest.php index bef28b7431..beead485e7 100644 --- a/tests/IndexTemplateTest.php +++ b/tests/IndexTemplateTest.php @@ -13,13 +13,15 @@ * IndexTemplate class tests. * * @author Dmitry Balabka + * + * @internal */ class IndexTemplateTest extends BaseTest { /** * @group unit */ - public function testInstantiate() + public function testInstantiate(): void { $name = 'index_template1'; $client = $this->_getClient(); @@ -32,7 +34,7 @@ public function testInstantiate() /** * @group unit */ - public function testIncorrectInstantiate() + public function testIncorrectInstantiate(): void { $this->expectException(\Elastica\Exception\InvalidException::class); @@ -43,16 +45,17 @@ public function testIncorrectInstantiate() /** * @group unit */ - public function testDelete() + public function testDelete(): void { $name = 'index_template1'; $response = new Response(''); - /** @var \PHPUnit_Framework_MockObject_MockObject|Client $clientMock */ + /** @var Client|\PHPUnit_Framework_MockObject_MockObject $clientMock */ $clientMock = $this->createMock(Client::class); $clientMock->expects($this->once()) ->method('request') ->with('_template/'.$name, Request::DELETE, [], []) - ->willReturn($response); + ->willReturn($response) + ; $indexTemplate = new IndexTemplate($clientMock, $name); $this->assertSame($response, $indexTemplate->delete()); } @@ -60,17 +63,18 @@ public function testDelete() /** * @group unit */ - public function testCreate() + public function testCreate(): void { $args = [1]; $response = new Response(''); $name = 'index_template1'; - /** @var \PHPUnit_Framework_MockObject_MockObject|Client $clientMock */ + /** @var Client|\PHPUnit_Framework_MockObject_MockObject $clientMock */ $clientMock = $this->createMock(Client::class); $clientMock->expects($this->once()) ->method('request') ->with('_template/'.$name, Request::PUT, $args, []) - ->willReturn($response); + ->willReturn($response) + ; $indexTemplate = new IndexTemplate($clientMock, $name); $this->assertSame($response, $indexTemplate->create($args)); } @@ -78,16 +82,17 @@ public function testCreate() /** * @group unit */ - public function testExists() + public function testExists(): void { $name = 'index_template1'; $response = new Response('', 200); - /** @var \PHPUnit_Framework_MockObject_MockObject|Client $clientMock */ + /** @var Client|\PHPUnit_Framework_MockObject_MockObject $clientMock */ $clientMock = $this->createMock(Client::class); $clientMock->expects($this->once()) ->method('request') ->with('_template/'.$name, Request::HEAD, [], []) - ->willReturn($response); + ->willReturn($response) + ; $indexTemplate = new IndexTemplate($clientMock, $name); $this->assertTrue($indexTemplate->exists()); } @@ -95,7 +100,7 @@ public function testExists() /** * @group functional */ - public function testCreateTemplate() + public function testCreateTemplate(): void { $template = [ 'index_patterns' => 'te*', @@ -114,7 +119,7 @@ public function testCreateTemplate() /** * @group functional */ - public function testCreateAlreadyExistsTemplateException() + public function testCreateAlreadyExistsTemplateException(): void { $template = [ 'index_patterns' => 'te*', diff --git a/tests/IndexTest.php b/tests/IndexTest.php index 7d6b9c4514..8aceb07c7f 100644 --- a/tests/IndexTest.php +++ b/tests/IndexTest.php @@ -18,6 +18,8 @@ /** * @group functional + * + * @internal */ class IndexTest extends BaseTest { diff --git a/tests/JSONTest.php b/tests/JSONTest.php index 3ce7ee4691..c0962126bd 100644 --- a/tests/JSONTest.php +++ b/tests/JSONTest.php @@ -9,16 +9,18 @@ * JSONTest. * * @author Oleg Andreyev + * + * @internal */ class JSONTest extends TestCase { - public function testStringifyMustNotThrowExceptionOnValid() + public function testStringifyMustNotThrowExceptionOnValid(): void { JSON::stringify([]); $this->assertTrue(true); } - public function testStringifyMustThrowExceptionNanOrInf() + public function testStringifyMustThrowExceptionNanOrInf(): void { $this->expectException(\Elastica\Exception\JSONParseException::class); $this->expectExceptionMessage('Inf and NaN cannot be JSON encoded'); @@ -28,7 +30,7 @@ public function testStringifyMustThrowExceptionNanOrInf() $this->assertTrue(true); } - public function testStringifyMustThrowExceptionMaximumDepth() + public function testStringifyMustThrowExceptionMaximumDepth(): void { $this->expectException(\Elastica\Exception\JSONParseException::class); $this->expectExceptionMessage('Maximum stack depth exceeded'); diff --git a/tests/MappingTest.php b/tests/MappingTest.php index ec2c949b7d..b3fef5a9ab 100644 --- a/tests/MappingTest.php +++ b/tests/MappingTest.php @@ -8,12 +8,15 @@ use Elastica\Query\QueryString; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class MappingTest extends BaseTest { /** * @group functional */ - public function testMappingStoreFields() + public function testMappingStoreFields(): void { $client = $this->_getClient(); $index = $client->getIndex('test'); @@ -30,7 +33,8 @@ public function testMappingStoreFields() $index->setMapping($mapping); $firstname = 'Nicolas'; - $doc = new Document(1, + $doc = new Document( + 1, [ 'firstname' => $firstname, 'lastname' => 'Ruflin', @@ -63,7 +67,7 @@ public function testMappingStoreFields() /** * @group functional */ - public function testNestedMapping() + public function testNestedMapping(): void { $client = $this->_getClient(); $index = $client->getIndex('test'); @@ -103,7 +107,7 @@ public function testNestedMapping() /** * @group functional */ - public function testJoinMapping() + public function testJoinMapping(): void { $client = $this->_getClient(); $index = $client->getIndex('testjoinparentid'); @@ -122,15 +126,15 @@ public function testJoinMapping() $expected = [ 'properties' => [ - 'firstname' => ['type' => 'text', 'store' => true], - 'lastname' => ['type' => 'text'], - 'my_join_field' => [ - 'type' => 'join', - 'relations' => [ - 'question' => 'answer', - ], - ], - ], + 'firstname' => ['type' => 'text', 'store' => true], + 'lastname' => ['type' => 'text'], + 'my_join_field' => [ + 'type' => 'join', + 'relations' => [ + 'question' => 'answer', + ], + ], + ], ]; $this->assertEquals($expected, $mapping->toArray()); @@ -182,7 +186,7 @@ public function testJoinMapping() /** * @group functional */ - public function testMappingExample() + public function testMappingExample(): void { $index = $this->_createIndex(); @@ -198,7 +202,9 @@ public function testMappingExample() $index->setMapping($mapping); - $doc = new Document(1, [ + $doc = new Document( + 1, + [ 'note' => [ [ 'titulo' => 'nota1', @@ -225,7 +231,7 @@ public function testMappingExample() * * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic-templates.html */ - public function testDynamicTemplate() + public function testDynamicTemplate(): void { $index = $this->_createIndex(); @@ -277,7 +283,7 @@ public function testDynamicTemplate() /** * @group functional */ - public function testSetMeta() + public function testSetMeta(): void { $index = $this->_createIndex(); $mapping = new Mapping([ @@ -297,7 +303,7 @@ public function testSetMeta() /** * @group functional */ - public function testGetters() + public function testGetters(): void { $properties = [ 'firstname' => ['type' => 'text', 'store' => true], diff --git a/tests/Multi/MultiBuilderTest.php b/tests/Multi/MultiBuilderTest.php index 752a40298c..642a4690af 100644 --- a/tests/Multi/MultiBuilderTest.php +++ b/tests/Multi/MultiBuilderTest.php @@ -12,6 +12,8 @@ /** * @group unit + * + * @internal */ class MultiBuilderTest extends BaseTest { @@ -25,7 +27,7 @@ class MultiBuilderTest extends BaseTest */ private $multiBuilder; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -33,10 +35,11 @@ protected function setUp() $this->multiBuilder = new MultiBuilder(); } - public function testBuildEmptyMultiResultSet() + public function testBuildEmptyMultiResultSet(): void { $this->builder->expects($this->never()) - ->method('buildResultSet'); + ->method('buildResultSet') + ; $response = new Response([]); $searches = []; @@ -46,7 +49,7 @@ public function testBuildEmptyMultiResultSet() $this->assertInstanceOf(MultiResultSet::class, $result); } - public function testBuildMultiResultSet() + public function testBuildMultiResultSet(): void { $response = new Response([ 'responses' => [ @@ -67,7 +70,8 @@ public function testBuildMultiResultSet() [$this->isInstanceOf(Response::class), $s1->getQuery()], [$this->isInstanceOf(Response::class), $s2->getQuery()] ) - ->willReturnOnConsecutiveCalls($resultSet1, $resultSet2); + ->willReturnOnConsecutiveCalls($resultSet1, $resultSet2) + ; $result = $this->multiBuilder->buildMultiResultSet($response, $searches); diff --git a/tests/Multi/SearchTest.php b/tests/Multi/SearchTest.php index e335a639b8..9463181d8d 100644 --- a/tests/Multi/SearchTest.php +++ b/tests/Multi/SearchTest.php @@ -13,37 +13,15 @@ use Elastica\Search; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class SearchTest extends BaseTest { - protected function _createIndex(?string $name = null, bool $delete = true, int $shards = 1): Index - { - $client = $this->_getClient(); - - $index = $client->getIndex('zero'); - $index->create(['settings' => ['index' => ['number_of_shards' => 1, 'number_of_replicas' => 0]]], true); - - $docs = []; - $docs[] = new Document(1, ['id' => 1, 'email' => 'test@test.com', 'username' => 'farrelley']); - $docs[] = new Document(2, ['id' => 1, 'email' => 'test@test.com', 'username' => 'farrelley']); - $docs[] = new Document(3, ['id' => 1, 'email' => 'test@test.com', 'username' => 'farrelley']); - $docs[] = new Document(4, ['id' => 1, 'email' => 'test@test.com', 'username' => 'kate']); - $docs[] = new Document(5, ['id' => 1, 'email' => 'test@test.com', 'username' => 'kate']); - $docs[] = new Document(6, ['id' => 1, 'email' => 'test@test.com', 'username' => 'bunny']); - $docs[] = new Document(7, ['id' => 1, 'email' => 'test@test.com', 'username' => 'bunny']); - $docs[] = new Document(8, ['id' => 1, 'email' => 'test@test.com', 'username' => 'bunny']); - $docs[] = new Document(9, ['id' => 1, 'email' => 'test@test.com', 'username' => 'bunny']); - $docs[] = new Document(10, ['id' => 1, 'email' => 'test@test.com', 'username' => 'bunny']); - $docs[] = new Document(11, ['id' => 1, 'email' => 'test@test.com', 'username' => 'bunny']); - $index->addDocuments($docs); - $index->refresh(); - - return $index; - } - /** * @group unit */ - public function testConstruct() + public function testConstruct(): void { $client = $this->_getClient(); $multiSearch = new MultiSearch($client); @@ -54,7 +32,7 @@ public function testConstruct() /** * @group unit */ - public function testSetSearches() + public function testSetSearches(): void { $client = $this->_getClient(); $multiSearch = new MultiSearch($client); @@ -86,7 +64,7 @@ public function testSetSearches() /** * @group unit */ - public function testSetSearchesByKeys() + public function testSetSearchesByKeys(): void { $client = $this->_getClient(); $multiSearch = new MultiSearch($client); @@ -118,7 +96,7 @@ public function testSetSearchesByKeys() /** * @group functional */ - public function testSearch() + public function testSearch(): void { $index = $this->_createIndex(); $client = $index->getClient(); @@ -208,7 +186,7 @@ public function testSearch() /** * @group functional */ - public function testSearchWithKeys() + public function testSearchWithKeys(): void { $index = $this->_createIndex(); $client = $index->getClient(); @@ -300,7 +278,7 @@ public function testSearchWithKeys() /** * @group functional */ - public function testSearchWithError() + public function testSearchWithError(): void { $index = $this->_createIndex(); $client = $index->getClient(); @@ -345,7 +323,7 @@ public function testSearchWithError() /** * @group functional */ - public function testSearchWithErrorWithKeys() + public function testSearchWithErrorWithKeys(): void { $index = $this->_createIndex(); $client = $index->getClient(); @@ -390,7 +368,7 @@ public function testSearchWithErrorWithKeys() /** * @group functional */ - public function testGlobalSearchTypeSearch() + public function testGlobalSearchTypeSearch(): void { $index = $this->_createIndex(); $client = $index->getClient(); @@ -473,7 +451,7 @@ public function testGlobalSearchTypeSearch() /** * @group functional */ - public function testGlobalSearchTypeSearchWithKeys() + public function testGlobalSearchTypeSearchWithKeys(): void { $index = $this->_createIndex(); $client = $index->getClient(); @@ -557,7 +535,7 @@ public function testGlobalSearchTypeSearchWithKeys() /** * @group functional */ - public function testSearchWithSearchOptions() + public function testSearchWithSearchOptions(): void { $index = $this->_createIndex(); $client = $index->getClient(); @@ -593,4 +571,29 @@ public function testSearchWithSearchOptions() $this->assertEquals(1, $resultSets[0]->getTotalHits()); $this->assertEquals(6, $resultSets[1]->getTotalHits()); } + + protected function _createIndex(?string $name = null, bool $delete = true, int $shards = 1): Index + { + $client = $this->_getClient(); + + $index = $client->getIndex('zero'); + $index->create(['settings' => ['index' => ['number_of_shards' => 1, 'number_of_replicas' => 0]]], true); + + $docs = []; + $docs[] = new Document(1, ['id' => 1, 'email' => 'test@test.com', 'username' => 'farrelley']); + $docs[] = new Document(2, ['id' => 1, 'email' => 'test@test.com', 'username' => 'farrelley']); + $docs[] = new Document(3, ['id' => 1, 'email' => 'test@test.com', 'username' => 'farrelley']); + $docs[] = new Document(4, ['id' => 1, 'email' => 'test@test.com', 'username' => 'kate']); + $docs[] = new Document(5, ['id' => 1, 'email' => 'test@test.com', 'username' => 'kate']); + $docs[] = new Document(6, ['id' => 1, 'email' => 'test@test.com', 'username' => 'bunny']); + $docs[] = new Document(7, ['id' => 1, 'email' => 'test@test.com', 'username' => 'bunny']); + $docs[] = new Document(8, ['id' => 1, 'email' => 'test@test.com', 'username' => 'bunny']); + $docs[] = new Document(9, ['id' => 1, 'email' => 'test@test.com', 'username' => 'bunny']); + $docs[] = new Document(10, ['id' => 1, 'email' => 'test@test.com', 'username' => 'bunny']); + $docs[] = new Document(11, ['id' => 1, 'email' => 'test@test.com', 'username' => 'bunny']); + $index->addDocuments($docs); + $index->refresh(); + + return $index; + } } diff --git a/tests/Node/InfoTest.php b/tests/Node/InfoTest.php index a3f95810eb..81052ba676 100644 --- a/tests/Node/InfoTest.php +++ b/tests/Node/InfoTest.php @@ -6,12 +6,15 @@ use Elastica\Node\Info as NodeInfo; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class InfoTest extends BaseTest { /** * @group functional */ - public function testGet() + public function testGet(): void { $client = $this->_getClient(); $names = $client->getCluster()->getNodeNames(); @@ -35,7 +38,7 @@ public function testGet() /** * @group functional */ - public function testHasPlugin() + public function testHasPlugin(): void { $client = $this->_getClient(); $nodes = $client->getCluster()->getNodes(); @@ -49,7 +52,7 @@ public function testHasPlugin() /** * @group functional */ - public function testGetId() + public function testGetId(): void { $client = $this->_getClient(); $nodes = $client->getCluster()->getNodes(); @@ -68,7 +71,7 @@ public function testGetId() /** * @group functional */ - public function testGetName() + public function testGetName(): void { $client = $this->_getClient(); @@ -85,7 +88,7 @@ public function testGetName() /** * @group functional */ - public function testParams() + public function testParams(): void { $client = $this->_getClient(); diff --git a/tests/NodeTest.php b/tests/NodeTest.php index 1add01eca3..d712214bc2 100644 --- a/tests/NodeTest.php +++ b/tests/NodeTest.php @@ -7,12 +7,15 @@ use Elastica\Node\Stats; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class NodeTest extends BaseTest { /** * @group functional */ - public function testCreateNode() + public function testCreateNode(): void { $client = $this->_getClient(); $names = $client->getCluster()->getNodeNames(); @@ -25,7 +28,7 @@ public function testCreateNode() /** * @group functional */ - public function testGetInfo() + public function testGetInfo(): void { $client = $this->_getClient(); $names = $client->getCluster()->getNodeNames(); @@ -41,7 +44,7 @@ public function testGetInfo() /** * @group functional */ - public function testGetStats() + public function testGetStats(): void { $client = $this->_getClient(); $names = $client->getCluster()->getNodeNames(); @@ -57,7 +60,7 @@ public function testGetStats() /** * @group functional */ - public function testGetName() + public function testGetName(): void { $client = $this->_getClient(); @@ -76,7 +79,7 @@ public function testGetName() /** * @group functional */ - public function testGetId() + public function testGetId(): void { $node = new Node('Elastica', $this->_getClient()); } diff --git a/tests/ParamTest.php b/tests/ParamTest.php index 7460327808..4b5d0f120d 100644 --- a/tests/ParamTest.php +++ b/tests/ParamTest.php @@ -6,12 +6,15 @@ use Elastica\Test\Base as BaseTest; use Elastica\Util; +/** + * @internal + */ class ParamTest extends BaseTest { /** * @group unit */ - public function testToArrayEmpty() + public function testToArrayEmpty(): void { $param = new Param(); $this->assertInstanceOf(Param::class, $param); @@ -21,7 +24,7 @@ public function testToArrayEmpty() /** * @group unit */ - public function testSetParams() + public function testSetParams(): void { $param = new Param(); $params = ['hello' => 'word', 'nicolas' => 'ruflin']; @@ -34,7 +37,7 @@ public function testSetParams() /** * @group unit */ - public function testSetGetParam() + public function testSetGetParam(): void { $param = new Param(); @@ -51,7 +54,7 @@ public function testSetGetParam() /** * @group unit */ - public function testAddParam() + public function testAddParam(): void { $param = new Param(); @@ -67,7 +70,7 @@ public function testAddParam() /** * @group unit */ - public function testAddParam2() + public function testAddParam2(): void { $param = new Param(); @@ -85,7 +88,7 @@ public function testAddParam2() /** * @group unit */ - public function testGetParamInvalid() + public function testGetParamInvalid(): void { $this->expectException(\Elastica\Exception\InvalidException::class); @@ -97,7 +100,7 @@ public function testGetParamInvalid() /** * @group unit */ - public function testHasParam() + public function testHasParam(): void { $param = new Param(); diff --git a/tests/PipelineTest.php b/tests/PipelineTest.php index 3e945ca226..6e6b93e675 100644 --- a/tests/PipelineTest.php +++ b/tests/PipelineTest.php @@ -10,12 +10,15 @@ use Elastica\Processor\Set; use Elastica\Processor\Trim; +/** + * @internal + */ class PipelineTest extends BasePipeline { /** * @group unit */ - public function testProcessor() + public function testProcessor(): void { $trim = new Trim('field1'); $rename = new Rename('foo', 'target.field'); @@ -50,7 +53,7 @@ public function testProcessor() /** * @group functional */ - public function testPipelineCreate() + public function testPipelineCreate(): void { $set = new Set('field4', 333); $trim = new Trim('field1'); @@ -77,7 +80,7 @@ public function testPipelineCreate() /** * @group functional */ - public function testPipelineonIndex() + public function testPipelineonIndex(): void { $set = new Set('foo', 333); @@ -119,7 +122,7 @@ public function testPipelineonIndex() /** * @group functional */ - public function testDeletePipeline() + public function testDeletePipeline(): void { $pipeline = $this->_createPipeline(); try { diff --git a/tests/Processor/AppendTest.php b/tests/Processor/AppendTest.php index 410bbf48a0..32e4a56d7f 100644 --- a/tests/Processor/AppendTest.php +++ b/tests/Processor/AppendTest.php @@ -8,12 +8,15 @@ use Elastica\ResultSet; use Elastica\Test\BasePipeline as BasePipelineTest; +/** + * @internal + */ class AppendTest extends BasePipelineTest { /** * @group unit */ - public function testAppendSingleValue() + public function testAppendSingleValue(): void { $processor = new Append('field1', 'item2'); @@ -30,7 +33,7 @@ public function testAppendSingleValue() /** * @group unit */ - public function testAppendArray() + public function testAppendArray(): void { $processor = new Append('field1', ['item2', 'item3', 'item4']); @@ -47,7 +50,7 @@ public function testAppendArray() /** * @group functional */ - public function testAppend() + public function testAppend(): void { $append = new Append('foo', ['item2', 'item3', 'item4']); diff --git a/tests/Processor/AttachmentTest.php b/tests/Processor/AttachmentTest.php index ef006d82d7..47cca66a4e 100644 --- a/tests/Processor/AttachmentTest.php +++ b/tests/Processor/AttachmentTest.php @@ -10,6 +10,8 @@ /** * @group functional + * + * @internal */ class AttachmentTest extends BasePipelineTest { diff --git a/tests/Processor/ConvertTest.php b/tests/Processor/ConvertTest.php index 6bbecb870e..94b2122b5e 100644 --- a/tests/Processor/ConvertTest.php +++ b/tests/Processor/ConvertTest.php @@ -8,12 +8,15 @@ use Elastica\ResultSet; use Elastica\Test\BasePipeline as BasePipelineTest; +/** + * @internal + */ class ConvertTest extends BasePipelineTest { /** * @group unit */ - public function testConvert() + public function testConvert(): void { $processor = new Convert('foo', 'integer'); @@ -30,7 +33,7 @@ public function testConvert() /** * @group unit */ - public function testConvertWithNonDefaultOptions() + public function testConvertWithNonDefaultOptions(): void { $processor = new Convert('foo', 'integer'); $processor->setIgnoreMissing(true); @@ -62,7 +65,7 @@ public function testConvertWithNonDefaultOptions() /** * @group functional */ - public function testConvertField() + public function testConvertField(): void { $append = new Convert('foo', 'float'); diff --git a/tests/Processor/DateIndexNameTest.php b/tests/Processor/DateIndexNameTest.php index 1a3d6ec7c3..0fd08d2152 100644 --- a/tests/Processor/DateIndexNameTest.php +++ b/tests/Processor/DateIndexNameTest.php @@ -5,12 +5,15 @@ use Elastica\Processor\DateIndexName; use Elastica\Test\BasePipeline as BasePipelineTest; +/** + * @internal + */ class DateIndexNameTest extends BasePipelineTest { /** * @group unit */ - public function testDateIndexName() + public function testDateIndexName(): void { $processor = new DateIndexName('date1', 'M'); @@ -27,7 +30,7 @@ public function testDateIndexName() /** * @group unit */ - public function testDateIndexNameWithNonDefaultOptions() + public function testDateIndexNameWithNonDefaultOptions(): void { $processor = new DateIndexName('date1', 'M'); $processor->setTimezone('Europe/Rome'); diff --git a/tests/Processor/DateTest.php b/tests/Processor/DateTest.php index 1afa009d4b..e59dc705cf 100644 --- a/tests/Processor/DateTest.php +++ b/tests/Processor/DateTest.php @@ -8,12 +8,15 @@ use Elastica\ResultSet; use Elastica\Test\BasePipeline as BasePipelineTest; +/** + * @internal + */ class DateTest extends BasePipelineTest { /** * @group unit */ - public function testDate() + public function testDate(): void { $processor = new Date('initial_date', ['dd/MM/yyyy hh:mm:ss']); @@ -41,7 +44,7 @@ public function testDate() /** * @group unit */ - public function testDateWithNonDefaultOptions() + public function testDateWithNonDefaultOptions(): void { $processor = new Date('initial_date', ['dd/MM/yyyy hh:mm:ss', 'ISO8601', 'UNIX', 'UNIX_MS']); $processor->setTargetField('timestamp'); @@ -64,7 +67,7 @@ public function testDateWithNonDefaultOptions() /** * @group functional */ - public function testDateField() + public function testDateField(): void { $date = new Date('date_field', ['yyyy dd MM hh:mm:ss']); $date->setTargetField('date_parsed'); diff --git a/tests/Processor/DotExpanderTest.php b/tests/Processor/DotExpanderTest.php index 72a94cb0da..0632a80267 100644 --- a/tests/Processor/DotExpanderTest.php +++ b/tests/Processor/DotExpanderTest.php @@ -8,12 +8,15 @@ use Elastica\ResultSet; use Elastica\Test\BasePipeline as BasePipelineTest; +/** + * @internal + */ class DotExpanderTest extends BasePipelineTest { /** * @group unit */ - public function testDotExpander() + public function testDotExpander(): void { $processor = new DotExpander('foo.bar'); @@ -29,7 +32,7 @@ public function testDotExpander() /** * @group functional */ - public function testDotExpanderField() + public function testDotExpanderField(): void { $dotExpander = new DotExpander('foo.bar'); diff --git a/tests/Processor/FailTest.php b/tests/Processor/FailTest.php index 04071795d5..3cb6732c42 100644 --- a/tests/Processor/FailTest.php +++ b/tests/Processor/FailTest.php @@ -8,12 +8,15 @@ use Elastica\Processor\Json; use Elastica\Test\BasePipeline as BasePipelineTest; +/** + * @internal + */ class FailTest extends BasePipelineTest { /** * @group unit */ - public function testFail() + public function testFail(): void { $processor = new Fail('This is a custom fail message for processor'); @@ -29,7 +32,7 @@ public function testFail() /** * @group functional */ - public function testFailField() + public function testFailField(): void { $fail = new Fail('custom error fail message'); $json = new Json('name'); diff --git a/tests/Processor/JoinTest.php b/tests/Processor/JoinTest.php index a5cc1fadbd..056be2b157 100644 --- a/tests/Processor/JoinTest.php +++ b/tests/Processor/JoinTest.php @@ -8,12 +8,15 @@ use Elastica\ResultSet; use Elastica\Test\BasePipeline as BasePipelineTest; +/** + * @internal + */ class JoinTest extends BasePipelineTest { /** * @group unit */ - public function testJoin() + public function testJoin(): void { $processor = new Join('joined_array_field', '-'); @@ -30,7 +33,7 @@ public function testJoin() /** * @group functional */ - public function testJoinField() + public function testJoinField(): void { $join = new Join('name', '-'); diff --git a/tests/Processor/JsonTest.php b/tests/Processor/JsonTest.php index b82bdb1380..68a9bdd40f 100644 --- a/tests/Processor/JsonTest.php +++ b/tests/Processor/JsonTest.php @@ -8,12 +8,15 @@ use Elastica\ResultSet; use Elastica\Test\BasePipeline as BasePipelineTest; +/** + * @internal + */ class JsonTest extends BasePipelineTest { /** * @group unit */ - public function testJson() + public function testJson(): void { $processor = new Json('string_source'); @@ -29,7 +32,7 @@ public function testJson() /** * @group unit */ - public function testJsonWithNonDefaultOptions() + public function testJsonWithNonDefaultOptions(): void { $processor = new Json('string_source'); $processor->setTargetField('json_target'); @@ -49,7 +52,7 @@ public function testJsonWithNonDefaultOptions() /** * @group functional */ - public function testJsonField() + public function testJsonField(): void { $json = new Json('name'); $json->setTargetField('realname'); diff --git a/tests/Processor/KvTest.php b/tests/Processor/KvTest.php index 67adb325e5..0450cb735b 100644 --- a/tests/Processor/KvTest.php +++ b/tests/Processor/KvTest.php @@ -5,12 +5,15 @@ use Elastica\Processor\Kv; use Elastica\Test\BasePipeline as BasePipelineTest; +/** + * @internal + */ class KvTest extends BasePipelineTest { /** * @group unit */ - public function testKv() + public function testKv(): void { $processor = new Kv('message', ' ', '='); @@ -28,7 +31,7 @@ public function testKv() /** * @group unit */ - public function testKvWithNonDefaultOptions() + public function testKvWithNonDefaultOptions(): void { $processor = new Kv('message', ' ', '='); $processor->setTargetField('target_field'); @@ -54,7 +57,7 @@ public function testKvWithNonDefaultOptions() /** * @group functional */ - public function testKVIncludeExludeKeys() + public function testKVIncludeExludeKeys(): void { $kv = new Kv('field1', '&', '='); $kv->setExcludeKeys(['second']); diff --git a/tests/Processor/LowercaseTest.php b/tests/Processor/LowercaseTest.php index d49635a2c8..bf7f87bdc5 100644 --- a/tests/Processor/LowercaseTest.php +++ b/tests/Processor/LowercaseTest.php @@ -8,12 +8,15 @@ use Elastica\ResultSet; use Elastica\Test\BasePipeline as BasePipelineTest; +/** + * @internal + */ class LowercaseTest extends BasePipelineTest { /** * @group unit */ - public function testLowercase() + public function testLowercase(): void { $processor = new Lowercase('foo'); @@ -29,7 +32,7 @@ public function testLowercase() /** * @group functional */ - public function testLowercaseField() + public function testLowercaseField(): void { $lcase = new Lowercase('name'); diff --git a/tests/Processor/RemoveTest.php b/tests/Processor/RemoveTest.php index 117ca03909..af8e860e1b 100644 --- a/tests/Processor/RemoveTest.php +++ b/tests/Processor/RemoveTest.php @@ -8,12 +8,15 @@ use Elastica\ResultSet; use Elastica\Test\BasePipeline as BasePipelineTest; +/** + * @internal + */ class RemoveTest extends BasePipelineTest { /** * @group unit */ - public function testRemove() + public function testRemove(): void { $processor = new Remove('foo'); @@ -29,7 +32,7 @@ public function testRemove() /** * @group unit */ - public function testRemoveArray() + public function testRemoveArray(): void { $processor = new Remove(['foo', 'bar']); @@ -45,7 +48,7 @@ public function testRemoveArray() /** * @group functional */ - public function testRemoveField() + public function testRemoveField(): void { $remove = new Remove(['es_version', 'package']); diff --git a/tests/Processor/RenameTest.php b/tests/Processor/RenameTest.php index f7a1cc1669..4a5c958927 100644 --- a/tests/Processor/RenameTest.php +++ b/tests/Processor/RenameTest.php @@ -8,12 +8,15 @@ use Elastica\ResultSet; use Elastica\Test\BasePipeline as BasePipelineTest; +/** + * @internal + */ class RenameTest extends BasePipelineTest { /** * @group unit */ - public function testRename() + public function testRename(): void { $processor = new Rename('foo', 'foobar'); @@ -30,7 +33,7 @@ public function testRename() /** * @group unit */ - public function testRenameWithNonDefaultOptions() + public function testRenameWithNonDefaultOptions(): void { $processor = new Rename('foo', 'foobar'); $processor->setIgnoreMissing(true); @@ -49,7 +52,7 @@ public function testRenameWithNonDefaultOptions() /** * @group functional */ - public function testRenameField() + public function testRenameField(): void { $rename = new Rename('package', 'packages'); diff --git a/tests/Processor/SetTest.php b/tests/Processor/SetTest.php index 73200774e9..5ef2ff47c8 100644 --- a/tests/Processor/SetTest.php +++ b/tests/Processor/SetTest.php @@ -8,12 +8,15 @@ use Elastica\ResultSet; use Elastica\Test\BasePipeline as BasePipelineTest; +/** + * @internal + */ class SetTest extends BasePipelineTest { /** * @group unit */ - public function testSet() + public function testSet(): void { $processor = new Set('field1', 582.1); @@ -30,7 +33,7 @@ public function testSet() /** * @group unit */ - public function testSetWithNonDefaultOptions() + public function testSetWithNonDefaultOptions(): void { $processor = new Set('field1', 582.1); $processor->setOverride(false); @@ -49,7 +52,7 @@ public function testSetWithNonDefaultOptions() /** * @group functional */ - public function testSetField() + public function testSetField(): void { $set = new Set('package', 'Elastica'); diff --git a/tests/Processor/SortTest.php b/tests/Processor/SortTest.php index 0166f29d1b..fd96c7ff05 100644 --- a/tests/Processor/SortTest.php +++ b/tests/Processor/SortTest.php @@ -8,12 +8,15 @@ use Elastica\ResultSet; use Elastica\Test\BasePipeline as BasePipelineTest; +/** + * @internal + */ class SortTest extends BasePipelineTest { /** * @group unit */ - public function testSort() + public function testSort(): void { $processor = new Sort('field_to_sort'); @@ -29,7 +32,7 @@ public function testSort() /** * @group unit */ - public function testSortWithNonDefaultOptions() + public function testSortWithNonDefaultOptions(): void { $processor = new Sort('field_to_sort'); $processor->setOrder('desc'); @@ -47,7 +50,7 @@ public function testSortWithNonDefaultOptions() /** * @group functional */ - public function testSortField() + public function testSortField(): void { $sort = new Sort('name'); diff --git a/tests/Processor/SplitTest.php b/tests/Processor/SplitTest.php index 9cc8e7cff7..ab9504b167 100644 --- a/tests/Processor/SplitTest.php +++ b/tests/Processor/SplitTest.php @@ -8,12 +8,15 @@ use Elastica\ResultSet; use Elastica\Test\BasePipeline as BasePipelineTest; +/** + * @internal + */ class SplitTest extends BasePipelineTest { /** * @group unit */ - public function testSplit() + public function testSplit(): void { $processor = new Split('joined_array_field', '-'); @@ -30,7 +33,7 @@ public function testSplit() /** * @group unit */ - public function testSplitWithNonDefaultOptions() + public function testSplitWithNonDefaultOptions(): void { $processor = new Split('joined_array_field', '-'); $processor->setIgnoreMissing(true); @@ -49,7 +52,7 @@ public function testSplitWithNonDefaultOptions() /** * @group functional */ - public function testSplitField() + public function testSplitField(): void { $split = new Split('name', '&'); diff --git a/tests/Processor/TrimTest.php b/tests/Processor/TrimTest.php index 774d366a4a..ccc847edf1 100644 --- a/tests/Processor/TrimTest.php +++ b/tests/Processor/TrimTest.php @@ -8,12 +8,15 @@ use Elastica\ResultSet; use Elastica\Test\BasePipeline as BasePipelineTest; +/** + * @internal + */ class TrimTest extends BasePipelineTest { /** * @group unit */ - public function testTrim() + public function testTrim(): void { $processor = new Trim('foo'); @@ -29,7 +32,7 @@ public function testTrim() /** * @group functional */ - public function testTrimField() + public function testTrimField(): void { $trim = new Trim('name'); diff --git a/tests/Processor/UppercaseTest.php b/tests/Processor/UppercaseTest.php index 2f1d4c9a0f..5f377f7209 100644 --- a/tests/Processor/UppercaseTest.php +++ b/tests/Processor/UppercaseTest.php @@ -8,12 +8,15 @@ use Elastica\ResultSet; use Elastica\Test\BasePipeline as BasePipelineTest; +/** + * @internal + */ class UppercaseTest extends BasePipelineTest { /** * @group unit */ - public function testUppercase() + public function testUppercase(): void { $processor = new Uppercase('foo'); @@ -29,7 +32,7 @@ public function testUppercase() /** * @group functional */ - public function testUppercaseField() + public function testUppercaseField(): void { $ucase = new Uppercase('name'); diff --git a/tests/Query/BoolQueryTest.php b/tests/Query/BoolQueryTest.php index af43c666d3..54a87360a7 100644 --- a/tests/Query/BoolQueryTest.php +++ b/tests/Query/BoolQueryTest.php @@ -9,12 +9,15 @@ use Elastica\Query\Term; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class BoolQueryTest extends BaseTest { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $query = new BoolQuery(); @@ -65,7 +68,7 @@ public function testToArray() * * @group unit */ - public function testToArrayStructure() + public function testToArrayStructure(): void { $boolQuery = new BoolQuery(); @@ -84,7 +87,7 @@ public function testToArrayStructure() /** * @group functional */ - public function testSearch() + public function testSearch(): void { $client = $this->_getClient(); $index = new Index($client, 'test'); @@ -137,7 +140,7 @@ public function testSearch() /** * @group functional */ - public function testEmptyBoolQuery() + public function testEmptyBoolQuery(): void { $index = $this->_createIndex(); diff --git a/tests/Query/BoostingTest.php b/tests/Query/BoostingTest.php index cd3d3a0fd3..f27fd508a2 100644 --- a/tests/Query/BoostingTest.php +++ b/tests/Query/BoostingTest.php @@ -6,12 +6,15 @@ use Elastica\Query\Term; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class BoostingTest extends BaseTest { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $keyword = 'vital'; $negativeKeyword = 'Mercury'; @@ -36,7 +39,7 @@ public function testToArray() /** * @group unit */ - public function testNegativeBoost() + public function testNegativeBoost(): void { $keyword = 'vital'; $negativeKeyword = 'mercury'; diff --git a/tests/Query/CommonTest.php b/tests/Query/CommonTest.php index bb8df9c331..cc6af0ad45 100644 --- a/tests/Query/CommonTest.php +++ b/tests/Query/CommonTest.php @@ -6,12 +6,15 @@ use Elastica\Query\Common; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class CommonTest extends BaseTest { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $query = new Common('body', 'test query', .001); $query->setLowFrequencyOperator(Common::OPERATOR_AND); @@ -32,7 +35,7 @@ public function testToArray() /** * @group functional */ - public function testQuery() + public function testQuery(): void { $index = $this->_createIndex(); @@ -64,7 +67,7 @@ public function testQuery() /** * @group unit */ - public function testSetHighFrequencyOperator() + public function testSetHighFrequencyOperator(): void { $value = 'OPERATOR_TEST'; $query = new Common('body', 'test query', .001); @@ -76,7 +79,7 @@ public function testSetHighFrequencyOperator() /** * @group unit */ - public function testSetBoost() + public function testSetBoost(): void { $value = .02; $query = new Common('body', 'test query', .001); @@ -88,7 +91,7 @@ public function testSetBoost() /** * @group unit */ - public function testSetAnalyzer() + public function testSetAnalyzer(): void { $analyzer = 'standard'; $query = new Common('body', 'test query', .001); diff --git a/tests/Query/ConstantScoreTest.php b/tests/Query/ConstantScoreTest.php index 875028cf7f..bad3883434 100644 --- a/tests/Query/ConstantScoreTest.php +++ b/tests/Query/ConstantScoreTest.php @@ -6,12 +6,15 @@ use Elastica\Query\Ids; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class ConstantScoreTest extends BaseTest { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $query = new ConstantScore(); @@ -34,7 +37,7 @@ public function testToArray() /** * @group unit */ - public function testConstruct() + public function testConstruct(): void { $filter = new Ids(); $filter->setIds([1]); @@ -53,7 +56,7 @@ public function testConstruct() /** * @group unit */ - public function testConstructEmpty() + public function testConstructEmpty(): void { $query = new ConstantScore(); $expectedArray = ['constant_score' => []]; diff --git a/tests/Query/DisMaxTest.php b/tests/Query/DisMaxTest.php index b5079b158f..3e7e7f471c 100644 --- a/tests/Query/DisMaxTest.php +++ b/tests/Query/DisMaxTest.php @@ -8,12 +8,15 @@ use Elastica\Query\QueryString; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class DisMaxTest extends BaseTest { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $query = new DisMax(); @@ -53,7 +56,7 @@ public function testToArray() /** * @group functional */ - public function testQuery() + public function testQuery(): void { $index = $this->_createIndex(); @@ -85,7 +88,7 @@ public function testQuery() /** * @group functional */ - public function testQueryArray() + public function testQueryArray(): void { $index = $this->_createIndex(); @@ -99,8 +102,8 @@ public function testQueryArray() $index->refresh(); $queryString1 = ['query_string' => [ - 'query' => 'Bade*', - ], + 'query' => 'Bade*', + ], ]; $queryString2 = ['query_string' => [ diff --git a/tests/Query/DistanceFeatureTest.php b/tests/Query/DistanceFeatureTest.php index 243b9d61bc..a22e6736bb 100644 --- a/tests/Query/DistanceFeatureTest.php +++ b/tests/Query/DistanceFeatureTest.php @@ -5,12 +5,15 @@ use Elastica\Query\DistanceFeature; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class DistanceFeatureTest extends BaseTest { /** * @group unit */ - public function testToArrayDate() + public function testToArrayDate(): void { $query = new DistanceFeature('field_date', 'now', '7d'); @@ -28,7 +31,7 @@ public function testToArrayDate() /** * @group unit */ - public function testToArrayGeoPoint() + public function testToArrayGeoPoint(): void { $query = new DistanceFeature('field_geo_point', [-71.3, 41.15], '1000m'); @@ -46,7 +49,7 @@ public function testToArrayGeoPoint() /** * @group unit */ - public function testSetBoost() + public function testSetBoost(): void { $query = new DistanceFeature('field_date', 'now', '7d'); $query->setBoost($value = 2.0); diff --git a/tests/Query/EscapeStringTest.php b/tests/Query/EscapeStringTest.php index 50256986a9..2d16bee378 100644 --- a/tests/Query/EscapeStringTest.php +++ b/tests/Query/EscapeStringTest.php @@ -7,18 +7,23 @@ use Elastica\Test\Base as BaseTest; use Elastica\Util; +/** + * @internal + */ class EscapeStringTest extends BaseTest { /** * @group functional */ - public function testSearch() + public function testSearch(): void { $index = $this->_createIndex(); $index->getSettings()->setNumberOfReplicas(0); - $doc = new Document(1, [ - 'email' => 'test@test.com', 'username' => 'test 7/6 123', 'test' => ['2', '3', '5'], ] + $doc = new Document( + 1, + [ + 'email' => 'test@test.com', 'username' => 'test 7/6 123', 'test' => ['2', '3', '5'], ] ); $index->addDocument($doc); diff --git a/tests/Query/ExistsTest.php b/tests/Query/ExistsTest.php index 8445f65b14..42e2ed8d97 100644 --- a/tests/Query/ExistsTest.php +++ b/tests/Query/ExistsTest.php @@ -5,12 +5,15 @@ use Elastica\Query\Exists; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class ExistsTest extends BaseTest { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $field = 'test'; $query = new Exists($field); @@ -22,7 +25,7 @@ public function testToArray() /** * @group unit */ - public function testSetField() + public function testSetField(): void { $field = 'test'; $query = new Exists($field); diff --git a/tests/Query/FunctionScoreTest.php b/tests/Query/FunctionScoreTest.php index be046ee16a..74cc393912 100644 --- a/tests/Query/FunctionScoreTest.php +++ b/tests/Query/FunctionScoreTest.php @@ -10,44 +10,17 @@ use Elastica\Script\Script; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class FunctionScoreTest extends BaseTest { protected $locationOrigin = '32.804654, -117.242594'; - protected function _getIndexForTest() - { - $index = $this->_createIndex(); - $index->setMapping(new Mapping([ - 'name' => ['type' => 'text', 'index' => 'false'], - 'location' => ['type' => 'geo_point'], - 'price' => ['type' => 'float'], - 'popularity' => ['type' => 'integer'], - ])); - - $index->addDocuments([ - new Document(1, [ - 'name' => "Mr. Frostie's", - 'location' => [['lat' => 32.799605, 'lon' => -117.243027], ['lat' => 32.792744, 'lon' => -117.2387341]], - 'price' => 4.5, - 'popularity' => null, - ]), - new Document(2, [ - 'name' => "Miller's Field", - 'location' => ['lat' => 32.795964, 'lon' => -117.255028], - 'price' => 9.5, - 'popularity' => 1, - ]), - ]); - - $index->refresh(); - - return $index; - } - /** * @group unit */ - public function testToArray() + public function testToArray(): void { $priceOrigin = 0; $locationScale = '2mi'; @@ -86,7 +59,7 @@ public function testToArray() /** * @group unit */ - public function testDecayWeight() + public function testDecayWeight(): void { $priceOrigin = 0; $locationScale = '2mi'; @@ -149,7 +122,7 @@ public function testDecayWeight() /** * @group functional */ - public function testGauss() + public function testGauss(): void { $query = new FunctionScore(); $query->addDecayFunction(FunctionScore::DECAY_GAUSS, 'location', $this->locationOrigin, '4mi'); @@ -165,7 +138,7 @@ public function testGauss() /** * @group functional */ - public function testGaussMultiValue() + public function testGaussMultiValue(): void { $query = new FunctionScore(); $query->addDecayFunction( @@ -190,7 +163,7 @@ public function testGaussMultiValue() /** * @group unit */ - public function testAddWeightFunction() + public function testAddWeightFunction(): void { $filter = new Term(['price' => 4.5]); $query = new FunctionScore(); @@ -206,7 +179,7 @@ public function testAddWeightFunction() /** * @group unit */ - public function testLegacyFilterAddWeightFunction() + public function testLegacyFilterAddWeightFunction(): void { $query = new FunctionScore(); $filter = new Term(['price' => 4.5]); @@ -222,7 +195,7 @@ public function testLegacyFilterAddWeightFunction() /** * @group functional */ - public function testWeight() + public function testWeight(): void { $filter = new Term(['price' => 4.5]); $query = new FunctionScore(); @@ -256,7 +229,7 @@ public function testWeight() /** * @group functional */ - public function testWeightWithLegacyFilter() + public function testWeightWithLegacyFilter(): void { $filter = new Term(['price' => 4.5]); $query = new FunctionScore(); @@ -290,7 +263,7 @@ public function testWeightWithLegacyFilter() /** * @group functional */ - public function testRandomScore() + public function testRandomScore(): void { $filter = new Term(['price' => 4.5]); $query = new FunctionScore(); @@ -328,7 +301,7 @@ public function testRandomScore() /** * @group functional */ - public function testRandomScoreWithLegacyFilter() + public function testRandomScoreWithLegacyFilter(): void { $filter = new Term(['price' => 4.5]); $query = new FunctionScore(); @@ -366,7 +339,7 @@ public function testRandomScoreWithLegacyFilter() /** * @group unit */ - public function testRandomScoreWeight() + public function testRandomScoreWeight(): void { $filter = new Term(['price' => 4.5]); $query = new FunctionScore(); @@ -397,7 +370,7 @@ public function testRandomScoreWeight() /** * @group unit */ - public function testRandomScoreWeightWithLegacyFilter() + public function testRandomScoreWeightWithLegacyFilter(): void { $filter = new Term(['price' => 4.5]); $query = new FunctionScore(); @@ -428,7 +401,7 @@ public function testRandomScoreWeightWithLegacyFilter() /** * @group functional */ - public function testRandomScoreWithoutSeed() + public function testRandomScoreWithoutSeed(): void { $query = new FunctionScore(); $query->setRandomScore(); @@ -441,7 +414,7 @@ public function testRandomScoreWithoutSeed() /** * @group functional */ - public function testRandomScoreWithoutField() + public function testRandomScoreWithoutField(): void { $filter = new Term(['price' => 4.5]); $query = new FunctionScore(); @@ -478,7 +451,7 @@ public function testRandomScoreWithoutField() /** * @group functional */ - public function testScriptScore() + public function testScriptScore(): void { $scriptString = "_score * doc['price'].value"; $script = new Script($scriptString, null, Script::LANG_PAINLESS); @@ -512,7 +485,7 @@ public function testScriptScore() /** * @group functional */ - public function testSetMinScore() + public function testSetMinScore(): void { $this->_checkVersion('1.5'); @@ -549,7 +522,7 @@ public function testSetMinScore() /** * @group functional */ - public function testFieldValueFactor() + public function testFieldValueFactor(): void { $this->_checkVersion('1.6'); @@ -579,4 +552,34 @@ public function testFieldValueFactor() $this->assertCount(2, $results); $this->assertEquals(2, $results[0]->getId()); } + + protected function _getIndexForTest() + { + $index = $this->_createIndex(); + $index->setMapping(new Mapping([ + 'name' => ['type' => 'text', 'index' => 'false'], + 'location' => ['type' => 'geo_point'], + 'price' => ['type' => 'float'], + 'popularity' => ['type' => 'integer'], + ])); + + $index->addDocuments([ + new Document(1, [ + 'name' => "Mr. Frostie's", + 'location' => [['lat' => 32.799605, 'lon' => -117.243027], ['lat' => 32.792744, 'lon' => -117.2387341]], + 'price' => 4.5, + 'popularity' => null, + ]), + new Document(2, [ + 'name' => "Miller's Field", + 'location' => ['lat' => 32.795964, 'lon' => -117.255028], + 'price' => 9.5, + 'popularity' => 1, + ]), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Query/FuzzyTest.php b/tests/Query/FuzzyTest.php index aac798358d..d5eab6e757 100644 --- a/tests/Query/FuzzyTest.php +++ b/tests/Query/FuzzyTest.php @@ -7,12 +7,15 @@ use Elastica\Query\Fuzzy; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class FuzzyTest extends BaseTest { /** * @group unit */ - public function testAddField() + public function testAddField(): void { $fuzzy = new Fuzzy(); $fuzzy->setField('user', 'Nicolas'); @@ -28,7 +31,7 @@ public function testAddField() /** * @group unit */ - public function testToArray() + public function testToArray(): void { $fuzzy = new Fuzzy(); @@ -71,7 +74,7 @@ public function testToArray() /** * @group unit */ - public function testNeedSetFieldBeforeOption() + public function testNeedSetFieldBeforeOption(): void { $fuzzy = new Fuzzy(); $this->expectException(InvalidException::class); @@ -82,7 +85,7 @@ public function testNeedSetFieldBeforeOption() /** * @group functional */ - public function testQuery() + public function testQuery(): void { $client = $this->_getClient(); $index = $client->getIndex('test'); @@ -110,7 +113,7 @@ public function testQuery() /** * @group unit */ - public function testResetSingleField() + public function testResetSingleField(): void { $fuzzy = new Fuzzy(); $fuzzy->setField('name', 'value'); @@ -128,7 +131,7 @@ public function testResetSingleField() /** * @group unit */ - public function testOnlySetSingleField() + public function testOnlySetSingleField(): void { $fuzzy = new Fuzzy(); $fuzzy->setField('name', 'value'); diff --git a/tests/Query/GeoBoundingBoxTest.php b/tests/Query/GeoBoundingBoxTest.php index c969623110..c53dee8343 100644 --- a/tests/Query/GeoBoundingBoxTest.php +++ b/tests/Query/GeoBoundingBoxTest.php @@ -5,12 +5,15 @@ use Elastica\Query\GeoBoundingBox; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class GeoBoundingBoxTest extends BaseTest { /** * @group unit */ - public function testAddCoordinates() + public function testAddCoordinates(): void { $key = 'pin.location'; $coords = ['40.73, -74.1', '40.01, -71.12']; @@ -27,7 +30,7 @@ public function testAddCoordinates() /** * @group unit */ - public function testAddCoordinatesInvalidException() + public function testAddCoordinatesInvalidException(): void { $this->expectException(\Elastica\Exception\InvalidException::class); @@ -37,7 +40,7 @@ public function testAddCoordinatesInvalidException() /** * @group unit */ - public function testToArray() + public function testToArray(): void { $key = 'pin.location'; $coords = ['40.73, -74.1', '40.01, -71.12']; diff --git a/tests/Query/GeoDistanceTest.php b/tests/Query/GeoDistanceTest.php index e29c9b2ceb..8ee57cb2ba 100644 --- a/tests/Query/GeoDistanceTest.php +++ b/tests/Query/GeoDistanceTest.php @@ -8,12 +8,15 @@ use Elastica\Query\GeoDistance; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class GeoDistanceTest extends BaseTest { /** * @group functional */ - public function testGeoPoint() + public function testGeoPoint(): void { $index = $this->_createIndex(); $index->setMapping(new Mapping(['point' => ['type' => 'geo_point']])); @@ -49,7 +52,7 @@ public function testGeoPoint() /** * @group unit */ - public function testConstructLatlon() + public function testConstructLatlon(): void { $key = 'location'; $location = [ @@ -75,7 +78,7 @@ public function testConstructLatlon() /** * @group unit */ - public function testConstructGeohash() + public function testConstructGeohash(): void { $key = 'location'; $location = 'u09tvqx'; @@ -98,7 +101,7 @@ public function testConstructGeohash() /** * @group unit */ - public function testSetDistanceType() + public function testSetDistanceType(): void { $query = new GeoDistance('location', ['lat' => 48.86, 'lon' => 2.35], '10km'); $distanceType = GeoDistance::DISTANCE_TYPE_ARC; diff --git a/tests/Query/GeoPolygonTest.php b/tests/Query/GeoPolygonTest.php index bfdaa7b9a6..403ade792e 100644 --- a/tests/Query/GeoPolygonTest.php +++ b/tests/Query/GeoPolygonTest.php @@ -9,12 +9,15 @@ use Elastica\Query\MatchAll; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class GeoPolygonTest extends BaseTest { /** * @group functional */ - public function testGeoPoint() + public function testGeoPoint(): void { $index = $this->_createIndex(); @@ -22,7 +25,8 @@ public function testGeoPoint() $index->setMapping(new Mapping(['location' => ['type' => 'geo_point']])); // Add doc 1 - $doc1 = new Document(1, + $doc1 = new Document( + 1, [ 'name' => 'ruflin', ] @@ -32,7 +36,8 @@ public function testGeoPoint() $index->addDocument($doc1); // Add doc 2 - $doc2 = new Document(2, + $doc2 = new Document( + 2, [ 'name' => 'ruflin', ] diff --git a/tests/Query/GeoShapePreIndexedTest.php b/tests/Query/GeoShapePreIndexedTest.php index d2ffcad9af..5363c3f4bc 100644 --- a/tests/Query/GeoShapePreIndexedTest.php +++ b/tests/Query/GeoShapePreIndexedTest.php @@ -9,12 +9,15 @@ use Elastica\Query\GeoShapePreIndexed; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class GeoShapePreIndexedTest extends BaseTest { /** * @group functional */ - public function testSearch() + public function testSearch(): void { $index = $this->_createIndex(); $indexName = $index->getName(); @@ -40,7 +43,10 @@ public function testSearch() $index->refresh(); $gsp = new GeoShapePreIndexed( - 'location', '2', $indexName, 'location' + 'location', + '2', + $indexName, + 'location' ); $query = new BoolQuery(); @@ -55,10 +61,13 @@ public function testSearch() /** * @group unit */ - public function testConstruct() + public function testConstruct(): void { $gsp = new GeoShapePreIndexed( - 'search_field', '1', 'index', 'indexed_field' + 'search_field', + '1', + 'index', + 'indexed_field' ); $expected = [ @@ -80,7 +89,7 @@ public function testConstruct() /** * @group unit */ - public function testSetRelation() + public function testSetRelation(): void { $gsp = new GeoShapePreIndexed('location', '1', 'indexName', 'location'); diff --git a/tests/Query/GeoShapeProvidedTest.php b/tests/Query/GeoShapeProvidedTest.php index ec4340cc8b..3f73fad270 100644 --- a/tests/Query/GeoShapeProvidedTest.php +++ b/tests/Query/GeoShapeProvidedTest.php @@ -9,12 +9,15 @@ use Elastica\Query\GeoShapeProvided; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class GeoShapeProvidedTest extends BaseTest { /** * @group functional */ - public function testSearch() + public function testSearch(): void { $index = $this->_createIndex(); $mapping = new Mapping([ @@ -58,7 +61,7 @@ public function testSearch() /** * @group unit */ - public function testConstructEnvelope() + public function testConstructEnvelope(): void { $envelope = [ [25.0, 75.0], @@ -84,7 +87,7 @@ public function testConstructEnvelope() /** * @group unit */ - public function testConstructPolygon() + public function testConstructPolygon(): void { $polygon = [[102.0, 2.0], [103.0, 2.0], [103.0, 3.0], [103.0, 3.0], [102.0, 2.0]]; $gsp = new GeoShapeProvided('location', $polygon, GeoShapeProvided::TYPE_POLYGON); @@ -107,7 +110,7 @@ public function testConstructPolygon() /** * @group unit */ - public function testSetRelation() + public function testSetRelation(): void { $gsp = new GeoShapeProvided('location', [[25.0, 75.0], [75.0, 25.0]]); diff --git a/tests/Query/HasChildTest.php b/tests/Query/HasChildTest.php index c234eee32e..85868fd9db 100644 --- a/tests/Query/HasChildTest.php +++ b/tests/Query/HasChildTest.php @@ -8,12 +8,15 @@ use Elastica\Search; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class HasChildTest extends BaseTest { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $q = new MatchAll(); @@ -34,7 +37,7 @@ public function testToArray() /** * @group unit */ - public function testSetScope() + public function testSetScope(): void { $q = new MatchAll(); @@ -59,7 +62,7 @@ public function testSetScope() /** * @group functional */ - public function testHasChildren() + public function testHasChildren(): void { $client = $this->_getClient(); $index = $client->getIndex('testhaschild'); diff --git a/tests/Query/HasParentTest.php b/tests/Query/HasParentTest.php index c3e7534eae..16563e8d48 100644 --- a/tests/Query/HasParentTest.php +++ b/tests/Query/HasParentTest.php @@ -8,12 +8,15 @@ use Elastica\Search; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class HasParentTest extends BaseTest { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $q = new MatchAll(); @@ -34,7 +37,7 @@ public function testToArray() /** * @group unit */ - public function testSetScope() + public function testSetScope(): void { $q = new MatchAll(); @@ -59,7 +62,7 @@ public function testSetScope() /** * @group functional */ - public function testHasParent() + public function testHasParent(): void { $client = $this->_getClient(); $index = $client->getIndex('testhasparentjoin'); diff --git a/tests/Query/HighlightTest.php b/tests/Query/HighlightTest.php index ebde4bfab2..17a847a987 100644 --- a/tests/Query/HighlightTest.php +++ b/tests/Query/HighlightTest.php @@ -7,12 +7,15 @@ use Elastica\Query\MatchPhrase; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class HighlightTest extends BaseTest { /** * @group functional */ - public function testHightlightSearch() + public function testHightlightSearch(): void { $index = $this->_createIndex(); diff --git a/tests/Query/IdsTest.php b/tests/Query/IdsTest.php index b72e1999ab..c0c7b01112 100644 --- a/tests/Query/IdsTest.php +++ b/tests/Query/IdsTest.php @@ -8,12 +8,15 @@ use Elastica\Query\Type; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class IdsTest extends BaseTest { /** @var Index */ protected $index; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -29,7 +32,7 @@ protected function setUp() /** * @group functional */ - public function testSetIdsSearchSingle() + public function testSetIdsSearchSingle(): void { $query = new Ids(); $query->setIds('1'); @@ -42,7 +45,7 @@ public function testSetIdsSearchSingle() /** * @group functional */ - public function testSetIdsSearchArray() + public function testSetIdsSearchArray(): void { $query = new Ids(); $query->setIds(['1', '2']); @@ -55,7 +58,7 @@ public function testSetIdsSearchArray() /** * @group functional */ - public function testAddIdsSearchSingle() + public function testAddIdsSearchSingle(): void { $query = new Ids(); $query->addId('3'); @@ -68,7 +71,7 @@ public function testAddIdsSearchSingle() /** * @group functional */ - public function testComboIdsSearchArray() + public function testComboIdsSearchArray(): void { $query = new Ids(); @@ -83,7 +86,7 @@ public function testComboIdsSearchArray() /** * @group functional */ - public function testSetTypeSingleSearchSingle() + public function testSetTypeSingleSearchSingle(): void { $query = new Ids(); $query->setIds('1'); @@ -95,7 +98,7 @@ public function testSetTypeSingleSearchSingle() /** * @group functional */ - public function testSetTypeSingleSearchArray() + public function testSetTypeSingleSearchArray(): void { $query = new Ids(); $query->setIds(['1', '2']); @@ -108,7 +111,7 @@ public function testSetTypeSingleSearchArray() /** * @group functional */ - public function testSetTypeSingleSearchSingleDocInOtherType() + public function testSetTypeSingleSearchSingleDocInOtherType(): void { $query = new Ids(); @@ -124,7 +127,7 @@ public function testSetTypeSingleSearchSingleDocInOtherType() /** * @group functional */ - public function testSetTypeSingleSearchArrayDocInOtherType() + public function testSetTypeSingleSearchArrayDocInOtherType(): void { $query = new Ids(); diff --git a/tests/Query/InnerHitsTest.php b/tests/Query/InnerHitsTest.php index 26bbe31dd0..647f875832 100644 --- a/tests/Query/InnerHitsTest.php +++ b/tests/Query/InnerHitsTest.php @@ -13,165 +13,15 @@ use Elastica\Script\ScriptFields; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class InnerHitsTest extends BaseTest { - private function _getIndexForNestedTest() - { - $index = $this->_createIndex(); - $index->setMapping(new Mapping([ - 'users' => [ - 'type' => 'nested', - 'properties' => [ - 'name' => ['type' => 'text', 'fielddata' => true], - ], - ], - 'title' => ['type' => 'text'], - 'last_activity_date' => ['type' => 'date'], - ])); - - $index->addDocuments([ - $index->createDocument(1, [ - 'users' => [ - ['name' => 'John Smith', 'last_activity_date' => '2015-01-05'], - ['name' => 'Conan', 'last_activity_date' => '2015-01-05'], - ], - 'last_activity_date' => '2015-01-05', - 'title' => 'Question about linux #1', - ]), - $index->createDocument(2, [ - 'users' => [ - ['name' => 'John Doe', 'last_activity_date' => '2015-01-05'], - ['name' => 'Simon', 'last_activity_date' => '2015-01-05'], - ], - 'last_activity_date' => '2014-12-23', - 'title' => 'Question about linux #2', - ]), - $index->createDocument(3, [ - 'users' => [ - ['name' => 'Simon', 'last_activity_date' => '2015-01-05'], - ['name' => 'Garfunkel', 'last_activity_date' => '2015-01-05'], - ], - 'last_activity_date' => '2015-01-05', - 'title' => 'Question about windows #1', - ]), - $index->createDocument(4, [ - 'users' => [ - ['name' => 'Einstein'], - ['name' => 'Newton'], - ['name' => 'Maxwell'], - ], - 'last_activity_date' => '2014-12-23', - 'title' => 'Question about windows #2', - ]), - $index->createDocument(5, [ - 'users' => [ - ['name' => 'Faraday'], - ['name' => 'Leibniz'], - ['name' => 'Descartes'], - ], - 'last_activity_date' => '2014-12-23', - 'title' => 'Question about osx', - ]), - ]); - - $index->refresh(); - - return $index; - } - - private function _getIndexForParentChildrenTest() - { - $index = $this->_createIndex(); - $mappingQuestion = new Mapping(); - $mappingQuestion->setProperties([ - 'title' => ['type' => 'text'], - 'answer' => ['type' => 'text', 'fielddata' => true], - 'last_activity_date' => ['type' => 'date'], - 'my_join_field' => [ - 'type' => 'join', - 'relations' => [ - 'questions' => 'answers', - ], - ], - ]); - - $index->setMapping($mappingQuestion); - $index->addDocuments([ - $index->createDocument(1, [ - 'last_activity_date' => '2015-01-05', - 'title' => 'Question about linux #1', - 'my_join_field' => [ - 'name' => 'questions', - ], - ]), - $index->createDocument(2, [ - 'last_activity_date' => '2014-12-23', - 'title' => 'Question about linux #2', - 'my_join_field' => [ - 'name' => 'questions', - ], - ]), - $index->createDocument(3, [ - 'last_activity_date' => '2015-01-05', - 'title' => 'Question about windows #1', - 'my_join_field' => [ - 'name' => 'questions', - ], - ]), - $index->createDocument(4, [ - 'last_activity_date' => '2014-12-23', - 'title' => 'Question about windows #2', - 'my_join_field' => [ - 'name' => 'questions', - ], - ]), - $index->createDocument(5, [ - 'last_activity_date' => '2014-12-23', - 'title' => 'Question about osx', - 'my_join_field' => [ - 'name' => 'questions', - ], - ]), - ]); - - $doc1 = $index->createDocument(6, [ - 'answer' => 'linux is cool', - 'last_activity_date' => '2016-01-05', - 'my_join_field' => [ - 'name' => 'answers', - 'parent' => 1, - ], - ]); - - $doc2 = $index->createDocument(7, [ - 'answer' => 'linux is bad', - 'last_activity_date' => '2005-01-05', - 'my_join_field' => [ - 'name' => 'answers', - 'parent' => 1, - ], - ]); - - $doc3 = $index->createDocument(8, [ - 'answer' => 'windows was cool', - 'last_activity_date' => '2005-01-05', - 'my_join_field' => [ - 'name' => 'answers', - 'parent' => 2, - ], - ]); - - $this->_getClient()->addDocuments([$doc1, $doc2, $doc3], ['routing' => 1]); - - $index->refresh(); - - return $index; - } - /** * @group unit */ - public function testSetSize() + public function testSetSize(): void { $innerHits = new InnerHits(); $returnValue = $innerHits->setSize(12); @@ -182,7 +32,7 @@ public function testSetSize() /** * @group unit */ - public function testSetFrom() + public function testSetFrom(): void { $innerHits = new InnerHits(); $returnValue = $innerHits->setFrom(12); @@ -193,7 +43,7 @@ public function testSetFrom() /** * @group unit */ - public function testSetSort() + public function testSetSort(): void { $sort = ['last_activity_date' => ['order' => 'desc']]; $innerHits = new InnerHits(); @@ -205,7 +55,7 @@ public function testSetSort() /** * @group unit */ - public function testSetSource() + public function testSetSource(): void { $fields = ['title', 'tags']; $innerHits = new InnerHits(); @@ -217,7 +67,7 @@ public function testSetSource() /** * @group unit */ - public function testSetVersion() + public function testSetVersion(): void { $innerHits = new InnerHits(); $returnValue = $innerHits->setVersion(true); @@ -231,7 +81,7 @@ public function testSetVersion() /** * @group unit */ - public function testSetExplain() + public function testSetExplain(): void { $innerHits = new InnerHits(); $returnValue = $innerHits->setExplain(true); @@ -245,7 +95,7 @@ public function testSetExplain() /** * @group unit */ - public function testSetHighlight() + public function testSetHighlight(): void { $highlight = [ 'fields' => [ @@ -261,7 +111,7 @@ public function testSetHighlight() /** * @group unit */ - public function testSetFieldDataFields() + public function testSetFieldDataFields(): void { $fields = ['title', 'tags']; $innerHits = new InnerHits(); @@ -273,7 +123,7 @@ public function testSetFieldDataFields() /** * @group unit */ - public function testSetScriptFields() + public function testSetScriptFields(): void { $script = new Script('1 + 2'); $scriptFields = new ScriptFields(['three' => $script]); @@ -287,7 +137,7 @@ public function testSetScriptFields() /** * @group unit */ - public function testAddScriptField() + public function testAddScriptField(): void { $script = new Script('2+3'); $innerHits = new InnerHits(); @@ -296,27 +146,10 @@ public function testAddScriptField() $this->assertInstanceOf(InnerHits::class, $returnValue); } - private function getNestedQuery(AbstractQuery $query, InnerHits $innerHits) - { - $nested = (new Nested()) - ->setInnerHits($innerHits) - ->setPath('users') - ->setQuery($query); - - return $this->_getIndexForNestedTest()->search($nested); - } - - private function getParentChildQuery(AbstractQuery $query, InnerHits $innerHits) - { - $child = (new HasChild($query, 'answers'))->setInnerHits($innerHits); - - return $this->_getIndexForParentChildrenTest()->search($child); - } - /** * @group functional */ - public function testInnerHitsNested() + public function testInnerHitsNested(): void { $queryString = new SimpleQueryString('windows newton', ['title', 'users.name']); $innerHits = new InnerHits(); @@ -333,7 +166,7 @@ public function testInnerHitsNested() /** * @group functional */ - public function testInnerHitsParentChildren() + public function testInnerHitsParentChildren(): void { $queryString = new SimpleQueryString('linux cool'); $innerHits = new InnerHits(); @@ -357,7 +190,7 @@ public function testInnerHitsParentChildren() /** * @group functional */ - public function testInnerHitsLimitedSource() + public function testInnerHitsLimitedSource(): void { $this->markTestSkipped('Source filtering on inner hits is bugged. See https://github.com/elastic/elasticsearch/issues/21312'); @@ -378,7 +211,7 @@ public function testInnerHitsLimitedSource() /** * @group functional */ - public function testInnerHitsWithOffset() + public function testInnerHitsWithOffset(): void { $queryString = new SimpleQueryString('linux cool'); $innerHits = new InnerHits(); @@ -398,7 +231,7 @@ public function testInnerHitsWithOffset() /** * @group functional */ - public function testInnerHitsWithSort() + public function testInnerHitsWithSort(): void { $queryString = new SimpleQueryString('linux cool'); $innerHits = new InnerHits(); @@ -423,7 +256,7 @@ public function testInnerHitsWithSort() /** * @group functional */ - public function testInnerHitsWithExplain() + public function testInnerHitsWithExplain(): void { $matchAll = new MatchAll(); $innerHits = new InnerHits(); @@ -442,7 +275,7 @@ public function testInnerHitsWithExplain() /** * @group functional */ - public function testInnerHitsWithVersion() + public function testInnerHitsWithVersion(): void { $matchAll = new MatchAll(); $innerHits = new InnerHits(); @@ -461,7 +294,7 @@ public function testInnerHitsWithVersion() /** * @group functional */ - public function testInnerHitsWithScriptFields() + public function testInnerHitsWithScriptFields(): void { $matchAll = new MatchAll(); $innerHits = new InnerHits(); @@ -485,7 +318,7 @@ public function testInnerHitsWithScriptFields() /** * @group functional */ - public function testInnerHitsWithHighlight() + public function testInnerHitsWithHighlight(): void { $queryString = new SimpleQueryString('question simon', ['title', 'users.name']); $innerHits = new InnerHits(); @@ -505,7 +338,7 @@ public function testInnerHitsWithHighlight() /** * @group functional */ - public function testInnerHitsWithFieldData() + public function testInnerHitsWithFieldData(): void { $queryString = new SimpleQueryString('question simon', ['title', 'users.name']); $innerHits = new InnerHits(); @@ -523,4 +356,175 @@ public function testInnerHitsWithFieldData() } } } + + private function _getIndexForNestedTest() + { + $index = $this->_createIndex(); + $index->setMapping(new Mapping([ + 'users' => [ + 'type' => 'nested', + 'properties' => [ + 'name' => ['type' => 'text', 'fielddata' => true], + ], + ], + 'title' => ['type' => 'text'], + 'last_activity_date' => ['type' => 'date'], + ])); + + $index->addDocuments([ + $index->createDocument(1, [ + 'users' => [ + ['name' => 'John Smith', 'last_activity_date' => '2015-01-05'], + ['name' => 'Conan', 'last_activity_date' => '2015-01-05'], + ], + 'last_activity_date' => '2015-01-05', + 'title' => 'Question about linux #1', + ]), + $index->createDocument(2, [ + 'users' => [ + ['name' => 'John Doe', 'last_activity_date' => '2015-01-05'], + ['name' => 'Simon', 'last_activity_date' => '2015-01-05'], + ], + 'last_activity_date' => '2014-12-23', + 'title' => 'Question about linux #2', + ]), + $index->createDocument(3, [ + 'users' => [ + ['name' => 'Simon', 'last_activity_date' => '2015-01-05'], + ['name' => 'Garfunkel', 'last_activity_date' => '2015-01-05'], + ], + 'last_activity_date' => '2015-01-05', + 'title' => 'Question about windows #1', + ]), + $index->createDocument(4, [ + 'users' => [ + ['name' => 'Einstein'], + ['name' => 'Newton'], + ['name' => 'Maxwell'], + ], + 'last_activity_date' => '2014-12-23', + 'title' => 'Question about windows #2', + ]), + $index->createDocument(5, [ + 'users' => [ + ['name' => 'Faraday'], + ['name' => 'Leibniz'], + ['name' => 'Descartes'], + ], + 'last_activity_date' => '2014-12-23', + 'title' => 'Question about osx', + ]), + ]); + + $index->refresh(); + + return $index; + } + + private function _getIndexForParentChildrenTest() + { + $index = $this->_createIndex(); + $mappingQuestion = new Mapping(); + $mappingQuestion->setProperties([ + 'title' => ['type' => 'text'], + 'answer' => ['type' => 'text', 'fielddata' => true], + 'last_activity_date' => ['type' => 'date'], + 'my_join_field' => [ + 'type' => 'join', + 'relations' => [ + 'questions' => 'answers', + ], + ], + ]); + + $index->setMapping($mappingQuestion); + $index->addDocuments([ + $index->createDocument(1, [ + 'last_activity_date' => '2015-01-05', + 'title' => 'Question about linux #1', + 'my_join_field' => [ + 'name' => 'questions', + ], + ]), + $index->createDocument(2, [ + 'last_activity_date' => '2014-12-23', + 'title' => 'Question about linux #2', + 'my_join_field' => [ + 'name' => 'questions', + ], + ]), + $index->createDocument(3, [ + 'last_activity_date' => '2015-01-05', + 'title' => 'Question about windows #1', + 'my_join_field' => [ + 'name' => 'questions', + ], + ]), + $index->createDocument(4, [ + 'last_activity_date' => '2014-12-23', + 'title' => 'Question about windows #2', + 'my_join_field' => [ + 'name' => 'questions', + ], + ]), + $index->createDocument(5, [ + 'last_activity_date' => '2014-12-23', + 'title' => 'Question about osx', + 'my_join_field' => [ + 'name' => 'questions', + ], + ]), + ]); + + $doc1 = $index->createDocument(6, [ + 'answer' => 'linux is cool', + 'last_activity_date' => '2016-01-05', + 'my_join_field' => [ + 'name' => 'answers', + 'parent' => 1, + ], + ]); + + $doc2 = $index->createDocument(7, [ + 'answer' => 'linux is bad', + 'last_activity_date' => '2005-01-05', + 'my_join_field' => [ + 'name' => 'answers', + 'parent' => 1, + ], + ]); + + $doc3 = $index->createDocument(8, [ + 'answer' => 'windows was cool', + 'last_activity_date' => '2005-01-05', + 'my_join_field' => [ + 'name' => 'answers', + 'parent' => 2, + ], + ]); + + $this->_getClient()->addDocuments([$doc1, $doc2, $doc3], ['routing' => 1]); + + $index->refresh(); + + return $index; + } + + private function getNestedQuery(AbstractQuery $query, InnerHits $innerHits) + { + $nested = (new Nested()) + ->setInnerHits($innerHits) + ->setPath('users') + ->setQuery($query) + ; + + return $this->_getIndexForNestedTest()->search($nested); + } + + private function getParentChildQuery(AbstractQuery $query, InnerHits $innerHits) + { + $child = (new HasChild($query, 'answers'))->setInnerHits($innerHits); + + return $this->_getIndexForParentChildrenTest()->search($child); + } } diff --git a/tests/Query/LimitTest.php b/tests/Query/LimitTest.php index cc815ceb79..6e53318132 100644 --- a/tests/Query/LimitTest.php +++ b/tests/Query/LimitTest.php @@ -5,12 +5,15 @@ use Elastica\Query\Limit; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class LimitTest extends BaseTest { /** * @group unit */ - public function testSetType() + public function testSetType(): void { $query = new Limit(10); $this->assertEquals(10, $query->getParam('value')); @@ -22,7 +25,7 @@ public function testSetType() /** * @group unit */ - public function testToArray() + public function testToArray(): void { $query = new Limit(15); diff --git a/tests/Query/MatchAllTest.php b/tests/Query/MatchAllTest.php index 2dc02f9ebd..df45e9cadb 100644 --- a/tests/Query/MatchAllTest.php +++ b/tests/Query/MatchAllTest.php @@ -7,12 +7,15 @@ use Elastica\Search; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class MatchAllTest extends BaseTest { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $query = new MatchAll(); @@ -24,7 +27,7 @@ public function testToArray() /** * @group functional */ - public function testMatchAllIndicesTypes() + public function testMatchAllIndicesTypes(): void { $index1 = $this->_createIndex(); diff --git a/tests/Query/MatchNoneTest.php b/tests/Query/MatchNoneTest.php index da6643d893..ec1d78b26b 100644 --- a/tests/Query/MatchNoneTest.php +++ b/tests/Query/MatchNoneTest.php @@ -7,12 +7,15 @@ use Elastica\Search; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class MatchNoneTest extends BaseTest { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $query = new MatchNone(); @@ -24,7 +27,7 @@ public function testToArray() /** * @group functional */ - public function testMatchNone() + public function testMatchNone(): void { $index = $this->_createIndex(); $client = $index->getClient(); diff --git a/tests/Query/MatchPhrasePrefixTest.php b/tests/Query/MatchPhrasePrefixTest.php index 4f86cc67f0..3fec0a9de5 100644 --- a/tests/Query/MatchPhrasePrefixTest.php +++ b/tests/Query/MatchPhrasePrefixTest.php @@ -6,12 +6,15 @@ use Elastica\Query\MatchPhrasePrefix; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class MatchPhrasePrefixTest extends BaseTest { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $field = 'test'; $testQuery = 'Nicolas Ruflin'; @@ -42,7 +45,7 @@ public function testToArray() /** * @group functional */ - public function testMatchPhrasePrefix() + public function testMatchPhrasePrefix(): void { $client = $this->_getClient(); $index = $client->getIndex('test'); diff --git a/tests/Query/MatchPhraseTest.php b/tests/Query/MatchPhraseTest.php index dcc1341dcc..58d7e2032c 100644 --- a/tests/Query/MatchPhraseTest.php +++ b/tests/Query/MatchPhraseTest.php @@ -6,12 +6,15 @@ use Elastica\Query\MatchPhrase; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class MatchPhraseTest extends BaseTest { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $field = 'test'; $testQuery = 'Nicolas Ruflin'; @@ -39,7 +42,7 @@ public function testToArray() /** * @group functional */ - public function testMatchPhrase() + public function testMatchPhrase(): void { $client = $this->_getClient(); $index = $client->getIndex('test'); diff --git a/tests/Query/MatchTest.php b/tests/Query/MatchTest.php index 6ab9c949f1..ee1676a781 100644 --- a/tests/Query/MatchTest.php +++ b/tests/Query/MatchTest.php @@ -6,12 +6,15 @@ use Elastica\Query\Match; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class MatchTest extends BaseTest { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $field = 'test'; $testQuery = 'Nicolas Ruflin'; @@ -59,7 +62,7 @@ public function testToArray() /** * @group functional */ - public function testMatch() + public function testMatch(): void { $client = $this->_getClient(); $index = $client->getIndex('test'); @@ -89,7 +92,7 @@ public function testMatch() /** * @group functional */ - public function testMatchSetFieldBoost() + public function testMatchSetFieldBoost(): void { $client = $this->_getClient(); $index = $client->getIndex('test'); @@ -120,7 +123,7 @@ public function testMatchSetFieldBoost() /** * @group functional */ - public function testMatchSetFieldBoostWithString() + public function testMatchSetFieldBoostWithString(): void { $client = $this->_getClient(); $index = $client->getIndex('test'); @@ -151,7 +154,7 @@ public function testMatchSetFieldBoostWithString() /** * @group functional */ - public function testMatchZeroTerm() + public function testMatchZeroTerm(): void { $client = $this->_getClient(); $index = $client->getIndex('test'); @@ -176,7 +179,7 @@ public function testMatchZeroTerm() /** * @group unit */ - public function testMatchFuzzinessType() + public function testMatchFuzzinessType(): void { $field = 'test'; $query = new Match(); @@ -197,7 +200,7 @@ public function testMatchFuzzinessType() /** * @group unit */ - public function testConstruct() + public function testConstruct(): void { $match = new Match(null, 'values'); $this->assertEquals(['match' => []], $match->toArray()); diff --git a/tests/Query/MoreLikeThisTest.php b/tests/Query/MoreLikeThisTest.php index 9e48ffab1e..d8b5f40163 100644 --- a/tests/Query/MoreLikeThisTest.php +++ b/tests/Query/MoreLikeThisTest.php @@ -11,12 +11,15 @@ use Elastica\Query\Term; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class MoreLikeThisTest extends BaseTest { /** * @group functional */ - public function testSearch() + public function testSearch(): void { $client = $this->_getClient(); $index = new Index($client, 'test'); @@ -58,7 +61,7 @@ public function testSearch() /** * @group functional */ - public function testSearchByDocument() + public function testSearchByDocument(): void { $client = $this->_getClient(['persistent' => false]); $index = $client->getIndex('elastica_test'); @@ -115,7 +118,7 @@ public function testSearchByDocument() /** * @group unit */ - public function testSetFields() + public function testSetFields(): void { $query = new MoreLikeThis(); @@ -129,7 +132,7 @@ public function testSetFields() /** * @group unit */ - public function testSetLike() + public function testSetLike(): void { $query = new MoreLikeThis(); $query->setLike(' hello world'); @@ -141,7 +144,7 @@ public function testSetLike() /** * @group unit */ - public function testSetBoost() + public function testSetBoost(): void { $query = new MoreLikeThis(); @@ -154,7 +157,7 @@ public function testSetBoost() /** * @group unit */ - public function testSetMaxQueryTerms() + public function testSetMaxQueryTerms(): void { $query = new MoreLikeThis(); @@ -167,7 +170,7 @@ public function testSetMaxQueryTerms() /** * @group unit */ - public function testSetMinimumShouldMatch() + public function testSetMinimumShouldMatch(): void { $query = new MoreLikeThis(); @@ -180,7 +183,7 @@ public function testSetMinimumShouldMatch() /** * @group unit */ - public function testSetMinDocFrequency() + public function testSetMinDocFrequency(): void { $query = new MoreLikeThis(); @@ -193,7 +196,7 @@ public function testSetMinDocFrequency() /** * @group unit */ - public function testSetMaxDocFrequency() + public function testSetMaxDocFrequency(): void { $query = new MoreLikeThis(); @@ -206,7 +209,7 @@ public function testSetMaxDocFrequency() /** * @group unit */ - public function testSetMinWordLength() + public function testSetMinWordLength(): void { $query = new MoreLikeThis(); @@ -219,7 +222,7 @@ public function testSetMinWordLength() /** * @group unit */ - public function testSetMaxWordLength() + public function testSetMaxWordLength(): void { $query = new MoreLikeThis(); @@ -232,7 +235,7 @@ public function testSetMaxWordLength() /** * @group unit */ - public function testSetBoostTerms() + public function testSetBoostTerms(): void { $query = new MoreLikeThis(); @@ -245,7 +248,7 @@ public function testSetBoostTerms() /** * @group unit */ - public function testSetAnalyzer() + public function testSetAnalyzer(): void { $query = new MoreLikeThis(); @@ -258,7 +261,7 @@ public function testSetAnalyzer() /** * @group unit */ - public function testSetStopWords() + public function testSetStopWords(): void { $query = new MoreLikeThis(); @@ -271,7 +274,7 @@ public function testSetStopWords() /** * @group unit */ - public function testToArrayForId() + public function testToArrayForId(): void { $query = new MoreLikeThis(); $query->setLike(new Document('1', [], 'index')); @@ -293,7 +296,7 @@ public function testToArrayForId() /** * @group unit */ - public function testToArrayForSource() + public function testToArrayForSource(): void { $query = new MoreLikeThis(); $query->setLike(new Document('', ['Foo' => 'Bar'], 'index')); diff --git a/tests/Query/MultiMatchTest.php b/tests/Query/MultiMatchTest.php index b8eec5311c..4b6eb28628 100644 --- a/tests/Query/MultiMatchTest.php +++ b/tests/Query/MultiMatchTest.php @@ -9,6 +9,9 @@ use Elastica\Query\MultiMatch; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class MultiMatchTest extends BaseTest { private $index; @@ -24,7 +27,7 @@ class MultiMatchTest extends BaseTest /** * @group functional */ - public function testMinimumShouldMatch() + public function testMinimumShouldMatch(): void { $multiMatch = new MultiMatch(); $multiMatch->setQuery('Tristan Maindron'); @@ -38,7 +41,7 @@ public function testMinimumShouldMatch() /** * @group functional */ - public function testAndOperator() + public function testAndOperator(): void { $multiMatch = new MultiMatch(); $multiMatch->setQuery('Monique Maindron'); @@ -52,7 +55,7 @@ public function testAndOperator() /** * @group functional */ - public function testType() + public function testType(): void { $multiMatch = new MultiMatch(); $multiMatch->setQuery('Trist'); @@ -66,7 +69,7 @@ public function testType() /** * @group functional */ - public function testFuzzy() + public function testFuzzy(): void { $multiMatch = new MultiMatch(); $multiMatch->setQuery('Tritsan'); // Misspell on purpose @@ -96,7 +99,7 @@ public function testFuzzy() /** * @group functional */ - public function testFuzzyWithOptions1() + public function testFuzzyWithOptions1(): void { // Here Elasticsearch will not accept mispells // on the first 6 letters. @@ -113,7 +116,7 @@ public function testFuzzyWithOptions1() /** * @group functional */ - public function testFuzzyWithOptions2() + public function testFuzzyWithOptions2(): void { // Here with a 'M' search we should hit 'Moraes' first // and then stop because MaxExpansion = 1. @@ -132,7 +135,7 @@ public function testFuzzyWithOptions2() /** * @group functional */ - public function testZeroTerm() + public function testZeroTerm(): void { $multiMatch = new MultiMatch(); $multiMatch->setQuery('not'); // This is a stopword. @@ -152,7 +155,7 @@ public function testZeroTerm() /** * @group functional */ - public function testBaseMultiMatch() + public function testBaseMultiMatch(): void { $multiMatch = new MultiMatch(); $multiMatch->setQuery('Rodolfo'); diff --git a/tests/Query/NestedTest.php b/tests/Query/NestedTest.php index 1be8b019e5..e26b77c2e9 100644 --- a/tests/Query/NestedTest.php +++ b/tests/Query/NestedTest.php @@ -6,12 +6,15 @@ use Elastica\Query\QueryString; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class NestedTest extends BaseTest { /** * @group unit */ - public function testSetQuery() + public function testSetQuery(): void { $nested = new Nested(); $path = 'test1'; diff --git a/tests/Query/ParentIdTest.php b/tests/Query/ParentIdTest.php index a7cea4fbe3..0ca657cdce 100644 --- a/tests/Query/ParentIdTest.php +++ b/tests/Query/ParentIdTest.php @@ -7,12 +7,15 @@ use Elastica\Search; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class ParentIdTest extends BaseTest { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $query = new ParentId('join', '1'); $expectedArray = [ @@ -29,7 +32,7 @@ public function testToArray() /** * @group functional */ - public function testParentId() + public function testParentId(): void { $client = $this->_getClient(); $index = $client->getIndex('testparentid'); @@ -120,7 +123,7 @@ public function testParentId() /** * @group unit */ - public function testQueryBuilderParentId() + public function testQueryBuilderParentId(): void { $client = $this->_getClient(); $index = $client->getIndex('testparentid'); diff --git a/tests/Query/PercolateTest.php b/tests/Query/PercolateTest.php index 057b773df2..fb621d77cd 100644 --- a/tests/Query/PercolateTest.php +++ b/tests/Query/PercolateTest.php @@ -7,6 +7,9 @@ use Elastica\Query\Percolate; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class PercolateTest extends BaseTest { /** @@ -17,7 +20,7 @@ class PercolateTest extends BaseTest /** * @group functional */ - public function testPercolateQueryOnNewDocument() + public function testPercolateQueryOnNewDocument(): void { $this->_prepareIndexForPercolate(); //Register a query in the percolator: @@ -28,7 +31,8 @@ public function testPercolateQueryOnNewDocument() //Match a document to the registered percolator queries: $percolateQuery = new Percolate(); $percolateQuery->setField('query') - ->setDocument($doc->getData()); + ->setDocument($doc->getData()) + ; $resultSet = $this->index->search($percolateQuery); $this->assertEquals(1, $resultSet->count()); @@ -46,7 +50,8 @@ public function testPercolateQueryOnNewDocument() $doc2 = new Document(4, ['message' => 'Just a simple text for test']); $percolateQuery = new Percolate(); $percolateQuery->setField('query') - ->setDocument($doc2->getData()); + ->setDocument($doc2->getData()) + ; $resultSet = $this->index->search($percolateQuery); $this->assertEquals(0, $resultSet->count()); @@ -55,7 +60,7 @@ public function testPercolateQueryOnNewDocument() /** * @group functional */ - public function testPercolateQueryOnExistingDocument() + public function testPercolateQueryOnExistingDocument(): void { $this->_prepareIndexForPercolate(); //Register a query in the percolator: @@ -68,7 +73,8 @@ public function testPercolateQueryOnExistingDocument() $percolateQuery = new Percolate(); $percolateQuery->setField('query') ->setDocumentIndex($this->index->getName()) - ->setDocumentId($doc->getId()); + ->setDocumentId($doc->getId()) + ; $resultSet = $this->index->search($percolateQuery); $this->assertEquals(1, $resultSet->count()); @@ -85,26 +91,17 @@ public function testPercolateQueryOnExistingDocument() $percolateQuery = new Percolate(); $percolateQuery->setField('query') ->setDocumentIndex($this->index->getName()) - ->setDocumentId($doc2->getId()); + ->setDocumentId($doc2->getId()) + ; $resultSet = $this->index->search($percolateQuery); $this->assertEquals(0, $resultSet->count()); } - private function _prepareIndexForPercolate() - { - $this->index = $this->_createIndex(); - $this->index->getSettings()->setNumberOfReplicas(0); - //The doctype mapping is the mapping used to preprocess the document - // defined in the percolator query before it gets indexed into a temporary index. - //The queries mapping is the mapping used for indexing the query documents. - $this->index->setMapping(new Mapping(['message' => ['type' => 'text'], 'query' => ['type' => 'percolator']])); - } - /** * @group unit */ - public function testSetField() + public function testSetField(): void { $field = 'field1'; $query = new Percolate(); @@ -118,7 +115,7 @@ public function testSetField() /** * @group unit */ - public function testSetDocument() + public function testSetDocument(): void { $query = new Percolate(); $doc = new Document(1, ['message' => 'A new bonsai tree in the office']); @@ -132,7 +129,7 @@ public function testSetDocument() /** * @group unit */ - public function testSetDocumentIndex() + public function testSetDocumentIndex(): void { $index = $this->_createIndex('indexone'); $query = new Percolate(); @@ -146,7 +143,7 @@ public function testSetDocumentIndex() /** * @group unit */ - public function testSetDocumentId() + public function testSetDocumentId(): void { $id = 3; $query = new Percolate(); @@ -160,7 +157,7 @@ public function testSetDocumentId() /** * @group unit */ - public function testSetDocumentRouting() + public function testSetDocumentRouting(): void { $routing = 'testRout'; $query = new Percolate(); @@ -174,7 +171,7 @@ public function testSetDocumentRouting() /** * @group unit */ - public function testSetDocumentPreference() + public function testSetDocumentPreference(): void { $preference = ['pref1' => 'test', 'pref2' => 'test2']; $query = new Percolate(); @@ -188,7 +185,7 @@ public function testSetDocumentPreference() /** * @group unit */ - public function testSetDocumentVersion() + public function testSetDocumentVersion(): void { $version = 10; $query = new Percolate(); @@ -198,4 +195,14 @@ public function testSetDocumentVersion() $this->assertEquals($data['percolate']['version'], $version); } + + private function _prepareIndexForPercolate(): void + { + $this->index = $this->_createIndex(); + $this->index->getSettings()->setNumberOfReplicas(0); + //The doctype mapping is the mapping used to preprocess the document + // defined in the percolator query before it gets indexed into a temporary index. + //The queries mapping is the mapping used for indexing the query documents. + $this->index->setMapping(new Mapping(['message' => ['type' => 'text'], 'query' => ['type' => 'percolator']])); + } } diff --git a/tests/Query/PostFilterTest.php b/tests/Query/PostFilterTest.php index 2ebe19d01b..d800cf0b20 100644 --- a/tests/Query/PostFilterTest.php +++ b/tests/Query/PostFilterTest.php @@ -8,27 +8,15 @@ use Elastica\Query\Term; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class PostFilterTest extends BaseTest { - protected function _getTestIndex() - { - $index = $this->_createIndex(); - $docs = [ - new Document(1, ['color' => 'green', 'make' => 'ford']), - new Document(2, ['color' => 'blue', 'make' => 'volvo']), - new Document(3, ['color' => 'red', 'make' => 'ford']), - new Document(4, ['color' => 'green', 'make' => 'renault']), - ]; - $index->addDocuments($docs); - $index->refresh(); - - return $index; - } - /** * @group unit */ - public function testToArray() + public function testToArray(): void { $query = new Query(); @@ -44,7 +32,7 @@ public function testToArray() /** * @group functional */ - public function testQuery() + public function testQuery(): void { $query = new Query(); @@ -60,4 +48,19 @@ public function testQuery() $this->assertEquals(1, $this->_getTestIndex()->count($query)); } + + protected function _getTestIndex() + { + $index = $this->_createIndex(); + $docs = [ + new Document(1, ['color' => 'green', 'make' => 'ford']), + new Document(2, ['color' => 'blue', 'make' => 'volvo']), + new Document(3, ['color' => 'red', 'make' => 'ford']), + new Document(4, ['color' => 'green', 'make' => 'renault']), + ]; + $index->addDocuments($docs); + $index->refresh(); + + return $index; + } } diff --git a/tests/Query/PrefixTest.php b/tests/Query/PrefixTest.php index 070097fe6b..cdce2d1fd3 100644 --- a/tests/Query/PrefixTest.php +++ b/tests/Query/PrefixTest.php @@ -5,12 +5,15 @@ use Elastica\Query\Prefix; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class PrefixTest extends BaseTest { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $query = new Prefix(); $key = 'name'; diff --git a/tests/Query/QueryStringTest.php b/tests/Query/QueryStringTest.php index 9a39dc7474..b2433d0822 100644 --- a/tests/Query/QueryStringTest.php +++ b/tests/Query/QueryStringTest.php @@ -7,12 +7,15 @@ use Elastica\Query\QueryString; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class QueryStringTest extends BaseTest { /** * @group unit */ - public function testSearchMultipleFields() + public function testSearchMultipleFields(): void { $str = \md5(\rand()); $query = new QueryString($str); @@ -44,7 +47,7 @@ public function testSearchMultipleFields() /** * @group functional */ - public function testSearch() + public function testSearch(): void { $index = $this->_createIndex(); $index->getSettings()->setNumberOfReplicas(0); @@ -64,7 +67,7 @@ public function testSearch() * * @group functional */ - public function testSearchFields() + public function testSearchFields(): void { $index = $this->_createIndex(); @@ -85,7 +88,7 @@ public function testSearchFields() * * @group functional */ - public function testSearchFieldsValidationException() + public function testSearchFieldsValidationException(): void { $index = $this->_createIndex(); @@ -116,7 +119,7 @@ public function testSearchFieldsValidationException() /** * @group unit */ - public function testSetDefaultOperator() + public function testSetDefaultOperator(): void { $operator = 'AND'; $query = new QueryString('test'); @@ -130,7 +133,7 @@ public function testSetDefaultOperator() /** * @group unit */ - public function testSetDefaultField() + public function testSetDefaultField(): void { $default = 'field1'; $query = new QueryString('test'); @@ -144,7 +147,7 @@ public function testSetDefaultField() /** * @group unit */ - public function testSetAnalyzer() + public function testSetAnalyzer(): void { $value = 'test'; $query = new QueryString('test'); @@ -156,7 +159,7 @@ public function testSetAnalyzer() /** * @group unit */ - public function testSetAllowLeadingWildcard() + public function testSetAllowLeadingWildcard(): void { $value = true; $query = new QueryString('test'); @@ -168,7 +171,7 @@ public function testSetAllowLeadingWildcard() /** * @group unit */ - public function testSetEnablePositionIncrements() + public function testSetEnablePositionIncrements(): void { $value = true; $query = new QueryString('test'); @@ -180,7 +183,7 @@ public function testSetEnablePositionIncrements() /** * @group unit */ - public function testSetFuzzyPrefixLength() + public function testSetFuzzyPrefixLength(): void { $value = 1; $query = new QueryString('test'); @@ -192,7 +195,7 @@ public function testSetFuzzyPrefixLength() /** * @group unit */ - public function testSetFuzzyMinSim() + public function testSetFuzzyMinSim(): void { $value = 0.1; $query = new QueryString('test'); @@ -204,7 +207,7 @@ public function testSetFuzzyMinSim() /** * @group unit */ - public function testSetAnalyzeWildcard() + public function testSetAnalyzeWildcard(): void { $value = true; $query = new QueryString('test'); @@ -216,7 +219,7 @@ public function testSetAnalyzeWildcard() /** * @group unit */ - public function testSetTieBreaker() + public function testSetTieBreaker(): void { $value = 0.2; $query = new QueryString('test'); @@ -228,7 +231,7 @@ public function testSetTieBreaker() /** * @group unit */ - public function testSetRewrite() + public function testSetRewrite(): void { $rewrite = 'scoring_boolean'; $query = new QueryString('test'); @@ -242,7 +245,7 @@ public function testSetRewrite() /** * @group unit */ - public function testSetTimezone() + public function testSetTimezone(): void { $timezone = 'Europe/Paris'; $text = 'date:[2012 TO 2014]'; @@ -264,7 +267,7 @@ public function testSetTimezone() /** * @group unit */ - public function testSetPhraseSlop() + public function testSetPhraseSlop(): void { $phraseSlop = 9; @@ -278,7 +281,7 @@ public function testSetPhraseSlop() /** * @group functional */ - public function testSetBoost() + public function testSetBoost(): void { $index = $this->_createIndex(); $query = new QueryString('test'); diff --git a/tests/Query/RangeTest.php b/tests/Query/RangeTest.php index f26a5dcb30..81f9d1b97d 100644 --- a/tests/Query/RangeTest.php +++ b/tests/Query/RangeTest.php @@ -6,12 +6,15 @@ use Elastica\Query\Range; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class RangeTest extends BaseTest { /** * @group functional */ - public function testQuery() + public function testQuery(): void { $client = $this->_getClient(); $index = $client->getIndex('test'); @@ -41,7 +44,7 @@ public function testQuery() /** * @group unit */ - public function testToArray() + public function testToArray(): void { $range = new Range(); @@ -60,7 +63,7 @@ public function testToArray() /** * @group unit */ - public function testConstruct() + public function testConstruct(): void { $ranges = ['from' => 20, 'to' => 40]; $range = new Range( diff --git a/tests/Query/RegexpTest.php b/tests/Query/RegexpTest.php index eb2f07820e..11e8e2fe7c 100644 --- a/tests/Query/RegexpTest.php +++ b/tests/Query/RegexpTest.php @@ -5,12 +5,15 @@ use Elastica\Query\Regexp; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class RegexpTest extends BaseTest { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $field = 'name'; $value = 'ruf'; diff --git a/tests/Query/RescoreTest.php b/tests/Query/RescoreTest.php index e26c3a9c31..f2cfdb5b7e 100644 --- a/tests/Query/RescoreTest.php +++ b/tests/Query/RescoreTest.php @@ -8,12 +8,15 @@ use Elastica\Rescore\Query as QueryRescore; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class RescoreTest extends BaseTest { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $query = new Query(); $mainQuery = new Match(); @@ -53,7 +56,7 @@ public function testToArray() /** * @group unit */ - public function testSetSize() + public function testSetSize(): void { $query = new Query(); $mainQuery = new Match(); @@ -95,7 +98,7 @@ public function testSetSize() /** * @group unit */ - public function testSetWeights() + public function testSetWeights(): void { $query = new Query(); $mainQuery = new Match(); @@ -141,7 +144,7 @@ public function testSetWeights() /** * @group functional */ - public function testMultipleQueries() + public function testMultipleQueries(): void { $query = new Query(); $mainQuery = new Match(); @@ -213,7 +216,7 @@ public function testMultipleQueries() /** * @group functional */ - public function testQuery() + public function testQuery(): void { $query = new Query(); $mainQuery = new Match(); diff --git a/tests/Query/ScriptTest.php b/tests/Query/ScriptTest.php index 8351486645..f2e70d9bbf 100644 --- a/tests/Query/ScriptTest.php +++ b/tests/Query/ScriptTest.php @@ -6,12 +6,15 @@ use Elastica\Script\Script; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class ScriptTest extends BaseTest { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $string = '_score * 2.0'; @@ -33,7 +36,7 @@ public function testToArray() /** * @group unit */ - public function testSetScript() + public function testSetScript(): void { $string = '_score * 2.0'; $params = [ diff --git a/tests/Query/SimpleQueryStringTest.php b/tests/Query/SimpleQueryStringTest.php index 174384af3c..73e8c4b2fd 100644 --- a/tests/Query/SimpleQueryStringTest.php +++ b/tests/Query/SimpleQueryStringTest.php @@ -6,12 +6,15 @@ use Elastica\Query\SimpleQueryString; use Elastica\Test\Base; +/** + * @internal + */ class SimpleQueryStringTest extends Base { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $string = 'this is a test'; $fields = ['field1', 'field2']; @@ -34,7 +37,7 @@ public function testToArray() /** * @group functional */ - public function testQuery() + public function testQuery(): void { $index = $this->_createIndex(); $docs = [ @@ -62,7 +65,7 @@ public function testQuery() /** * @group unit */ - public function testSetMinimumShouldMatch() + public function testSetMinimumShouldMatch(): void { $expected = [ 'simple_query_string' => [ @@ -81,7 +84,7 @@ public function testSetMinimumShouldMatch() /** * @group functional */ - public function testSetMinimumShouldMatchWorks() + public function testSetMinimumShouldMatchWorks(): void { $this->_checkVersion('1.5'); diff --git a/tests/Query/SimpleTest.php b/tests/Query/SimpleTest.php index 65dcbe5957..a48a65453a 100644 --- a/tests/Query/SimpleTest.php +++ b/tests/Query/SimpleTest.php @@ -5,12 +5,15 @@ use Elastica\Query\Simple; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class SimpleTest extends BaseTest { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $testQuery = ['hello' => ['world'], 'name' => 'ruflin']; $query = new Simple($testQuery); diff --git a/tests/Query/SpanContainingTest.php b/tests/Query/SpanContainingTest.php index f4f2701791..6db60a310a 100644 --- a/tests/Query/SpanContainingTest.php +++ b/tests/Query/SpanContainingTest.php @@ -8,12 +8,15 @@ use Elastica\Query\SpanTerm; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class SpanContainingTest extends BaseTest { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $field = 'name'; $spanTermQuery1 = new SpanTerm([$field => 'nicolas']); @@ -60,7 +63,7 @@ public function testToArray() /** * @group functional */ - public function testSpanContaining() + public function testSpanContaining(): void { $field = 'lorem'; $value = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse odio lacus, aliquam nec nulla quis, aliquam eleifend eros.'; diff --git a/tests/Query/SpanFirstTest.php b/tests/Query/SpanFirstTest.php index 21a4930f62..4144cdb165 100644 --- a/tests/Query/SpanFirstTest.php +++ b/tests/Query/SpanFirstTest.php @@ -7,12 +7,15 @@ use Elastica\Query\SpanTerm; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class SpanFirstTest extends BaseTest { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $query = new SpanFirst(); $query->setMatch(new SpanTerm(['user' => 'kimchy'])); @@ -33,7 +36,7 @@ public function testToArray() /** * @group functional */ - public function testSpanNearTerm() + public function testSpanNearTerm(): void { $field = 'lorem'; $value = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse odio lacus, aliquam nec nulla quis, aliquam eleifend eros.'; diff --git a/tests/Query/SpanMultiTest.php b/tests/Query/SpanMultiTest.php index da6eb98887..056691f81e 100644 --- a/tests/Query/SpanMultiTest.php +++ b/tests/Query/SpanMultiTest.php @@ -10,12 +10,15 @@ use Elastica\Query\Wildcard; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class SpanMultiTest extends BaseTest { /** * @group unit */ - public function testConstructValid() + public function testConstructValid(): void { $field = 'name'; $value = 'marek'; @@ -56,7 +59,7 @@ public function testConstructValid() /** * @group functional */ - public function testSpanMulti() + public function testSpanMulti(): void { $field = 'lorem'; $text1 = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; diff --git a/tests/Query/SpanNearTest.php b/tests/Query/SpanNearTest.php index 0fabba34b4..e5b50e4530 100644 --- a/tests/Query/SpanNearTest.php +++ b/tests/Query/SpanNearTest.php @@ -8,12 +8,15 @@ use Elastica\Query\Term; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class SpanNearTest extends BaseTest { /** * @group unit */ - public function testConstructWrongTypeInvalid() + public function testConstructWrongTypeInvalid(): void { $this->expectException(\Elastica\Exception\InvalidException::class); @@ -25,7 +28,7 @@ public function testConstructWrongTypeInvalid() /** * @group unit */ - public function testConstructValid() + public function testConstructValid(): void { $field = 'name'; $spanTermQuery1 = new SpanTerm([$field => ['value' => 'marek', 'boost' => 1.5]]); @@ -61,7 +64,7 @@ public function testConstructValid() /** * @group functional */ - public function testSpanNearTerm() + public function testSpanNearTerm(): void { $field = 'lorem'; $value = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse odio lacus, aliquam nec nulla quis, aliquam eleifend eros.'; diff --git a/tests/Query/SpanNotTest.php b/tests/Query/SpanNotTest.php index 1c764595c5..66290f8c5c 100644 --- a/tests/Query/SpanNotTest.php +++ b/tests/Query/SpanNotTest.php @@ -8,12 +8,15 @@ use Elastica\Query\SpanTerm; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class SpanNotTest extends BaseTest { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $field = 'name'; $spanTermQuery1 = new SpanTerm([$field => 'nicolas']); @@ -60,7 +63,7 @@ public function testToArray() /** * @group functional */ - public function testSpanNot() + public function testSpanNot(): void { $field = 'lorem'; $value = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse odio lacus, aliquam nec nulla quis, aliquam eleifend eros.'; diff --git a/tests/Query/SpanOrTest.php b/tests/Query/SpanOrTest.php index e013a81514..892dc9c290 100644 --- a/tests/Query/SpanOrTest.php +++ b/tests/Query/SpanOrTest.php @@ -8,12 +8,15 @@ use Elastica\Query\Term; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class SpanOrTest extends BaseTest { /** * @group unit */ - public function testConstructWrongTypeInvalid() + public function testConstructWrongTypeInvalid(): void { $this->expectException(\Elastica\Exception\InvalidException::class); @@ -25,7 +28,7 @@ public function testConstructWrongTypeInvalid() /** * @group unit */ - public function testConstructValid() + public function testConstructValid(): void { $field = 'name'; $spanTermQuery1 = new SpanTerm([$field => ['value' => 'marek', 'boost' => 1.5]]); @@ -59,7 +62,7 @@ public function testConstructValid() /** * @group functional */ - public function testSpanOrTerm() + public function testSpanOrTerm(): void { $field = 'lorem'; $text1 = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; diff --git a/tests/Query/SpanTermTest.php b/tests/Query/SpanTermTest.php index a5f1665598..d3e4356e49 100644 --- a/tests/Query/SpanTermTest.php +++ b/tests/Query/SpanTermTest.php @@ -6,12 +6,15 @@ use Elastica\Query\SpanTerm; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class SpanTermTest extends BaseTest { /** * @group unit */ - public function testConstruct() + public function testConstruct(): void { $field = 'name'; $value = 'marek'; @@ -29,7 +32,7 @@ public function testConstruct() /** * @group functional */ - public function testSpanTerm() + public function testSpanTerm(): void { $field = 'name'; $value = 'match'; diff --git a/tests/Query/SpanWithinTest.php b/tests/Query/SpanWithinTest.php index 3623d10443..051eb5feae 100644 --- a/tests/Query/SpanWithinTest.php +++ b/tests/Query/SpanWithinTest.php @@ -8,12 +8,15 @@ use Elastica\Query\SpanWithin; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class SpanWithinTest extends BaseTest { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $field = 'name'; $spanTermQuery1 = new SpanTerm([$field => 'nicolas']); @@ -60,7 +63,7 @@ public function testToArray() /** * @group functional */ - public function testSpanWithin() + public function testSpanWithin(): void { $field = 'lorem'; $value = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse odio lacus, aliquam nec nulla quis, aliquam eleifend eros.'; diff --git a/tests/Query/TermTest.php b/tests/Query/TermTest.php index 40a42bfc81..d5b7ef70f3 100644 --- a/tests/Query/TermTest.php +++ b/tests/Query/TermTest.php @@ -5,12 +5,15 @@ use Elastica\Query\Term; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class TermTest extends BaseTest { /** * @group unit */ - public function testToArray() + public function testToArray(): void { $query = new Term(); $key = 'name'; @@ -29,7 +32,7 @@ public function testToArray() /** * @group unit */ - public function testDiacriticsValueToArray() + public function testDiacriticsValueToArray(): void { $query = new Term(); $key = 'name'; diff --git a/tests/Query/TermsTest.php b/tests/Query/TermsTest.php index 7fd9e97023..99e7063026 100644 --- a/tests/Query/TermsTest.php +++ b/tests/Query/TermsTest.php @@ -7,12 +7,15 @@ use Elastica\Query\Terms; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class TermsTest extends BaseTest { /** * @group functional */ - public function testFilteredSearch() + public function testFilteredSearch(): void { $index = $this->_createIndex(); @@ -40,7 +43,7 @@ public function testFilteredSearch() /** * @group functional */ - public function testFilteredSearchWithLookup() + public function testFilteredSearchWithLookup(): void { $index = $this->_createIndex(); @@ -97,8 +100,10 @@ public function provideMinimumArguments() /** * @group unit * @dataProvider provideMinimumArguments + * + * @param mixed $minimum */ - public function testSetMinimum($minimum) + public function testSetMinimum($minimum): void { $key = 'name'; $terms = ['nicolas', 'ruflin']; @@ -113,13 +118,13 @@ public function testSetMinimum($minimum) /** * @group unit */ - public function testSetTermsLookup() + public function testSetTermsLookup(): void { $key = 'name'; $terms = [ 'index' => 'index_name', 'type' => 'type_name', - 'id' => '1', + 'id' => '1', 'path' => 'terms', ]; @@ -132,7 +137,7 @@ public function testSetTermsLookup() /** * @group unit */ - public function testInvalidParams() + public function testInvalidParams(): void { $this->expectException(InvalidException::class); diff --git a/tests/Query/WildcardTest.php b/tests/Query/WildcardTest.php index b7a98f3005..c87e2ac363 100644 --- a/tests/Query/WildcardTest.php +++ b/tests/Query/WildcardTest.php @@ -7,12 +7,15 @@ use Elastica\Query\Wildcard; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class WildcardTest extends BaseTest { /** * @group unit */ - public function testConstructEmpty() + public function testConstructEmpty(): void { $wildcard = new Wildcard(); $this->assertEmpty($wildcard->getParams()); @@ -21,7 +24,7 @@ public function testConstructEmpty() /** * @group unit */ - public function testToArray() + public function testToArray(): void { $key = 'name'; $value = 'Ru*lin'; @@ -44,7 +47,7 @@ public function testToArray() /** * @group functional */ - public function testSearchWithAnalyzer() + public function testSearchWithAnalyzer(): void { $client = $this->_getClient(); $index = $client->getIndex('test'); diff --git a/tests/QueryBuilder/DSL/AbstractDSLTest.php b/tests/QueryBuilder/DSL/AbstractDSLTest.php index f84d208ec8..6034be90d7 100644 --- a/tests/QueryBuilder/DSL/AbstractDSLTest.php +++ b/tests/QueryBuilder/DSL/AbstractDSLTest.php @@ -8,7 +8,7 @@ abstract class AbstractDSLTest extends BaseTest { - protected function _assertImplemented(DSL $dsl, string $methodName, string $className, array $arguments) + protected function _assertImplemented(DSL $dsl, string $methodName, string $className, array $arguments): void { // Check method existence $this->assertTrue(\method_exists($dsl, $methodName)); @@ -28,7 +28,7 @@ protected function _assertImplemented(DSL $dsl, string $methodName, string $clas } } - protected function _assertNotImplemented(DSL $dsl, string $methodName, array $arguments) + protected function _assertNotImplemented(DSL $dsl, string $methodName, array $arguments): void { try { \call_user_func([$dsl, $methodName], $arguments); @@ -42,7 +42,7 @@ protected function _assertNotImplemented(DSL $dsl, string $methodName, array $ar * @param \ReflectionParameter[] $left * @param \ReflectionParameter[] $right */ - protected function _assertParametersEquals(array $left, array $right) + protected function _assertParametersEquals(array $left, array $right): void { $countLeft = \count($left); $this->assertCount($countLeft, $right, 'Parameters count mismatch'); diff --git a/tests/QueryBuilder/DSL/AggregationTest.php b/tests/QueryBuilder/DSL/AggregationTest.php index 27d0811ee4..bd964ba002 100644 --- a/tests/QueryBuilder/DSL/AggregationTest.php +++ b/tests/QueryBuilder/DSL/AggregationTest.php @@ -6,12 +6,15 @@ use Elastica\Query\Exists; use Elastica\QueryBuilder\DSL; +/** + * @internal + */ class AggregationTest extends AbstractDSLTest { /** * @group unit */ - public function testType() + public function testType(): void { $aggregationDSL = new DSL\Aggregation(); @@ -22,7 +25,7 @@ public function testType() /** * @group unit */ - public function testInterface() + public function testInterface(): void { $aggregationDSL = new DSL\Aggregation(); diff --git a/tests/QueryBuilder/DSL/CollapseTest.php b/tests/QueryBuilder/DSL/CollapseTest.php index 3f3bed60da..a4985bc03f 100644 --- a/tests/QueryBuilder/DSL/CollapseTest.php +++ b/tests/QueryBuilder/DSL/CollapseTest.php @@ -5,12 +5,15 @@ use Elastica\Collapse; use Elastica\QueryBuilder\DSL; +/** + * @internal + */ class CollapseTest extends AbstractDSLTest { /** * @group unit */ - public function testType() + public function testType(): void { $collapseDSL = new DSL\Collapse(); @@ -21,7 +24,7 @@ public function testType() /** * @group unit */ - public function testInterface() + public function testInterface(): void { $collapseDSL = new DSL\Collapse(); diff --git a/tests/QueryBuilder/DSL/QueryTest.php b/tests/QueryBuilder/DSL/QueryTest.php index 014a7dcbf9..7c0b0fb13c 100644 --- a/tests/QueryBuilder/DSL/QueryTest.php +++ b/tests/QueryBuilder/DSL/QueryTest.php @@ -6,12 +6,15 @@ use Elastica\Query\Match; use Elastica\QueryBuilder\DSL; +/** + * @internal + */ class QueryTest extends AbstractDSLTest { /** * @group unit */ - public function testType() + public function testType(): void { $queryDSL = new DSL\Query(); @@ -22,7 +25,7 @@ public function testType() /** * @group unit */ - public function testMatch() + public function testMatch(): void { $queryDSL = new DSL\Query(); @@ -34,7 +37,7 @@ public function testMatch() /** * @group unit */ - public function testInterface() + public function testInterface(): void { $queryDSL = new DSL\Query(); diff --git a/tests/QueryBuilder/DSL/SuggestTest.php b/tests/QueryBuilder/DSL/SuggestTest.php index 4196026219..cc323d4772 100644 --- a/tests/QueryBuilder/DSL/SuggestTest.php +++ b/tests/QueryBuilder/DSL/SuggestTest.php @@ -5,12 +5,15 @@ use Elastica\QueryBuilder\DSL; use Elastica\Suggest; +/** + * @internal + */ class SuggestTest extends AbstractDSLTest { /** * @group unit */ - public function testType() + public function testType(): void { $suggestDSL = new DSL\Suggest(); @@ -21,7 +24,7 @@ public function testType() /** * @group unit */ - public function testInterface() + public function testInterface(): void { $suggestDSL = new DSL\Suggest(); diff --git a/tests/QueryBuilder/VersionTest.php b/tests/QueryBuilder/VersionTest.php index a1c3ad1800..7cd8272624 100644 --- a/tests/QueryBuilder/VersionTest.php +++ b/tests/QueryBuilder/VersionTest.php @@ -8,6 +8,8 @@ /** * @group unit + * + * @internal */ class VersionTest extends BaseTest { diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index a2b2c96ba5..ba0660e078 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -9,12 +9,15 @@ use Elastica\QueryBuilder; use Elastica\Suggest\AbstractSuggest; +/** + * @internal + */ class QueryBuilderTest extends Base { /** * @group unit */ - public function testCustomDSL() + public function testCustomDSL(): void { $qb = new QueryBuilder(); @@ -37,7 +40,7 @@ public function testCustomDSL() /** * @group unit */ - public function testFacade() + public function testFacade(): void { $qb = new QueryBuilder(); diff --git a/tests/QueryTest.php b/tests/QueryTest.php index 1e72cc0a92..c7241a619e 100644 --- a/tests/QueryTest.php +++ b/tests/QueryTest.php @@ -17,12 +17,15 @@ use Elastica\Suggest; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class QueryTest extends BaseTest { /** * @group unit */ - public function testRawQuery() + public function testRawQuery(): void { $textQuery = new Term(['title' => 'test']); @@ -37,7 +40,7 @@ public function testRawQuery() /** * @group unit */ - public function testSuggestShouldNotRemoveOtherParameters() + public function testSuggestShouldNotRemoveOtherParameters(): void { $query1 = new Query(); $query2 = new Query(); @@ -57,7 +60,7 @@ public function testSuggestShouldNotRemoveOtherParameters() /** * @group unit */ - public function testSetSuggestMustReturnQueryInstance() + public function testSetSuggestMustReturnQueryInstance(): void { $query = new Query(); $suggest = new Suggest(); @@ -67,7 +70,7 @@ public function testSetSuggestMustReturnQueryInstance() /** * @group unit */ - public function testArrayQuery() + public function testArrayQuery(): void { $query = [ 'query' => [ @@ -88,7 +91,7 @@ public function testArrayQuery() /** * @group functional */ - public function testSetSort() + public function testSetSort(): void { $index = $this->_createIndex(); $index->setMapping(new Mapping([ @@ -135,7 +138,7 @@ public function testSetSort() /** * @group unit */ - public function testAddSort() + public function testAddSort(): void { $query = new Query(); $sortParam = ['firstname' => ['order' => 'asc']]; @@ -147,7 +150,7 @@ public function testAddSort() /** * @group unit */ - public function testSetTrackScores() + public function testSetTrackScores(): void { $query = new Query(); $param = false; @@ -159,7 +162,7 @@ public function testSetTrackScores() /** * @group unit */ - public function testSetRawQuery() + public function testSetRawQuery(): void { $query = new Query(); @@ -172,7 +175,7 @@ public function testSetRawQuery() /** * @group unit */ - public function testSetStoredFields() + public function testSetStoredFields(): void { $query = new Query(); @@ -190,7 +193,7 @@ public function testSetStoredFields() /** * @group unit */ - public function testGetQuery() + public function testGetQuery(): void { $query = new Query(); @@ -211,7 +214,7 @@ public function testGetQuery() /** * @group unit */ - public function testSetQueryToArrayCast() + public function testSetQueryToArrayCast(): void { $query = new Query(); $termQuery = new Term(); @@ -229,7 +232,7 @@ public function testSetQueryToArrayCast() /** * @group unit */ - public function testNotCloneInnerObjects() + public function testNotCloneInnerObjects(): void { $query = new Query(); $termQuery = new Term(); @@ -246,7 +249,7 @@ public function testNotCloneInnerObjects() /** * @group unit */ - public function testSetQueryToArrayChangeQuery() + public function testSetQueryToArrayChangeQuery(): void { $query = new Query(); $termQuery = new Term(); @@ -264,7 +267,7 @@ public function testSetQueryToArrayChangeQuery() /** * @group unit */ - public function testSetScriptFieldsToArrayCast() + public function testSetScriptFieldsToArrayCast(): void { $query = new Query(); $scriptFields = new ScriptFields(); @@ -283,7 +286,7 @@ public function testSetScriptFieldsToArrayCast() /** * @group unit */ - public function testAddScriptFieldsToArrayCast() + public function testAddScriptFieldsToArrayCast(): void { $query = new Query(); $scriptField = new Script('script'); @@ -301,7 +304,7 @@ public function testAddScriptFieldsToArrayCast() /** * @group unit */ - public function testAddScriptFieldToExistingScriptFields() + public function testAddScriptFieldToExistingScriptFields(): void { $script1 = new Script('s1'); $script2 = new Script('s2'); @@ -326,7 +329,7 @@ public function testAddScriptFieldToExistingScriptFields() /** * @group unit */ - public function testAddAggregationToArrayCast() + public function testAddAggregationToArrayCast(): void { $query = new Query(); $aggregation = new TermsAggregation('text'); @@ -345,7 +348,7 @@ public function testAddAggregationToArrayCast() /** * @group unit */ - public function testSetSuggestToArrayCast() + public function testSetSuggestToArrayCast(): void { $query = new Query(); $suggest = new Suggest(); @@ -364,7 +367,7 @@ public function testSetSuggestToArrayCast() /** * @group unit */ - public function testSetRescoreToArrayCast() + public function testSetRescoreToArrayCast(): void { $query = new Query(); $rescore = new RescoreQuery(); @@ -383,7 +386,7 @@ public function testSetRescoreToArrayCast() /** * @group unit */ - public function testSetPostFilterToArrayCast() + public function testSetPostFilterToArrayCast(): void { $query = new Query(); $postFilter = new Terms(); @@ -401,12 +404,13 @@ public function testSetPostFilterToArrayCast() /** * @group functional */ - public function testNoSource() + public function testNoSource(): void { $index = $this->_createIndex(); // Adds 1 document to the index - $doc1 = new Document(1, + $doc1 = new Document( + 1, ['username' => 'ruflin', 'test' => ['2', '3', '5']] ); $index->addDocument($doc1); @@ -439,7 +443,7 @@ public function testNoSource() /** * @group unit */ - public function testSetCollapseToArrayCast() + public function testSetCollapseToArrayCast(): void { $query = new Query(); $collapse = new Collapse(); @@ -458,7 +462,7 @@ public function testSetCollapseToArrayCast() /** * @group unit */ - public function testCollapseArrayStructure() + public function testCollapseArrayStructure(): void { $query = new Query(); $collapse = new Collapse(); @@ -494,7 +498,7 @@ public function testCollapseArrayStructure() /** * @group unit */ - public function testCollapseSecondLevelArrayStructure() + public function testCollapseSecondLevelArrayStructure(): void { $query = new Query(); $collapse = new Collapse(); @@ -507,7 +511,7 @@ public function testCollapseSecondLevelArrayStructure() ->setSort(['date' => 'asc']) ->setCollapse( (new Collapse()) - ->setFieldname('date') + ->setFieldname('date') ) ) ->setMaxConcurrentGroupSearches(4) @@ -556,6 +560,8 @@ public function provideSetTrackTotalHitsInvalidValue(): iterable /** * @group functional * @dataProvider provideSetTrackTotalHitsInvalidValue + * + * @param mixed $value */ public function testSetTrackTotalHitsInvalidValue($value): void { diff --git a/tests/ReindexTest.php b/tests/ReindexTest.php index 69a859f8e2..cedcd9cec9 100644 --- a/tests/ReindexTest.php +++ b/tests/ReindexTest.php @@ -12,12 +12,15 @@ use Elastica\Reindex; use Elastica\Script\Script; +/** + * @internal + */ class ReindexTest extends Base { /** * @group functional */ - public function testReindex() + public function testReindex(): void { $oldIndex = $this->_createIndex('idx1', true, 2); $this->_addDocs($oldIndex, 10); @@ -35,7 +38,7 @@ public function testReindex() /** * @group functional */ - public function testReindexOpTypeOptionWithProceedSetOnConflicts() + public function testReindexOpTypeOptionWithProceedSetOnConflicts(): void { $oldIndex = $this->_createIndex('idx1', true, 2); $docs1 = $this->_addDocs($oldIndex, 10); @@ -62,7 +65,7 @@ public function testReindexOpTypeOptionWithProceedSetOnConflicts() /** * @group functional */ - public function testReindexOpTypeOptionWithProceedSetOnConflictStop() + public function testReindexOpTypeOptionWithProceedSetOnConflictStop(): void { $oldIndex = $this->_createIndex('idx1', true, 2); $docs1 = $this->_addDocs($oldIndex, 10); @@ -88,7 +91,7 @@ public function testReindexOpTypeOptionWithProceedSetOnConflictStop() /** * @group functional */ - public function testReindexWithQueryOption() + public function testReindexWithQueryOption(): void { $oldIndex = $this->_createIndex('idx1', true, 2); $docs1 = $this->_addDocs($oldIndex, 10); @@ -113,7 +116,7 @@ public function testReindexWithQueryOption() /** * @group functional */ - public function testReindexWithSizeOption() + public function testReindexWithSizeOption(): void { $oldIndex = $this->_createIndex('idx1', true, 2); $this->_addDocs($oldIndex, 10); @@ -132,7 +135,7 @@ public function testReindexWithSizeOption() /** * @group functional */ - public function testReindexWithFalseSetOnWaitForCompletion() + public function testReindexWithFalseSetOnWaitForCompletion(): void { $oldIndex = $this->_createIndex('idx1', true, 2); $this->_addDocs($oldIndex, 10); @@ -155,7 +158,7 @@ public function testReindexWithFalseSetOnWaitForCompletion() /** * @group functional */ - public function testReindexWithScript() + public function testReindexWithScript(): void { $oldIndex = $this->_createIndex('idx1', true, 2); $this->_addDocs($oldIndex, 10); @@ -181,7 +184,7 @@ public function testReindexWithScript() /** * @group functional */ - public function testReindexWithRemote() + public function testReindexWithRemote(): void { $oldIndex = $this->_createIndex('idx1', true, 1); $newIndex = $this->_createIndex('idx2', true, 1); diff --git a/tests/RequestTest.php b/tests/RequestTest.php index 7e2e93a998..aa10c7418d 100644 --- a/tests/RequestTest.php +++ b/tests/RequestTest.php @@ -7,12 +7,15 @@ use Elastica\Response; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class RequestTest extends BaseTest { /** * @group unit */ - public function testConstructor() + public function testConstructor(): void { $path = 'test'; $method = Request::POST; @@ -30,7 +33,7 @@ public function testConstructor() /** * @group unit */ - public function testInvalidConnection() + public function testInvalidConnection(): void { $this->expectException(\Elastica\Exception\InvalidException::class); @@ -41,7 +44,7 @@ public function testInvalidConnection() /** * @group functional */ - public function testSend() + public function testSend(): void { $connection = new Connection(); $connection->setHost($this->_getHost()); @@ -57,7 +60,7 @@ public function testSend() /** * @group unit */ - public function testToString() + public function testToString(): void { $path = 'test'; $method = Request::POST; diff --git a/tests/ResponseFunctionalTest.php b/tests/ResponseFunctionalTest.php index 9f9ab568fe..bdfc0b17d8 100644 --- a/tests/ResponseFunctionalTest.php +++ b/tests/ResponseFunctionalTest.php @@ -12,6 +12,8 @@ /** * @group functional + * + * @internal */ class ResponseFunctionalTest extends BaseTest { diff --git a/tests/ResponseTest.php b/tests/ResponseTest.php index b91edf37db..3ee6265875 100644 --- a/tests/ResponseTest.php +++ b/tests/ResponseTest.php @@ -7,6 +7,8 @@ /** * @group unit + * + * @internal */ class ResponseTest extends BaseTest { diff --git a/tests/ResultSet/BuilderTest.php b/tests/ResultSet/BuilderTest.php index b02e705167..d696b031dc 100644 --- a/tests/ResultSet/BuilderTest.php +++ b/tests/ResultSet/BuilderTest.php @@ -9,6 +9,8 @@ /** * @group unit + * + * @internal */ class BuilderTest extends BaseTest { @@ -17,14 +19,14 @@ class BuilderTest extends BaseTest */ private $builder; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->builder = new DefaultBuilder(); } - public function testEmptyResponse() + public function testEmptyResponse(): void { $response = new Response(''); $query = new Query(); @@ -36,7 +38,7 @@ public function testEmptyResponse() $this->assertCount(0, $resultSet->getResults()); } - public function testResponse() + public function testResponse(): void { $response = new Response([ 'hits' => [ diff --git a/tests/ResultSet/ChainProcessorTest.php b/tests/ResultSet/ChainProcessorTest.php index d8968453ad..15b270e809 100644 --- a/tests/ResultSet/ChainProcessorTest.php +++ b/tests/ResultSet/ChainProcessorTest.php @@ -11,10 +11,12 @@ /** * @group unit + * + * @internal */ class ChainProcessorTest extends BaseTest { - public function testProcessor() + public function testProcessor(): void { $processor = new ChainProcessor([ $processor1 = $this->createMock(ProcessorInterface::class), @@ -24,10 +26,12 @@ public function testProcessor() $processor1->expects($this->once()) ->method('process') - ->with($resultSet); + ->with($resultSet) + ; $processor2->expects($this->once()) ->method('process') - ->with($resultSet); + ->with($resultSet) + ; $processor->process($resultSet); } diff --git a/tests/ResultSet/ProcessingBuilderTest.php b/tests/ResultSet/ProcessingBuilderTest.php index 781dfd414f..4fd312cee8 100644 --- a/tests/ResultSet/ProcessingBuilderTest.php +++ b/tests/ResultSet/ProcessingBuilderTest.php @@ -12,6 +12,8 @@ /** * @group unit + * + * @internal */ class ProcessingBuilderTest extends BaseTest { @@ -26,11 +28,11 @@ class ProcessingBuilderTest extends BaseTest private $innerBuilder; /** - * @var ProcessorInterface|PHPUnit_Framework_MockObject_MockObject + * @var PHPUnit_Framework_MockObject_MockObject|ProcessorInterface */ private $processor; - protected function setUp() + protected function setUp(): void { parent::setUp(); @@ -40,7 +42,7 @@ protected function setUp() $this->builder = new ProcessingBuilder($this->innerBuilder, $this->processor); } - public function testProcessors() + public function testProcessors(): void { $response = new Response(''); $query = new Query(); @@ -49,10 +51,12 @@ public function testProcessors() $this->innerBuilder->expects($this->once()) ->method('buildResultSet') ->with($response, $query) - ->willReturn($resultSet); + ->willReturn($resultSet) + ; $this->processor->expects($this->once()) ->method('process') - ->with($resultSet); + ->with($resultSet) + ; $this->builder->buildResultSet($response, $query); } diff --git a/tests/ResultSetTest.php b/tests/ResultSetTest.php index 951f2b5901..76620d4137 100644 --- a/tests/ResultSetTest.php +++ b/tests/ResultSetTest.php @@ -8,12 +8,15 @@ use Elastica\ResultSet; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class ResultSetTest extends BaseTest { /** * @group functional */ - public function testGetters() + public function testGetters(): void { $index = $this->_createIndex(); $index->addDocuments([ @@ -39,7 +42,7 @@ public function testGetters() /** * @group functional */ - public function testArrayAccess() + public function testArrayAccess(): void { $index = $this->_createIndex(); $index->addDocuments([ @@ -62,7 +65,7 @@ public function testArrayAccess() /** * @group functional */ - public function testDocumentsAccess() + public function testDocumentsAccess(): void { $index = $this->_createIndex(); $index->addDocuments([ @@ -90,7 +93,7 @@ public function testDocumentsAccess() /** * @group functional */ - public function testInvalidOffsetCreation() + public function testInvalidOffsetCreation(): void { $this->expectException(InvalidException::class); diff --git a/tests/ResultTest.php b/tests/ResultTest.php index ff96a928c9..86c49e63b1 100644 --- a/tests/ResultTest.php +++ b/tests/ResultTest.php @@ -7,12 +7,15 @@ use Elastica\Result; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class ResultTest extends BaseTest { /** * @group functional */ - public function testGetters() + public function testGetters(): void { // Creates a new index 'xodoa' $index = $this->_createIndex(); @@ -38,7 +41,7 @@ public function testGetters() /** * @group functional */ - public function testGetIdNoSource() + public function testGetIdNoSource(): void { // Creates a new index 'xodoa' $indexName = 'xodoa'; @@ -76,7 +79,7 @@ public function testGetIdNoSource() /** * @group functional */ - public function testGetTotalTimeReturnsExpectedResults() + public function testGetTotalTimeReturnsExpectedResults(): void { $index = $this->_createIndex(); @@ -95,13 +98,13 @@ public function testGetTotalTimeReturnsExpectedResults() 'integer', \gettype($resultSet->getTotalTime()), 'Total Time should be an integer' - ); + ); } /** * @group unit */ - public function testHasFields() + public function testHasFields(): void { $data = ['value set']; diff --git a/tests/Script/ScriptFieldsTest.php b/tests/Script/ScriptFieldsTest.php index 079ff9cfb4..7d14a974e0 100644 --- a/tests/Script/ScriptFieldsTest.php +++ b/tests/Script/ScriptFieldsTest.php @@ -8,12 +8,15 @@ use Elastica\Script\ScriptFields; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class ScriptFieldsTest extends BaseTest { /** * @group unit */ - public function testNewScriptFields() + public function testNewScriptFields(): void { $script = new Script('1 + 2'); @@ -39,7 +42,7 @@ public function testNewScriptFields() /** * @group unit */ - public function testSetScriptFields() + public function testSetScriptFields(): void { $query = new Query(); $script = new Script('1 + 2'); @@ -59,7 +62,7 @@ public function testSetScriptFields() /** * @group functional */ - public function testQuery() + public function testQuery(): void { $index = $this->_createIndex(); @@ -84,7 +87,7 @@ public function testQuery() /** * @group functional */ - public function testScriptFieldWithJoin() + public function testScriptFieldWithJoin(): void { $client = $this->_getClient(); $index = $client->getIndex('testscriptfieldwithjoin'); diff --git a/tests/Script/ScriptIdTest.php b/tests/Script/ScriptIdTest.php index d59e1c4fec..da6b2601a9 100644 --- a/tests/Script/ScriptIdTest.php +++ b/tests/Script/ScriptIdTest.php @@ -5,6 +5,9 @@ use Elastica\Script\ScriptId; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class ScriptIdTest extends BaseTest { private const SCRIPT_ID = 'my_script'; @@ -12,7 +15,7 @@ class ScriptIdTest extends BaseTest /** * @group unit */ - public function testConstructor() + public function testConstructor(): void { $script = new ScriptId(self::SCRIPT_ID); @@ -55,7 +58,7 @@ public function testConstructor() /** * @group unit */ - public function testCreateString() + public function testCreateString(): void { $script = ScriptId::create(self::SCRIPT_ID); @@ -72,7 +75,7 @@ public function testCreateString() /** * @group unit */ - public function testCreateScript() + public function testCreateScript(): void { $data = new ScriptId(self::SCRIPT_ID); @@ -85,7 +88,7 @@ public function testCreateScript() /** * @group unit */ - public function testCreateArray() + public function testCreateArray(): void { $params = [ 'param1' => 'one', @@ -112,8 +115,10 @@ public function testCreateArray() /** * @group unit * @dataProvider dataProviderCreateInvalid + * + * @param mixed $data */ - public function testCreateInvalid($data) + public function testCreateInvalid($data): void { $this->expectException(\Elastica\Exception\InvalidException::class); @@ -141,7 +146,7 @@ public function dataProviderCreateInvalid() /** * @group unit */ - public function testSetLang() + public function testSetLang(): void { $script = new ScriptId(self::SCRIPT_ID, [], ScriptId::LANG_PAINLESS); @@ -152,7 +157,7 @@ public function testSetLang() /** * @group unit */ - public function testSetScriptId() + public function testSetScriptId(): void { $script = new ScriptId(self::SCRIPT_ID); diff --git a/tests/Script/ScriptTest.php b/tests/Script/ScriptTest.php index 7569a8e2a4..4bd0400977 100644 --- a/tests/Script/ScriptTest.php +++ b/tests/Script/ScriptTest.php @@ -5,6 +5,9 @@ use Elastica\Script\Script; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class ScriptTest extends BaseTest { private const SCRIPT = "_score * doc['my_numeric_field'].value"; @@ -12,7 +15,7 @@ class ScriptTest extends BaseTest /** * @group unit */ - public function testConstructor() + public function testConstructor(): void { $script = new Script(self::SCRIPT); @@ -55,7 +58,7 @@ public function testConstructor() /** * @group unit */ - public function testCreateString() + public function testCreateString(): void { $script = Script::create(self::SCRIPT); @@ -72,7 +75,7 @@ public function testCreateString() /** * @group unit */ - public function testCreateScript() + public function testCreateScript(): void { $data = new Script(self::SCRIPT); @@ -85,7 +88,7 @@ public function testCreateScript() /** * @group unit */ - public function testCreateArray() + public function testCreateArray(): void { $params = [ 'param1' => 'one', @@ -112,8 +115,10 @@ public function testCreateArray() /** * @group unit * @dataProvider dataProviderCreateInvalid + * + * @param mixed $data */ - public function testCreateInvalid($data) + public function testCreateInvalid($data): void { $this->expectException(\Elastica\Exception\InvalidException::class); @@ -141,7 +146,7 @@ public function dataProviderCreateInvalid() /** * @group unit */ - public function testSetLang() + public function testSetLang(): void { $script = new Script(self::SCRIPT, [], Script::LANG_PAINLESS); @@ -152,7 +157,7 @@ public function testSetLang() /** * @group unit */ - public function testSetScript() + public function testSetScript(): void { $script = new Script(self::SCRIPT); diff --git a/tests/ScrollTest.php b/tests/ScrollTest.php index 8cb8fff2f9..38597a6c1b 100644 --- a/tests/ScrollTest.php +++ b/tests/ScrollTest.php @@ -8,6 +8,9 @@ use Elastica\Scroll; use Elastica\Search; +/** + * @internal + */ class ScrollTest extends Base { /** @@ -15,7 +18,7 @@ class ScrollTest extends Base * * @group functional */ - public function testForeach() + public function testForeach(): void { $search = $this->_prepareSearch(); $scroll = new Scroll($search); @@ -62,7 +65,7 @@ public function testForeach() * * @group functional */ - public function testSearchRevert() + public function testSearchRevert(): void { $search = $this->_prepareSearch(); @@ -84,7 +87,7 @@ public function testSearchRevert() * * @group functional */ - public function testEmptyScroll() + public function testEmptyScroll(): void { $search = $this->_prepareSearch(0); $scroll = new Scroll($search); @@ -104,7 +107,7 @@ public function testEmptyScroll() * * @group functional */ - public function testScrollWithIgnoreUnavailable() + public function testScrollWithIgnoreUnavailable(): void { $search = $this->_prepareSearch(); $search->addIndex('unavailable_index'); @@ -176,7 +179,7 @@ private function _prepareSearch(int $indexSize = 11): Search /** * Tests the number of open search contexts on ES. */ - private function _assertOpenSearchContexts(Client $client, int $count) + private function _assertOpenSearchContexts(Client $client, int $count): void { $stats = $client->getStatus()->getData(); $this->assertSame($count, $stats['_all']['total']['search']['open_contexts'], 'Open search contexts should match'); diff --git a/tests/SearchTest.php b/tests/SearchTest.php index 4f5b4342e9..120ffe8e50 100644 --- a/tests/SearchTest.php +++ b/tests/SearchTest.php @@ -19,12 +19,15 @@ use Elastica\Suggest; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class SearchTest extends BaseTest { /** * @group unit */ - public function testConstruct() + public function testConstruct(): void { $client = $this->_getClient(); $search = new Search($client); @@ -35,7 +38,7 @@ public function testConstruct() /** * @group functional */ - public function testAddIndex() + public function testAddIndex(): void { $client = $this->_getClient(); $search = new Search($client); @@ -67,7 +70,7 @@ public function testAddIndex() /** * @group unit */ - public function testAddIndices() + public function testAddIndices(): void { $client = $this->_getClient(); $search = new Search($client); @@ -84,7 +87,7 @@ public function testAddIndices() /** * @group unit */ - public function testAddIndexInvalid() + public function testAddIndexInvalid(): void { $this->expectException(InvalidException::class); @@ -97,7 +100,7 @@ public function testAddIndexInvalid() /** * @group unit */ - public function testAddNumericIndex() + public function testAddNumericIndex(): void { $client = $this->_getClient(); $search = new Search($client); @@ -110,7 +113,7 @@ public function testAddNumericIndex() /** * @group functional */ - public function testGetPath() + public function testGetPath(): void { $client = $this->_getClient(); $search1 = new Search($client); @@ -133,7 +136,7 @@ public function testGetPath() /** * @group functional */ - public function testSearchRequest() + public function testSearchRequest(): void { $client = $this->_getClient(); $search1 = new Search($client); @@ -154,7 +157,7 @@ public function testSearchRequest() /** * @group functional */ - public function testSearchScrollRequest() + public function testSearchScrollRequest(): void { $client = $this->_getClient(); @@ -209,7 +212,7 @@ public function testSearchScrollRequest() * * @group functional */ - public function testLimitDefaultSearch() + public function testLimitDefaultSearch(): void { $client = $this->_getClient(); $search = new Search($client); @@ -246,7 +249,7 @@ public function testLimitDefaultSearch() /** * @group functional */ - public function testArrayConfigSearch() + public function testArrayConfigSearch(): void { $client = $this->_getClient(); $search = new Search($client); @@ -310,7 +313,8 @@ public function testArrayConfigSearch() $suggestName = new Suggest((new Suggest\Term('name_suggest', 'username'))->setText('tes')); $typedKeysQuery = (new Query()) ->addAggregation($countIds) - ->setSuggest($suggestName); + ->setSuggest($suggestName) + ; $resultSet = $search->search($typedKeysQuery, [Search::OPTION_TYPED_KEYS => true]); $this->assertNotEmpty($resultSet->getAggregation('cardinality#count_ids')); $this->assertNotEmpty($resultSet->getSuggests(), 'term#name_suggest'); @@ -319,7 +323,8 @@ public function testArrayConfigSearch() $mockResponse = new Response(\json_encode(['timed_out' => true])); $client = $this->createMock(Client::class); $client->method('request') - ->will($this->returnValue($mockResponse)); + ->will($this->returnValue($mockResponse)) + ; $search = new Search($client); $script = new Script('Thread.sleep(100); return _score;'); $query = new FunctionScore(); @@ -331,7 +336,7 @@ public function testArrayConfigSearch() /** * @group functional */ - public function testInvalidConfigSearch() + public function testInvalidConfigSearch(): void { $this->expectException(InvalidException::class); @@ -344,7 +349,7 @@ public function testInvalidConfigSearch() /** * @group functional */ - public function testSearchWithVersionOption() + public function testSearchWithVersionOption(): void { $index = $this->_createIndex(); $doc = new Document(1, ['id' => 1, 'email' => 'test@test.com', 'username' => 'ruflin']); @@ -368,7 +373,7 @@ public function testSearchWithVersionOption() /** * @group functional */ - public function testSearchGet() + public function testSearchGet(): void { $client = $this->_getClient(); $search1 = new Search($client); @@ -380,7 +385,7 @@ public function testSearchGet() /** * @group functional */ - public function testCountRequest() + public function testCountRequest(): void { $client = $this->_getClient(); $search = new Search($client); @@ -424,7 +429,7 @@ public function testCountRequest() /** * @group functional */ - public function testCountRequestGet() + public function testCountRequestGet(): void { $client = $this->_getClient(); $search = new Search($client); @@ -468,7 +473,7 @@ public function testCountRequestGet() /** * @group functional */ - public function testEmptySearch() + public function testEmptySearch(): void { $client = $this->_getClient(); $search = new Search($client); @@ -510,7 +515,7 @@ public function testEmptySearch() /** * @group functional */ - public function testCount() + public function testCount(): void { $index = $this->_createIndex(); $search = new Search($index->getClient()); @@ -533,7 +538,7 @@ public function testCount() /** * @group functional */ - public function testIgnoreUnavailableOption() + public function testIgnoreUnavailableOption(): void { $client = $this->_getClient(); $index = $client->getIndex('elastica_7086b4c2ee585bbb6740ece5ed7ece01'); @@ -560,7 +565,7 @@ public function testIgnoreUnavailableOption() /** * @group functional */ - public function testQuerySizeAfterCount() + public function testQuerySizeAfterCount(): void { $client = $this->_getClient(); $search = new Search($client); diff --git a/tests/SnapshotTest.php b/tests/SnapshotTest.php index e8614d3b9e..4c17c07f33 100644 --- a/tests/SnapshotTest.php +++ b/tests/SnapshotTest.php @@ -9,6 +9,8 @@ /** * @group functional + * + * @internal */ class SnapshotTest extends Base { @@ -30,7 +32,7 @@ class SnapshotTest extends Base */ protected $docs; - protected function setUp() + protected function setUp(): void { parent::setUp(); $this->snapshot = new Snapshot($this->_getClient()); diff --git a/tests/StatusTest.php b/tests/StatusTest.php index 08f5fcac39..88d0a80910 100644 --- a/tests/StatusTest.php +++ b/tests/StatusTest.php @@ -7,12 +7,15 @@ use Elastica\Status; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class StatusTest extends BaseTest { /** * @group functional */ - public function testGetResponse() + public function testGetResponse(): void { $index = $this->_createIndex(); $status = new Status($index->getClient()); @@ -22,7 +25,7 @@ public function testGetResponse() /** * @group functional */ - public function testGetIndexNames() + public function testGetIndexNames(): void { $indexName = 'test'; $client = $this->_getClient(); @@ -46,7 +49,7 @@ public function testGetIndexNames() /** * @group functional */ - public function testIndexExists() + public function testIndexExists(): void { $indexName = 'elastica_test'; $aliasName = 'elastica_test-alias'; @@ -72,7 +75,7 @@ public function testIndexExists() /** * @group functional */ - public function testAliasExists() + public function testAliasExists(): void { $aliasName = 'elastica_test-alias'; @@ -95,6 +98,8 @@ public function testAliasExists() $this->assertEquals([$indexName], \array_map( function ($index) { return $index->getName(); - }, $indicesWithAlias)); + }, + $indicesWithAlias + )); } } diff --git a/tests/Suggest/CompletionTest.php b/tests/Suggest/CompletionTest.php index cc636f6998..12e21d0e39 100644 --- a/tests/Suggest/CompletionTest.php +++ b/tests/Suggest/CompletionTest.php @@ -10,65 +10,15 @@ use Elastica\Suggest\Completion; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class CompletionTest extends BaseTest { - /** - * @return Index - */ - protected function _getIndexForTest() - { - $index = $this->_createIndex(); - $index->setMapping(new Mapping([ - 'fieldName' => [ - 'type' => 'completion', - ], - 'fieldName2' => [ - 'type' => 'completion', - ], - ])); - - $index->addDocuments([ - new Document(1, [ - 'fieldName' => [ - 'input' => ['Nevermind', 'Nirvana'], - 'weight' => 5, - ], - ]), - new Document(2, [ - 'fieldName' => [ - 'input' => ['Bleach', 'Nirvana'], - 'weight' => 2, - ], - ]), - new Document(3, [ - 'fieldName' => [ - 'input' => ['Incesticide', 'Nirvana'], - 'weight' => 7, - ], - ]), - new Document(4, [ - 'fieldName2' => [ - 'input' => ['Bleach', 'Nirvana'], - 'weight' => 3, - ], - ]), - new Document(5, [ - 'fieldName2' => [ - 'input' => ['Incesticide', 'Nirvana'], - 'weight' => 3, - ], - ]), - ]); - - $index->refresh(); - - return $index; - } - /** * @group unit */ - public function testToArray() + public function testToArray(): void { $suggest = new Completion('suggestName', 'fieldName'); $suggest->setPrefix('foo'); @@ -86,7 +36,7 @@ public function testToArray() /** * @group functional */ - public function testSuggestWorks() + public function testSuggestWorks(): void { $suggest = new Completion('suggestName', 'fieldName'); $suggest->setPrefix('Never'); @@ -106,7 +56,7 @@ public function testSuggestWorks() /** * @group functional */ - public function testFuzzySuggestWorks() + public function testFuzzySuggestWorks(): void { $suggest = new Completion('suggestName', 'fieldName'); $suggest->setFuzzy(['fuzziness' => 2]); @@ -127,7 +77,7 @@ public function testFuzzySuggestWorks() /** * @group functional */ - public function testCompletion() + public function testCompletion(): void { $suggest = new Completion('suggestName1', 'fieldName'); $suggest->setPrefix('Neavermint'); @@ -142,21 +92,21 @@ public function testCompletion() $query = Query::create($sug); $expectedSuggestions = [ - 'suggestName1' => [ - 0 => [ - 'text' => 'Neavermint', - 'offset' => 0, - 'length' => 10, - 'options' => [], - ], - ], + 'suggestName1' => [ + 0 => [ + 'text' => 'Neavermint', + 'offset' => 0, + 'length' => 10, + 'options' => [], + ], + ], 'suggestName2' => [ 0 => [ 'text' => 'Neverdint', 'offset' => 0, 'length' => 9, 'options' => [], - ], + ], ], ]; @@ -169,7 +119,7 @@ public function testCompletion() /** * @group unit */ - public function testSetFuzzy() + public function testSetFuzzy(): void { $suggest = new Completion('suggestName', 'fieldName'); @@ -188,7 +138,7 @@ public function testSetFuzzy() /** * @group functional */ - public function testRegexSuggestWorks() + public function testRegexSuggestWorks(): void { $suggest = new Completion('suggestName', 'fieldName'); $suggest->setRegex('n[ever|i]r'); @@ -200,4 +150,57 @@ public function testRegexSuggestWorks() $options = $suggests['suggestName'][0]['options']; $this->assertCount(3, $options); } + + /** + * @return Index + */ + protected function _getIndexForTest() + { + $index = $this->_createIndex(); + $index->setMapping(new Mapping([ + 'fieldName' => [ + 'type' => 'completion', + ], + 'fieldName2' => [ + 'type' => 'completion', + ], + ])); + + $index->addDocuments([ + new Document(1, [ + 'fieldName' => [ + 'input' => ['Nevermind', 'Nirvana'], + 'weight' => 5, + ], + ]), + new Document(2, [ + 'fieldName' => [ + 'input' => ['Bleach', 'Nirvana'], + 'weight' => 2, + ], + ]), + new Document(3, [ + 'fieldName' => [ + 'input' => ['Incesticide', 'Nirvana'], + 'weight' => 7, + ], + ]), + new Document(4, [ + 'fieldName2' => [ + 'input' => ['Bleach', 'Nirvana'], + 'weight' => 3, + ], + ]), + new Document(5, [ + 'fieldName2' => [ + 'input' => ['Incesticide', 'Nirvana'], + 'weight' => 3, + ], + ]), + ]); + + $index->refresh(); + + return $index; + } } diff --git a/tests/Suggest/PhraseTest.php b/tests/Suggest/PhraseTest.php index 1aeed56408..cb13a7663b 100644 --- a/tests/Suggest/PhraseTest.php +++ b/tests/Suggest/PhraseTest.php @@ -9,30 +9,15 @@ use Elastica\Suggest\Phrase; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class PhraseTest extends BaseTest { - /** - * @return Index - */ - protected function _getIndexForTest() - { - $index = $this->_createIndex(); - $index->addDocuments([ - new Document(1, ['text' => 'Github is pretty cool']), - new Document(2, ['text' => 'Elasticsearch is bonsai cool']), - new Document(3, ['text' => 'This is a test phrase']), - new Document(4, ['text' => 'Another sentence for testing']), - new Document(5, ['text' => 'Some more words here']), - ]); - $index->refresh(); - - return $index; - } - /** * @group unit */ - public function testToArray() + public function testToArray(): void { $suggest = new Suggest(); $phraseSuggest = new Phrase('suggest1', 'text'); @@ -60,7 +45,7 @@ public function testToArray() /** * @group functional */ - public function testPhraseSuggest() + public function testPhraseSuggest(): void { $suggest = new Suggest(); $phraseSuggest = new Phrase('suggest1', 'text'); @@ -79,4 +64,22 @@ public function testPhraseSuggest() $this->assertEquals('elasticsearch is bonsai cool', $suggests['suggest1'][0]['options'][0]['highlighted']); $this->assertEquals('elasticsearch is bonsai cool', $suggests['suggest1'][0]['options'][0]['text']); } + + /** + * @return Index + */ + protected function _getIndexForTest() + { + $index = $this->_createIndex(); + $index->addDocuments([ + new Document(1, ['text' => 'Github is pretty cool']), + new Document(2, ['text' => 'Elasticsearch is bonsai cool']), + new Document(3, ['text' => 'This is a test phrase']), + new Document(4, ['text' => 'Another sentence for testing']), + new Document(5, ['text' => 'Some more words here']), + ]); + $index->refresh(); + + return $index; + } } diff --git a/tests/Suggest/TermTest.php b/tests/Suggest/TermTest.php index ed128f2823..29a379b232 100644 --- a/tests/Suggest/TermTest.php +++ b/tests/Suggest/TermTest.php @@ -8,31 +8,15 @@ use Elastica\Suggest\Term; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class TermTest extends BaseTest { - /** - * @return Index - */ - protected function _getIndexForTest() - { - $index = $this->_createIndex(); - $index->addDocuments([ - new Document(1, ['id' => 1, 'text' => 'GitHub']), - new Document(2, ['id' => 1, 'text' => 'Elastic']), - new Document(3, ['id' => 1, 'text' => 'Search']), - new Document(4, ['id' => 1, 'text' => 'Food']), - new Document(5, ['id' => 1, 'text' => 'Flood']), - new Document(6, ['id' => 1, 'text' => 'Folks']), - ]); - $index->refresh(); - - return $index; - } - /** * @group unit */ - public function testToArray() + public function testToArray(): void { $suggest = new Suggest(); @@ -70,7 +54,7 @@ public function testToArray() /** * @group unit */ - public function testDistanceAlgorithm() + public function testDistanceAlgorithm(): void { $suggest = new Suggest(); @@ -110,7 +94,7 @@ public function testDistanceAlgorithm() /** * @group functional */ - public function testSuggestResults() + public function testSuggestResults(): void { $suggest = new Suggest(); $suggest1 = new Term('suggest1', 'text'); @@ -136,7 +120,7 @@ public function testSuggestResults() /** * @group functional */ - public function testSuggestNoResults() + public function testSuggestNoResults(): void { $termSuggest = new Term('suggest1', 'text'); $termSuggest->setText('Foobar')->setSize(4); @@ -150,4 +134,23 @@ public function testSuggestNoResults() $suggests = $result->getSuggests(); $this->assertCount(0, $suggests['suggest1'][0]['options']); } + + /** + * @return Index + */ + protected function _getIndexForTest() + { + $index = $this->_createIndex(); + $index->addDocuments([ + new Document(1, ['id' => 1, 'text' => 'GitHub']), + new Document(2, ['id' => 1, 'text' => 'Elastic']), + new Document(3, ['id' => 1, 'text' => 'Search']), + new Document(4, ['id' => 1, 'text' => 'Food']), + new Document(5, ['id' => 1, 'text' => 'Flood']), + new Document(6, ['id' => 1, 'text' => 'Folks']), + ]); + $index->refresh(); + + return $index; + } } diff --git a/tests/SuggestTest.php b/tests/SuggestTest.php index b559877cb1..5e50bebe06 100644 --- a/tests/SuggestTest.php +++ b/tests/SuggestTest.php @@ -8,6 +8,9 @@ use Elastica\Suggest\Term; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class SuggestTest extends BaseTest { /** @@ -15,7 +18,7 @@ class SuggestTest extends BaseTest * * @group functional */ - public function testCreateSelf() + public function testCreateSelf(): void { $suggest = new Suggest(); @@ -29,7 +32,7 @@ public function testCreateSelf() * * @group functional */ - public function testCreateWithSuggest() + public function testCreateWithSuggest(): void { $suggest1 = new Term('suggest1', '_all'); @@ -43,7 +46,7 @@ public function testCreateWithSuggest() * * @group functional */ - public function testCreateWithNonSuggest() + public function testCreateWithNonSuggest(): void { try { Suggest::create(new BoolQuery()); diff --git a/tests/TaskTest.php b/tests/TaskTest.php index 88b80b6f61..973e4ccb81 100644 --- a/tests/TaskTest.php +++ b/tests/TaskTest.php @@ -5,12 +5,15 @@ use Elastica\Document; use Elastica\Task; +/** + * @internal + */ class TaskTest extends Base { /** * @group functional */ - public function testGetData() + public function testGetData(): void { $task = $this->_createTask(); $data = $task->getData(); @@ -22,7 +25,7 @@ public function testGetData() /** * @group functional */ - public function testGetId() + public function testGetId(): void { $task = $this->_createTask(); $data = $task->getData(); @@ -34,7 +37,7 @@ public function testGetId() /** * @group functional */ - public function testIsComplete() + public function testIsComplete(): void { $task = $this->_createTask(); @@ -52,7 +55,7 @@ public function testIsComplete() /** * @group functional */ - public function testRefreshWithOptionsContainingOnWaitForResponseTrue() + public function testRefreshWithOptionsContainingOnWaitForResponseTrue(): void { $task = $this->_createTask(); $task->refresh([Task::WAIT_FOR_COMPLETION => Task::WAIT_FOR_COMPLETION_TRUE]); @@ -62,7 +65,7 @@ public function testRefreshWithOptionsContainingOnWaitForResponseTrue() /** * @group unit */ - public function testCancelThrowsExceptionWithEmptyTaskId() + public function testCancelThrowsExceptionWithEmptyTaskId(): void { $this->expectException(\Exception::class); $this->expectExceptionMessage('No task id given'); @@ -74,7 +77,7 @@ public function testCancelThrowsExceptionWithEmptyTaskId() /** * @group functional */ - public function testCancelDoesntCancelCompletedTasks() + public function testCancelDoesntCancelCompletedTasks(): void { $task = $this->_createTask(); $task->refresh([Task::WAIT_FOR_COMPLETION => Task::WAIT_FOR_COMPLETION_TRUE]); diff --git a/tests/Transport/AbstractTransportTest.php b/tests/Transport/AbstractTransportTest.php index 31afd3a29e..607f36eef8 100644 --- a/tests/Transport/AbstractTransportTest.php +++ b/tests/Transport/AbstractTransportTest.php @@ -10,6 +10,9 @@ use Elastica\Transport\AbstractTransport; use Elastica\Transport\Http; +/** + * @internal + */ class AbstractTransportTest extends BaseTest { /** @@ -50,8 +53,10 @@ public function getValidDefinitions() /** * @group unit * @dataProvider getValidDefinitions + * + * @param mixed $transport */ - public function testCanCreateTransportInstances($transport) + public function testCanCreateTransportInstances($transport): void { $connection = new Connection(); $params = []; @@ -71,8 +76,10 @@ public function getInvalidDefinitions() /** * @group unit * @dataProvider getInvalidDefinitions + * + * @param mixed $transport */ - public function testThrowsExecptionOnInvalidTransportDefinition($transport) + public function testThrowsExecptionOnInvalidTransportDefinition($transport): void { $this->expectException(\Elastica\Exception\InvalidException::class); $this->expectExceptionMessage('Invalid transport'); @@ -83,7 +90,7 @@ public function testThrowsExecptionOnInvalidTransportDefinition($transport) /** * @group unit */ - public function testCanInjectParamsWhenUsingArray() + public function testCanInjectParamsWhenUsingArray(): void { $connection = new Connection(); $params = [ @@ -109,8 +116,10 @@ public function testCanInjectParamsWhenUsingArray() * * @group functional * @dataProvider getTransport + * + * @param mixed $transport */ - public function testBooleanStringValues($transport) + public function testBooleanStringValues($transport): void { $client = $this->_getClient($transport); $index = $client->getIndex('elastica_testbooleanstringvalues'); diff --git a/tests/Transport/AwsAuthV4Test.php b/tests/Transport/AwsAuthV4Test.php index 6ae409ae0e..6f70911c0f 100644 --- a/tests/Transport/AwsAuthV4Test.php +++ b/tests/Transport/AwsAuthV4Test.php @@ -7,9 +7,12 @@ use Elastica\Exception\Connection\GuzzleException; use GuzzleHttp\Exception\RequestException; +/** + * @internal + */ class AwsAuthV4Test extends GuzzleTest { - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { if (!\class_exists('Aws\\Sdk')) { self::markTestSkipped('aws/aws-sdk-php package should be installed to run SignatureV4 transport tests'); @@ -19,7 +22,7 @@ public static function setUpBeforeClass() /** * @group unit */ - public function testSignsWithProvidedCredentialProvider() + public function testSignsWithProvidedCredentialProvider(): void { $config = [ 'persistent' => false, @@ -57,7 +60,7 @@ public function testSignsWithProvidedCredentialProvider() /** * @group unit */ - public function testPrefersCredentialProviderToHardCodedCredentials() + public function testPrefersCredentialProviderToHardCodedCredentials(): void { $config = [ 'persistent' => false, @@ -98,7 +101,7 @@ public function testPrefersCredentialProviderToHardCodedCredentials() /** * @group unit */ - public function testSignsWithProvidedCredentials() + public function testSignsWithProvidedCredentials(): void { $config = [ 'persistent' => false, @@ -133,7 +136,7 @@ public function testSignsWithProvidedCredentials() } } - public function testUseHttpAsDefaultProtocol() + public function testUseHttpAsDefaultProtocol(): void { $config = [ 'persistent' => false, @@ -157,7 +160,7 @@ public function testUseHttpAsDefaultProtocol() } } - public function testSetHttpsIfItIsRequired() + public function testSetHttpsIfItIsRequired(): void { $config = [ 'persistent' => false, @@ -182,7 +185,7 @@ public function testSetHttpsIfItIsRequired() } } - public function testSignsWithEnvironmentalCredentials() + public function testSignsWithEnvironmentalCredentials(): void { $config = [ 'persistent' => false, diff --git a/tests/Transport/GuzzleTest.php b/tests/Transport/GuzzleTest.php index 90a1a461b1..962cca542f 100644 --- a/tests/Transport/GuzzleTest.php +++ b/tests/Transport/GuzzleTest.php @@ -7,19 +7,33 @@ use Elastica\ResultSet\DefaultBuilder; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class GuzzleTest extends BaseTest { - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { if (!\class_exists('GuzzleHttp\\Client')) { self::markTestSkipped('guzzlehttp/guzzle package should be installed to run guzzle transport tests'); } } + protected function setUp(): void + { + \putenv('http_proxy='); + } + + protected function tearDown(): void + { + parent::tearDown(); + \putenv('http_proxy='); + } + /** * @group functional */ - public function testWithEnvironmentalProxy() + public function testWithEnvironmentalProxy(): void { $this->checkProxy($this->_getProxyUrl()); \putenv('http_proxy='.$this->_getProxyUrl().'/'); @@ -38,7 +52,7 @@ public function testWithEnvironmentalProxy() /** * @group functional */ - public function testWithEnabledEnvironmentalProxy() + public function testWithEnabledEnvironmentalProxy(): void { $this->checkProxy($this->_getProxyUrl403()); \putenv('http_proxy='.$this->_getProxyUrl403().'/'); @@ -58,7 +72,7 @@ public function testWithEnabledEnvironmentalProxy() /** * @group functional */ - public function testWithProxy() + public function testWithProxy(): void { $this->checkProxy($this->_getProxyUrl()); $client = $this->_getClient(['transport' => 'Guzzle', 'persistent' => false]); @@ -71,7 +85,7 @@ public function testWithProxy() /** * @group functional */ - public function testWithoutProxy() + public function testWithoutProxy(): void { $client = $this->_getClient(['transport' => 'Guzzle', 'persistent' => false]); $client->getConnection()->setProxy(''); @@ -83,7 +97,7 @@ public function testWithoutProxy() /** * @group functional */ - public function testBodyReuse() + public function testBodyReuse(): void { $client = $this->_getClient(['transport' => 'Guzzle', 'persistent' => false]); $index = $client->getIndex('elastica_body_reuse_test'); @@ -115,7 +129,7 @@ public function testBodyReuse() /** * @group unit */ - public function testInvalidConnection() + public function testInvalidConnection(): void { $this->expectException(\Elastica\Exception\Connection\GuzzleException::class); @@ -124,20 +138,9 @@ public function testInvalidConnection() $client->request('_status', 'GET'); } - protected function checkProxy($url) + protected function checkProxy($url): void { $url = \parse_url($url); $this->_checkConnection($url['host'], $url['port']); } - - protected function setUp() - { - \putenv('http_proxy='); - } - - protected function tearDown() - { - parent::tearDown(); - \putenv('http_proxy='); - } } diff --git a/tests/Transport/HttpTest.php b/tests/Transport/HttpTest.php index 8d9e233c21..778f516d9d 100644 --- a/tests/Transport/HttpTest.php +++ b/tests/Transport/HttpTest.php @@ -7,12 +7,21 @@ use Elastica\ResultSet\DefaultBuilder; use Elastica\Test\Base as BaseTest; +/** + * @internal + */ class HttpTest extends BaseTest { + protected function tearDown(): void + { + parent::tearDown(); + \putenv('http_proxy='); + } + /** * @group functional */ - public function testCurlNobodyOptionIsResetAfterHeadRequest() + public function testCurlNobodyOptionIsResetAfterHeadRequest(): void { $client = $this->_getClient(); $index = $client->getIndex('curl_test'); @@ -40,7 +49,7 @@ public function testCurlNobodyOptionIsResetAfterHeadRequest() /** * @group functional */ - public function testUnicodeData() + public function testUnicodeData(): void { $client = $this->_getClient(); $index = $client->getIndex('curl_test'); @@ -73,7 +82,7 @@ public function testUnicodeData() /** * @group functional */ - public function testWithEnvironmentalProxy() + public function testWithEnvironmentalProxy(): void { $this->checkProxy($this->_getProxyUrl()); \putenv('http_proxy='.$this->_getProxyUrl().'/'); @@ -92,7 +101,7 @@ public function testWithEnvironmentalProxy() /** * @group functional */ - public function testWithEnabledEnvironmentalProxy() + public function testWithEnabledEnvironmentalProxy(): void { $this->checkProxy($this->_getProxyUrl403()); \putenv('http_proxy='.$this->_getProxyUrl403().'/'); @@ -109,7 +118,7 @@ public function testWithEnabledEnvironmentalProxy() /** * @group functional */ - public function testWithProxy() + public function testWithProxy(): void { $this->checkProxy($this->_getProxyUrl()); $client = $this->_getClient(); @@ -122,7 +131,7 @@ public function testWithProxy() /** * @group functional */ - public function testWithoutProxy() + public function testWithoutProxy(): void { $client = $this->_getClient(); $client->getConnection()->setProxy(''); @@ -134,7 +143,7 @@ public function testWithoutProxy() /** * @group functional */ - public function testBodyReuse() + public function testBodyReuse(): void { $client = $this->_getClient(); @@ -167,7 +176,7 @@ public function testBodyReuse() /** * @group functional */ - public function testRequestSuccessWithHttpCompressionEnabled() + public function testRequestSuccessWithHttpCompressionEnabled(): void { $client = $this->_getClient(['transport' => ['type' => 'Http', 'compression' => true, 'curl' => [CURLINFO_HEADER_OUT => true]]]); @@ -183,7 +192,7 @@ public function testRequestSuccessWithHttpCompressionEnabled() /** * @group functional */ - public function testRequestSuccessWithHttpCompressionDisabled() + public function testRequestSuccessWithHttpCompressionDisabled(): void { $client = $this->_getClient(['transport' => ['type' => 'Http', 'compression' => false, 'curl' => [CURLINFO_HEADER_OUT => true]]]); @@ -196,15 +205,9 @@ public function testRequestSuccessWithHttpCompressionDisabled() $this->assertArrayHasKey('acknowledged', $createIndexResponse->getData()); } - protected function checkProxy($url) + protected function checkProxy($url): void { $url = \parse_url($url); $this->_checkConnection($url['host'], $url['port']); } - - protected function tearDown() - { - parent::tearDown(); - \putenv('http_proxy='); - } } diff --git a/tests/Transport/NullTransportTest.php b/tests/Transport/NullTransportTest.php index cae64bb3b9..95e0c17bcf 100644 --- a/tests/Transport/NullTransportTest.php +++ b/tests/Transport/NullTransportTest.php @@ -14,13 +14,15 @@ * * @author James Boehmer * @author Jan Domanski + * + * @internal */ class NullTransportTest extends BaseTest { /** @var NullTransport NullTransport */ protected $transport; - public function setUp() + public function setUp(): void { parent::setUp(); $this->transport = new NullTransport(); @@ -29,7 +31,7 @@ public function setUp() /** * @group functional */ - public function testEmptyResult() + public function testEmptyResult(): void { // Creates a client with any destination, and verify it returns a response object when executed $client = $this->_getClient(); @@ -74,7 +76,7 @@ public function testEmptyResult() /** * @group functional */ - public function testExec() + public function testExec(): void { $request = new Request('/test'); $params = ['name' => 'ruflin']; @@ -90,7 +92,7 @@ public function testExec() /** * @group unit */ - public function testResponse() + public function testResponse(): void { $resposeString = ''; $response = new Response($resposeString); @@ -101,7 +103,7 @@ public function testResponse() /** * @group unit */ - public function testGenerateDefaultResponse() + public function testGenerateDefaultResponse(): void { $params = ['blah' => 123]; $response = $this->transport->generateDefaultResponse($params); diff --git a/tests/Transport/TransportBenchmarkTest.php b/tests/Transport/TransportBenchmarkTest.php index 2b5dd542af..e2fe5e95ff 100644 --- a/tests/Transport/TransportBenchmarkTest.php +++ b/tests/Transport/TransportBenchmarkTest.php @@ -13,6 +13,8 @@ /** * @group benchmark + * + * @internal */ class TransportBenchmarkTest extends BaseTest { @@ -20,24 +22,15 @@ class TransportBenchmarkTest extends BaseTest protected $_maxData = 20; protected static $_results = []; - protected function setUp() - { - parent::setUp(); - $this->markTestSkipped('Benchmarks currently skipped: it has to be reworked'); - } - - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { self::printResults(); } - protected function getIndex(array $config): Index + protected function setUp(): void { - $client = $this->_getClient($config); - $index = $client->getIndex('benchmark'.self::buildUniqueId()); - $index->create(['index' => ['number_of_shards' => 1, 'number_of_replicas' => 0]], true); - - return $index; + parent::setUp(); + $this->markTestSkipped('Benchmarks currently skipped: it has to be reworked'); } /** @@ -66,6 +59,8 @@ public function testAddDocument(array $config, string $transport): void /** * @depends testAddDocument * @dataProvider providerTransport + * + * @param mixed $transport */ public function testRandomRead(array $config, $transport): void { @@ -89,6 +84,8 @@ public function testRandomRead(array $config, $transport): void /** * @depends testAddDocument * @dataProvider providerTransport + * + * @param mixed $transport */ public function testBulk(array $config, $transport): void { @@ -154,11 +151,11 @@ public function testGetMapping(array $config, string $transport): void public function providerTransport(): iterable { yield [[ - 'transport' => 'Http', - 'host' => $this->_getHost(), - 'port' => $this->_getPort(), - 'persistent' => false, - ], + 'transport' => 'Http', + 'host' => $this->_getHost(), + 'port' => $this->_getPort(), + 'persistent' => false, + ], 'Http:NotPersistent', ]; yield [[ @@ -166,9 +163,18 @@ public function providerTransport(): iterable 'host' => $this->_getHost(), 'port' => $this->_getPort(), 'persistent' => true, - ], + ], 'Http:Persistent', - ]; + ]; + } + + protected function getIndex(array $config): Index + { + $client = $this->_getClient($config); + $index = $client->getIndex('benchmark'.self::buildUniqueId()); + $index->create(['index' => ['number_of_shards' => 1, 'number_of_replicas' => 0]], true); + + return $index; } protected function getData(string $test): array diff --git a/tests/UtilTest.php b/tests/UtilTest.php index 5057d5e399..02f162a1c5 100644 --- a/tests/UtilTest.php +++ b/tests/UtilTest.php @@ -7,13 +7,19 @@ use Elastica\Test\Base as BaseTest; use Elastica\Util; +/** + * @internal + */ class UtilTest extends BaseTest { /** * @group unit * @dataProvider getIsDateMathEscapedPairs + * + * @param mixed $requestUri + * @param mixed $expectedIsEscaped */ - public function testIsDateMathEscaped($requestUri, $expectedIsEscaped) + public function testIsDateMathEscaped($requestUri, $expectedIsEscaped): void { $this->assertEquals($expectedIsEscaped, Util::isDateMathEscaped($requestUri)); } @@ -34,8 +40,11 @@ public function getIsDateMathEscapedPairs() /** * @group unit * @dataProvider getEscapeDateMathPairs + * + * @param mixed $requestUri + * @param mixed $expectedEscapedRequestUri */ - public function testEscapeDateMath($requestUri, $expectedEscapedRequestUri) + public function testEscapeDateMath($requestUri, $expectedEscapedRequestUri): void { $this->assertEquals($expectedEscapedRequestUri, Util::escapeDateMath($requestUri)); } @@ -65,8 +74,11 @@ public function getEscapeDateMathPairs() /** * @group unit * @dataProvider getEscapeTermPairs + * + * @param mixed $unescaped + * @param mixed $escaped */ - public function testEscapeTerm($unescaped, $escaped) + public function testEscapeTerm($unescaped, $escaped): void { $this->assertEquals($escaped, Util::escapeTerm($unescaped)); } @@ -86,8 +98,11 @@ public function getEscapeTermPairs() /** * @group unit * @dataProvider getReplaceBooleanWordsPairs + * + * @param mixed $before + * @param mixed $after */ - public function testReplaceBooleanWords($before, $after) + public function testReplaceBooleanWords($before, $after): void { $this->assertEquals($after, Util::replaceBooleanWords($before)); } @@ -107,7 +122,7 @@ public function getReplaceBooleanWordsPairs() /** * @group unit */ - public function testEscapeTermSpecialCharacters() + public function testEscapeTermSpecialCharacters(): void { $before = '\\+-&&||!(){}[]^"~*?:/<>'; $after = '\\\\\\+\\-\\&&\\||\\!\\(\\)\\{\\}\\[\\]\\^\\"\\~\\*\\?\\:\\/'; @@ -118,7 +133,7 @@ public function testEscapeTermSpecialCharacters() /** * @group unit */ - public function testToCamelCase() + public function testToCamelCase(): void { $string = 'hello_world'; $this->assertEquals('HelloWorld', Util::toCamelCase($string)); @@ -130,7 +145,7 @@ public function testToCamelCase() /** * @group unit */ - public function testToSnakeCase() + public function testToSnakeCase(): void { $string = 'HelloWorld'; $this->assertEquals('hello_world', Util::toSnakeCase($string)); @@ -142,7 +157,7 @@ public function testToSnakeCase() /** * @group unit */ - public function testConvertRequestToCurlCommand() + public function testConvertRequestToCurlCommand(): void { $path = 'test'; $method = Request::POST; @@ -164,7 +179,7 @@ public function testConvertRequestToCurlCommand() /** * @group unit */ - public function testConvertDateTimeObjectWithTimezone() + public function testConvertDateTimeObjectWithTimezone(): void { $dateTimeObject = new \DateTime(); $timestamp = $dateTimeObject->getTimestamp(); @@ -179,7 +194,7 @@ public function testConvertDateTimeObjectWithTimezone() /** * @group unit */ - public function testConvertDateTimeObjectWithoutTimezone() + public function testConvertDateTimeObjectWithoutTimezone(): void { $dateTimeObject = new \DateTime(); $timestamp = $dateTimeObject->getTimestamp();