From f3ab1729dc5f5eb28cacb7ef64e5a0af111f283d Mon Sep 17 00:00:00 2001 From: Moritz Friedrich Date: Wed, 15 May 2024 08:27:21 +0200 Subject: [PATCH] Removed more deprecated code, refactored deprecation warnings to accurately point to the source, fixed tests --- README.md | 2 +- src/Commands/CreateIndexCommand.php | 5 +- src/Commands/UpdateIndexCommand.php | 5 +- src/Concerns/BuildsFluentQueries.php | 86 --------------- src/Concerns/ExecutesQueries.php | 14 --- src/Concerns/ManagesIndices.php | 4 +- src/Connection.php | 88 +++++++++------- src/ConnectionManager.php | 4 +- src/ElasticsearchServiceProvider.php | 29 +++-- src/Factories/ClientFactory.php | 16 +-- src/Model.php | 96 +++-------------- src/Query.php | 30 +----- src/helpers.php | 3 - tests/DistanceTest.php | 68 +++++++----- tests/IgnoreTest.php | 7 +- tests/IndexTest.php | 56 +++++++--- tests/LoggingTest.php | 32 ------ tests/ModelTest.php | 11 -- tests/OrderTest.php | 2 +- tests/SearchTest.php | 13 +-- tests/SelectTest.php | 7 +- tests/SizeTest.php | 79 ++++++++++++++ tests/SkipTest.php | 49 ++++++--- tests/TakeTest.php | 48 --------- tests/TypeTest.php | 48 --------- tests/WhereBetweenTest.php | 23 ++-- tests/WhereInTest.php | 10 +- tests/WhereNotBetweenTest.php | 62 ++++++++--- tests/WhereNotInTest.php | 48 +++++++-- tests/WhereNotTest.php | 151 +++++++++++++++------------ tests/WhereTest.php | 28 ++--- 31 files changed, 493 insertions(+), 631 deletions(-) delete mode 100644 tests/LoggingTest.php create mode 100755 tests/SizeTest.php delete mode 100755 tests/TakeTest.php delete mode 100755 tests/TypeTest.php diff --git a/README.md b/README.md index 1d096e1..e65d4cf 100644 --- a/README.md +++ b/README.md @@ -2320,7 +2320,7 @@ $documents->url($page) ### Getting the query array without execution ```php -ES::type("my_type")->search("hello")->where("views", ">", 150)->query(); +ES::type("my_type")->search("hello")->where("views", ">", 150)->toArray(); ``` ### Getting the original elasticsearch response diff --git a/src/Commands/CreateIndexCommand.php b/src/Commands/CreateIndexCommand.php index 9b5c14c..56e8a3a 100755 --- a/src/Commands/CreateIndexCommand.php +++ b/src/Commands/CreateIndexCommand.php @@ -88,15 +88,14 @@ public function handle(ConnectionResolverInterface $resolver): void } if (isset($config['mappings'])) { - foreach ($config['mappings'] as $type => $mapping) { + foreach ($config['mappings'] as $mapping) { $this->info( - "Creating mapping for type: {$type} in index: {$index}" + "Creating mapping for index: {$index}" ); // Create mapping for type from config file $client->indices()->putMapping([ 'index' => $index, - 'type' => $type, 'body' => $mapping, 'include_type_name' => true, ]); diff --git a/src/Commands/UpdateIndexCommand.php b/src/Commands/UpdateIndexCommand.php index 2464806..7f366ee 100755 --- a/src/Commands/UpdateIndexCommand.php +++ b/src/Commands/UpdateIndexCommand.php @@ -101,14 +101,13 @@ public function handle(ConnectionResolverInterface $resolver): void // Create mapping for type from config file if (isset($config['mappings'])) { - foreach ($config['mappings'] as $type => $mapping) { + foreach ($config['mappings'] as $mapping) { $this->info( - "Creating mapping for type: {$type} in index: {$index}" + "Creating mapping for index: {$index}" ); $client->indices()->putMapping([ 'index' => $index, - 'type' => $type, 'body' => $mapping, ]); } diff --git a/src/Concerns/BuildsFluentQueries.php b/src/Concerns/BuildsFluentQueries.php index 714973d..51bc21a 100644 --- a/src/Concerns/BuildsFluentQueries.php +++ b/src/Concerns/BuildsFluentQueries.php @@ -6,7 +6,6 @@ use Closure; use InvalidArgumentException; -use JetBrains\PhpStorm\Deprecated; use Matchory\Elasticsearch\Classes\Search; use Matchory\Elasticsearch\Model; use Matchory\Elasticsearch\Query; @@ -276,28 +275,6 @@ trait BuildsFluentQueries */ protected array|null $source = null; - /** - * Mapping type - * - * Each document indexed is associated with a `_type` and an `_id`. - * The `_type` field is indexed in order to make searching by type name fast - * The value of the `_type` field is accessible in queries, aggregations, - * scripts, and when sorting. - * Note that mapping types are deprecated as of 6.0.0: - * Indices created in Elasticsearch 7.0.0 or later no longer accept a - * `_default_` mapping. Indices created in 6.x will continue to function as - * before in Elasticsearch 6.x. Types are deprecated in APIs in 7.0, with - * breaking changes to the index creation, put mapping, get mapping, put - * template, get template and get field mappings APIs. - * - * @var string|null - * @deprecated Mapping types are deprecated as of Elasticsearch 7.0.0 - * @see https://www.elastic.co/guide/en/elasticsearch/reference/7.10/removal-of-types.html - * @see https://www.elastic.co/guide/en/elasticsearch/reference/7.10/mapping-type-field.html - */ - #[Deprecated(reason: 'Mapping types are deprecated as of Elasticsearch 7.0.0')] - protected string|null $type = null; - /** * Retrieves the ID the query is restricted to. * @@ -355,36 +332,6 @@ public function getSearchType(): string|null return $this->searchType; } - /** - * Retrieves the document mapping type the query is restricted to. - * - * @return string|null - * @deprecated Mapping types are deprecated as of Elasticsearch 7.0.0 - * @see https://www.elastic.co/guide/en/elasticsearch/reference/7.10/removal-of-types.html - */ - #[Deprecated(reason: 'Mapping types are deprecated as of Elasticsearch 7.0.0')] - public function getType(): string|null - { - /** - * @noinspection PhpDeprecationInspection - * @psalm-suppress DeprecatedProperty - */ - return $this->type; - } - - /** - * @param string|null $id ID to filter by - * - * @return $this - * @deprecated Use id() instead - * @see Query::id() - */ - #[Deprecated(replacement: '%class%->id(%parameter0%)')] - public function _id(string|null $id = null): static - { - return $this->id($id); - } - /** * Adds a term filter for the `_id` field. * @@ -1156,27 +1103,6 @@ public function take(int $size = Query::DEFAULT_LIMIT): static return $this; } - /** - * Sets the document mapping type to restrict the query to. - * - * @param string $type Name of the document mapping type - * - * @return $this - * @deprecated Mapping types are deprecated as of Elasticsearch 7.0.0 - * @see https://www.elastic.co/guide/en/elasticsearch/reference/7.10/removal-of-types.html - */ - #[Deprecated(reason: 'Mapping types are deprecated as of Elasticsearch 7.0.0')] - public function type(string $type): static - { - /** - * @noinspection PhpDeprecationInspection - * @psalm-suppress DeprecatedProperty - */ - $this->type = $type; - - return $this; - } - /** * Set the ignored fields to not be returned * @@ -1507,18 +1433,6 @@ protected function getSkip(): int return $this->from; } - /** - * Get the query limit - * - * @return int - * @deprecated Use getSize() instead - */ - #[Deprecated(replacement: '%class%->getSize()')] - protected function getTake(): int - { - return $this->getSize(); - } - /** * Retrieves the number of hits to limit the query to. * diff --git a/src/Concerns/ExecutesQueries.php b/src/Concerns/ExecutesQueries.php index 2fb1f45..4741151 100644 --- a/src/Concerns/ExecutesQueries.php +++ b/src/Concerns/ExecutesQueries.php @@ -6,7 +6,6 @@ use DateTime; use Illuminate\Support\Facades\Request; -use JetBrains\PhpStorm\Deprecated; use JsonException; use Matchory\Elasticsearch\Classes\Bulk; use Matchory\Elasticsearch\Collection; @@ -629,19 +628,6 @@ public function paginate( ); } - /** - * Keeping around for backwards compatibility - * - * @return array - * @deprecated Use toArray() instead - * @see Query::toArray() - */ - #[Deprecated(replacement: '%class%->toArray()')] - public function query(): array - { - return $this->toArray(); - } - /** * Indicate that the query results should be cached forever. * diff --git a/src/Concerns/ManagesIndices.php b/src/Concerns/ManagesIndices.php index 4ccd697..45b4be1 100644 --- a/src/Concerns/ManagesIndices.php +++ b/src/Concerns/ManagesIndices.php @@ -17,7 +17,7 @@ trait ManagesIndices * * @return array */ - public function createIndex(string $name, ?callable $callback = null): array + public function createIndex(string $name, callable|null $callback = null): array { $index = new Index($name, $callback); @@ -35,7 +35,7 @@ public function createIndex(string $name, ?callable $callback = null): array * @throws RuntimeException * @see Query::createIndex() */ - public function create(?callable $callback = null): array + public function create(callable|null $callback = null): array { $index = $this->getIndex(); diff --git a/src/Connection.php b/src/Connection.php index cdb5a5f..6df5bd8 100755 --- a/src/Connection.php +++ b/src/Connection.php @@ -30,8 +30,10 @@ use function assert; use function json_encode; -use function trigger_deprecation; +use function sprintf; +use function trigger_error; +use const E_USER_DEPRECATED; use const JSON_THROW_ON_ERROR; /** @@ -126,6 +128,16 @@ final public function __construct( #[Deprecated] public static function setConnectionResolver(Resolver $resolver): void { + @trigger_error( + sprintf( + 'Since matchory/elasticsearch 3.0.0: The %s method is deprecated. ' . + 'Use the connection manager to create connections instead. It provides a simpler ' . + 'way to manage connections. This method will be removed in the next major version.', + __METHOD__ + ), + E_USER_DEPRECATED + ); + static::$resolver = $resolver; } @@ -145,12 +157,14 @@ public static function configureLogging( ClientBuilder $clientBuilder, array $config ): ClientBuilder { - trigger_deprecation( - 'matchory/elasticsearch', - '3.0.0', - 'The %s method is deprecated. Use the connection manager to create connections instead. It provides a ' . - 'simpler way to manage connections. This method will be removed in the next major version.', - __METHOD__ + @trigger_error( + sprintf( + 'Since matchory/elasticsearch 3.0.0: The %s method is deprecated. ' . + 'Use the connection manager to create connections instead. It provides a simpler ' . + 'way to manage connections. This method will be removed in the next major version.', + __METHOD__ + ), + E_USER_DEPRECATED ); if (Arr::get($config, 'logging.enabled')) { @@ -184,12 +198,14 @@ public static function configureLogging( #[Deprecated(reason: 'Use the connection manager to create connections instead.')] public static function create(mixed $config): Query { - trigger_deprecation( - 'matchory/elasticsearch', - '3.0.0', - 'The %s method is deprecated. Use the connection manager to create connections instead. It provides a ' . - 'simpler way to manage connections. This method will be removed in the next major version.', - __METHOD__ + @trigger_error( + sprintf( + 'Since matchory/elasticsearch 3.0.0: The %s method is deprecated. ' . + 'Use the connection manager to create connections instead. It provides a simpler ' . + 'way to manage connections. This method will be removed in the next major version.', + __METHOD__ + ), + E_USER_DEPRECATED ); $app = App::getFacadeApplication(); @@ -218,10 +234,6 @@ public function insert( $parameters[Query::PARAM_INDEX] = $index; } - if ($type) { - $parameters[Query::PARAM_TYPE] = $type; - } - if ($this->reportQueries) { $this->reportQuery($parameters); } @@ -278,12 +290,14 @@ public function newQuery(string|null $connection = null): Query // TODO: This is deprecated behaviour and should be removed in the next // major version. if ($connection) { - trigger_deprecation( - 'matchory/elasticsearch', - '3.0.0', - 'Passing the connection name to %s is deprecated. Use the proper connection instance directly ' . - 'instead. This parameter will be removed in the next major version.', - __METHOD__ + @trigger_error( + sprintf( + 'Passing the connection name to %s is deprecated. ' . + 'Use the proper connection instance directly instead. ' . + 'This parameter will be removed in the next major version.', + __METHOD__ + ), + E_USER_DEPRECATED ); /** @noinspection PhpDeprecationInspection */ @@ -307,12 +321,14 @@ public function newQuery(string|null $connection = null): Query #[Deprecated(reason: 'Use the connection manager to create connections instead.')] public function connection(string $name): Query { - trigger_deprecation( - 'matchory/elasticsearch', - '3.0.0', - 'The %s method is deprecated. Use the connection manager to create connections instead. It provides a ' . - 'simpler way to manage connections. This method will be removed in the next major version.', - __METHOD__ + @trigger_error( + sprintf( + 'Since matchory/elasticsearch 3.0.0: The %s method is deprecated. ' . + 'Use the connection manager to create connections instead. It provides a simpler ' . + 'way to manage connections. This method will be removed in the next major version.', + __METHOD__ + ), + E_USER_DEPRECATED ); return $this->newQuery($name); @@ -367,12 +383,14 @@ public function __call(string $name, array $arguments) #[Deprecated(reason: 'Use the connection manager to create connections instead.')] public function isLoaded(string $name): bool { - trigger_deprecation( - 'matchory/elasticsearch', - '3.0.0', - 'The %s method is deprecated. Use the connection manager to create connections instead. It provides a ' . - 'simpler way to manage connections. This method will be removed in the next major version.', - __METHOD__ + @trigger_error( + sprintf( + 'Since matchory/elasticsearch 3.0.0: The %s method is deprecated. ' . + 'Use the connection manager to create connections instead. It provides a simpler ' . + 'way to manage connections. This method will be removed in the next major version.', + __METHOD__ + ), + E_USER_DEPRECATED ); return (bool)static::$resolver->connection($name); diff --git a/src/ConnectionManager.php b/src/ConnectionManager.php index a2840bf..e98cc45 100644 --- a/src/ConnectionManager.php +++ b/src/ConnectionManager.php @@ -51,7 +51,7 @@ class ConnectionManager implements ConnectionResolverInterface public function __construct( protected array $configuration, protected readonly ClientFactoryInterface $clientFactory, - protected readonly ?CacheInterface $cache = null, + protected readonly CacheInterface|null $cache = null, ) { } @@ -77,7 +77,7 @@ public function __call(string $method, array $parameters) * @return ConnectionInterface * @throws InvalidArgumentException */ - public function connection(?string $name = null): ConnectionInterface + public function connection(string|null $name = null): ConnectionInterface { if (is_null($name)) { $name = $this->getDefaultConnection(); diff --git a/src/ElasticsearchServiceProvider.php b/src/ElasticsearchServiceProvider.php index d79cf52..5771ea6 100755 --- a/src/ElasticsearchServiceProvider.php +++ b/src/ElasticsearchServiceProvider.php @@ -31,9 +31,11 @@ use function dirname; use function file_exists; use function method_exists; -use function trigger_deprecation; +use function trigger_error; use function version_compare; +use const E_USER_DEPRECATED; + /** * Class ElasticsearchServiceProvider * @@ -85,10 +87,10 @@ protected function configure(): void { if (file_exists($this->packageConfigPath('es.php'))) { $configPath = $this->packageConfigPath('es.php'); - trigger_deprecation( - 'matchory/elasticsearch', - '3.0.0', - 'The "es.php" configuration file is deprecated. Use "elasticsearch.php" instead.' + @trigger_error( + "Since matchory/elasticsearch 3.0.0: The 'es.php' configuration file is deprecated. " . + "Use 'elasticsearch.php' instead.", + E_USER_DEPRECATED ); } else { $configPath = $this->packageConfigPath('elasticsearch.php'); @@ -250,14 +252,12 @@ function (Application $app) { 'es' ); - $this->app->extend('es', function (ConnectionResolverInterface $resolver) { - trigger_deprecation( - 'matchory/elasticsearch', - '3.0.0', - 'The "es" alias is deprecated. Use "elasticsearch" instead.' + $this->app->beforeResolving('es', function () { + @trigger_error( + "Since matchory/elasticsearch 3.0.0: The 'es' alias is deprecated. " . + "Use 'elasticsearch' instead.", + E_USER_DEPRECATED ); - - return $resolver; }); } @@ -274,10 +274,7 @@ protected function registerDefaultConnection(): void ->connection() ); - $this->app->alias( - ConnectionInterface::class, - 'elasticsearch.connection' - ); + $this->app->alias(ConnectionInterface::class, 'elasticsearch.connection'); } /** diff --git a/src/Factories/ClientFactory.php b/src/Factories/ClientFactory.php index 325a962..ad37c0d 100644 --- a/src/Factories/ClientFactory.php +++ b/src/Factories/ClientFactory.php @@ -10,11 +10,13 @@ use Matchory\Elasticsearch\Interfaces\ClientFactoryInterface; use Psr\Log\LoggerInterface; -use function trigger_deprecation; +use function trigger_error; -class ClientFactory implements ClientFactoryInterface +use const E_USER_DEPRECATED; + +readonly class ClientFactory implements ClientFactoryInterface { - public function __construct(private readonly LoggerInterface|null $logger = null) + public function __construct(private LoggerInterface|null $logger = null) { } @@ -25,10 +27,10 @@ public function __construct(private readonly LoggerInterface|null $logger = null public function createClient(array $config): Client { if (isset($config['servers'])) { - trigger_deprecation( - 'matchory/elasticsearch', - '3.0.0', - 'The "servers" configuration key is deprecated. Use "hosts" instead.' + @trigger_error( + "Since matchory/elasticsearch 3.0.0: The 'servers' configuration key is deprecated. " . + "Use 'hosts' instead.", + E_USER_DEPRECATED ); $config['hosts'] = $config['servers']; diff --git a/src/Model.php b/src/Model.php index 7bbed80..95d4570 100755 --- a/src/Model.php +++ b/src/Model.php @@ -47,12 +47,13 @@ use function is_null; use function json_encode; use function method_exists; -use function settype; use function sprintf; use function tap; +use function trigger_error; use function ucfirst; use const DATE_ATOM; +use const E_USER_DEPRECATED; /** * Elasticsearch data model @@ -494,17 +495,14 @@ public static function create(array $attributes, string|null $id = null): self * @param array $metadata Query result metadata * @param bool $exists Whether the document exists * @param string|null $index Name of the index the document lives in - * @param string|null $type (Deprecated) Mapping type of the document * * @return static - * @noinspection PhpDeprecationInspection */ public function newInstance( array $attributes = [], array $metadata = [], bool $exists = false, string|null $index = null, - string|null $type = null ): self { $model = new static([], $exists); @@ -512,7 +510,6 @@ public function newInstance( $model->setConnectionName($this->getConnectionName()); $model->setResultMetadata($metadata); $model->setIndex($index ?? $this->getIndex()); - $model->setType($type ?? $this->getType()); $model->mergeCasts($this->casts); $model->fireModelEvent('retrieved', false); @@ -918,6 +915,16 @@ public function setDateFormat(string $format): self #[Deprecated(replacement: '%class%->getConnectionName()')] public function getConnection(): string|null { + @trigger_error( + sprintf( + 'Since matchory/elasticsearch 3.0.0: The %s method is deprecated. ' . + 'Use the connection manager to create connections instead. It provides a simpler ' . + 'way to manage connections. This method will be removed in the next major version.', + __METHOD__ + ), + E_USER_DEPRECATED + ); + return $this->getConnectionName(); } @@ -1021,7 +1028,6 @@ public function getHighlights(string|null $field = null): mixed * * @return mixed * @throws InvalidCastException - * @noinspection PhpDeprecationInspection */ public function getAttribute(string $key): mixed { @@ -1039,10 +1045,6 @@ public function getAttribute(string $key): mixed return $this->getIndex(); } - if ($key === '_type') { - return $this->getType(); - } - if ($key === '_score') { return $this->getScore(); } @@ -1083,34 +1085,6 @@ public function setIndex(string|null $index): void $this->index = $index; } - /** - * Retrieves the document mapping type. - * - * @return string|null - * @deprecated Mapping types are deprecated as of Elasticsearch 7.0.0 - * @see https://www.elastic.co/guide/en/elasticsearch/reference/7.10/removal-of-types.html - */ - #[Deprecated('Mapping types are deprecated as of Elasticsearch 7.0.0')] - public function getType(): string|null - { - return $this->type; - } - - /** - * Sets the document mapping type. - * - * @param string|null $type - * - * @return void - * @deprecated Mapping types are deprecated as of Elasticsearch 7.0.0 - * @see https://www.elastic.co/guide/en/elasticsearch/reference/7.10/removal-of-types.html - */ - #[Deprecated(reason: 'Mapping types are deprecated as of Elasticsearch 7.0.0')] - public function setType(string|null $type): void - { - $this->type = $type; - } - /** * Retrieves the result score. * @@ -1249,7 +1223,6 @@ public function resolveRouteBinding($value, $field = null): self|null * Get a new query builder scoped to the current model. * * @return Query - * @noinspection PhpDeprecationInspection */ public function newQuery(): Query { @@ -1260,10 +1233,6 @@ public function newQuery(): Query $query->index($index); } - if ($type = $this->getType()) { - $query->type($type); - } - if ($fields = $this->getSelectable()) { $query->select($fields); } @@ -1517,13 +1486,11 @@ public function isNot(self|null $model): bool * * @return bool * @throws InvalidCastException - * @noinspection PhpDeprecationInspection */ public function is(self|null $model): bool { return !is_null($model) && $this->getId() === $model->getId() && - $this->getType() === $model->getType() && $this->getIndex() === $model->getIndex() && $this->getConnectionName() === $model->getConnectionName(); } @@ -1668,43 +1635,4 @@ final public function usesTimestamps(): bool { return false; } - - /** - * Set attributes casting - * - * @param string $name - * @param mixed $value - * - * @return mixed - * @deprecated This method will be removed in the next major version. - */ - #[Deprecated('This method will be removed in the next major version.')] - protected function setAttributeType(string $name, mixed $value): mixed - { - $castTypes = [ - 'boolean', - 'bool', - 'integer', - 'int', - 'float', - 'double', - 'string', - 'array', - 'object', - 'null', - ]; - - if ( - array_key_exists($name, $this->casts) && - in_array( - $this->casts[$name], - $castTypes, - true - ) - ) { - settype($value, $this->casts[$name]); - } - - return $value; - } } diff --git a/src/Query.php b/src/Query.php index 077b2c4..67a5ecf 100755 --- a/src/Query.php +++ b/src/Query.php @@ -11,7 +11,6 @@ use Illuminate\Contracts\Support\Jsonable; use Illuminate\Support\Traits\ForwardsCalls; use IteratorAggregate; -use JetBrains\PhpStorm\Deprecated; use JsonException; use JsonSerializable; use Matchory\Elasticsearch\Concerns\AppliesScopes; @@ -125,8 +124,6 @@ class Query implements Arrayable, JsonSerializable, Jsonable, IteratorAggregate public const PARAM_SIZE = 'size'; - public const PARAM_TYPE = 'type'; - public const REGEXP_FLAG_ALL = 1; public const REGEXP_FLAG_ANYSTRING = 16; @@ -152,23 +149,12 @@ class Query implements Arrayable, JsonSerializable, Jsonable, IteratorAggregate self::SOURCE_EXCLUDES => [], ]; - /** - * @deprecated Use getConnection()->getClient() to access the client instead - * @see ConnectionInterface::getClient() - * @see Query::getConnection() - */ - #[Deprecated(replacement: '%class%->getConnection()->getClient()')] - public null $client = null; - /** * Elastic model instance. * * @psalm-var T - * @deprecated Use getModel() instead - * @see Query::getModel() */ - #[Deprecated(replacement: '%class%->getModel()')] - public Model $model; + private Model $model; /** * Elasticsearch connection instance @@ -199,8 +185,6 @@ public function __construct( * We set a plain model here so there's always a model instance set. * This avoids errors in methods that rely on a model. * - * @noinspection PhpDeprecationInspection - * @psalm-suppress DeprecatedProperty * @psalm-suppress PossiblyInvalidPropertyAssignmentValue */ $this->model = $model ?? new Model(); @@ -258,8 +242,7 @@ public function __call(string $method, array $parameters): self * if the query builder is used without models. * * @return T Model instance used for the current query. - * @noinspection PhpDocSignatureInspection, PhpDeprecationInspection - * @psalm-suppress DeprecatedProperty + * @noinspection PhpDocSignatureInspection */ public function getModel(): Model { @@ -276,7 +259,6 @@ public function getModel(): Model * @psalm-param TModel $model * * @return static Query builder instance for chaining. - * @noinspection PhpDeprecationInspection */ public function setModel(Model $model): static { @@ -380,14 +362,6 @@ protected function buildQuery(): array $params[self::PARAM_INDEX] = $index; } - /** - * @noinspection PhpDeprecationInspection - * @psalm-suppress DeprecatedMethod - */ - if ($type = $query->getType()) { - $params[self::PARAM_TYPE] = $type; - } - return $params; } } diff --git a/src/helpers.php b/src/helpers.php index 586e6e2..c82118f 100755 --- a/src/helpers.php +++ b/src/helpers.php @@ -29,6 +29,3 @@ function base_path(string $path = ''): string return app()->basePath() . ($path ? '/' . $path : $path); } } - - - diff --git a/tests/DistanceTest.php b/tests/DistanceTest.php index f27755f..fb2b7de 100755 --- a/tests/DistanceTest.php +++ b/tests/DistanceTest.php @@ -1,48 +1,64 @@ getExpected("location", ['lat' => -33.8688197, 'lon' => 151.20929550000005], "10km"), - $this->getActual("location", ['lat' => -33.8688197, 'lon' => 151.20929550000005], "10km") + $this->getExpected('location', ['lat' => -33.8688197, 'lon' => 151.20929550000005], '10km'), + $this->getActual('location', ['lat' => -33.8688197, 'lon' => 151.20929550000005], '10km') ); self::assertNotEquals( - $this->getExpected("location", ['lat' => -33.8688197, 'lon' => 151.20929550000005], "10km"), - $this->getActual("location", ['lat' => -33.8688197, 'lon' => 151.20929550000005], "15km") + $this->getExpected('location', ['lat' => -33.8688197, 'lon' => 151.20929550000005], '10km'), + $this->getActual('location', ['lat' => -33.8688197, 'lon' => 151.20929550000005], '15km') ); } - /** - * Get The expected results. - * @param $field - * @param $geo_point - * @param $distance - * @return array - */ - protected function getExpected($field, $geo_point, $distance) + protected function getExpected(string $field, array $value, string $distance): array { $query = $this->getQueryArray(); $query['body']['query']['bool']['filter'][] = [ 'geo_distance' => [ - $field => $geo_point, + $field => $value, 'distance' => $distance ] ]; @@ -50,16 +66,20 @@ protected function getExpected($field, $geo_point, $distance) return $query; } - /** - * Get The actual results. - * @param $field - * @param $geo_point - * @param $distance - * @return mixed + * @throws \PHPUnit\Framework\InvalidArgumentException + * @throws ClassAlreadyExistsException + * @throws ClassIsFinalException + * @throws ClassIsReadonlyException + * @throws DuplicateMethodException + * @throws InvalidMethodNameException + * @throws OriginalConstructorInvocationRequiredException + * @throws ReflectionException + * @throws RuntimeException + * @throws UnknownTypeException */ - protected function getActual($field, $geo_point, $distance) + protected function getActual($field, $geo_point, $distance): array { - return $this->getQueryObject()->distance($field, $geo_point, $distance)->query(); + return $this->getQueryObject()->distance($field, $geo_point, $distance)->toArray(); } } diff --git a/tests/IgnoreTest.php b/tests/IgnoreTest.php index 0cfd016..ad67d03 100755 --- a/tests/IgnoreTest.php +++ b/tests/IgnoreTest.php @@ -8,6 +8,7 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\MockObject\ClassAlreadyExistsException; use PHPUnit\Framework\MockObject\ClassIsFinalException; +use PHPUnit\Framework\MockObject\ClassIsReadonlyException; use PHPUnit\Framework\MockObject\DuplicateMethodException; use PHPUnit\Framework\MockObject\InvalidMethodNameException; use PHPUnit\Framework\MockObject\OriginalConstructorInvocationRequiredException; @@ -22,9 +23,9 @@ class IgnoreTest extends TestCase use ESQueryTrait; /** - * @return void * @throws ClassAlreadyExistsException * @throws ClassIsFinalException + * @throws ClassIsReadonlyException * @throws DuplicateMethodException * @throws ExpectationFailedException * @throws InvalidArgumentException @@ -49,9 +50,6 @@ public function ignore(): void } /** - * @param int ...$args - * - * @return array * @throws ClassAlreadyExistsException * @throws ClassIsFinalException * @throws DuplicateMethodException @@ -61,6 +59,7 @@ public function ignore(): void * @throws RuntimeException * @throws UnknownTypeException * @throws \PHPUnit\Framework\InvalidArgumentException + * @throws ClassIsReadonlyException */ protected function getActual(int ...$args): array { diff --git a/tests/IndexTest.php b/tests/IndexTest.php index a7c8d31..da2e934 100755 --- a/tests/IndexTest.php +++ b/tests/IndexTest.php @@ -1,9 +1,22 @@ getExpected("index_1"), $this->getActual("index_1")); + self::assertEquals($this->getExpected('index_1'), $this->getActual('index_1')); } - /** - * Get The expected results. - * @param $index - * @return array - */ - protected function getExpected($index) + protected function getExpected(string $index): array { $query = $this->getQueryArray(); - $query["index"] = $index; + $query['index'] = $index; return $query; } - /** - * Get The actual results. - * @param $index - * @return mixed + * @throws InvalidArgumentException + * @throws ClassAlreadyExistsException + * @throws ClassIsFinalException + * @throws ClassIsReadonlyException + * @throws DuplicateMethodException + * @throws InvalidMethodNameException + * @throws OriginalConstructorInvocationRequiredException + * @throws ReflectionException + * @throws RuntimeException + * @throws UnknownTypeException */ - protected function getActual($index) + protected function getActual(string $index): array { - return $this->getQueryObject()->index($index)->query(); + return $this->getQueryObject()->index($index)->toArray(); } } diff --git a/tests/LoggingTest.php b/tests/LoggingTest.php deleted file mode 100644 index b64c479..0000000 --- a/tests/LoggingTest.php +++ /dev/null @@ -1,32 +0,0 @@ - [ - 'enabled' => true, - 'level' => Level::Debug, - 'location' => '../src/storage/logs/elasticsearch.log', - ], - ]); - - self::assertInstanceOf( - ClientBuilder::class, - $newClientBuilder - ); - } -} diff --git a/tests/ModelTest.php b/tests/ModelTest.php index 96f5bf1..2644f1e 100644 --- a/tests/ModelTest.php +++ b/tests/ModelTest.php @@ -248,17 +248,6 @@ public function testGetSelectable(): void { } - public function testGetType(): void - { - $model = new Model(); - - self::assertNull($model->getType()); - - $model->setType('foo'); - - self::assertSame('foo', $model->getType()); - } - public function testGetUnSelectable(): void { } diff --git a/tests/OrderTest.php b/tests/OrderTest.php index 293f653..a8f4fa9 100755 --- a/tests/OrderTest.php +++ b/tests/OrderTest.php @@ -61,6 +61,6 @@ protected function getActual( return $this ->getQueryObject() ->orderBy($field, $direction) - ->query(); + ->toArray(); } } diff --git a/tests/SearchTest.php b/tests/SearchTest.php index 68e26d1..0fdd930 100755 --- a/tests/SearchTest.php +++ b/tests/SearchTest.php @@ -43,18 +43,14 @@ class SearchTest extends TestCase public function testSearchMethod(): void { self::assertEquals( - $this->getExpected('foo', 1), - $this->getActual('foo', 1) + $this->getExpected('foo'), + $this->getActual('foo') ); } /** * Get The actual results. * - * @param string $q - * @param int $boost - * - * @return mixed * @throws \PHPUnit\Framework\InvalidArgumentException * @throws ClassAlreadyExistsException * @throws ClassIsFinalException @@ -75,11 +71,6 @@ protected function getActual(string $q, int $boost = 1): array /** * Get The expected results. - * - * @param array|string $body - * @param int|float $boost - * - * @return array */ protected function getExpected(array|string $body, int|float $boost = 1): array { diff --git a/tests/SelectTest.php b/tests/SelectTest.php index cf748f6..9de87d0 100755 --- a/tests/SelectTest.php +++ b/tests/SelectTest.php @@ -8,6 +8,7 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\MockObject\ClassAlreadyExistsException; use PHPUnit\Framework\MockObject\ClassIsFinalException; +use PHPUnit\Framework\MockObject\ClassIsReadonlyException; use PHPUnit\Framework\MockObject\DuplicateMethodException; use PHPUnit\Framework\MockObject\InvalidMethodNameException; use PHPUnit\Framework\MockObject\OriginalConstructorInvocationRequiredException; @@ -22,9 +23,9 @@ class SelectTest extends TestCase use ESQueryTrait; /** - * @return void * @throws ClassAlreadyExistsException * @throws ClassIsFinalException + * @throws ClassIsReadonlyException * @throws DuplicateMethodException * @throws ExpectationFailedException * @throws InvalidArgumentException @@ -45,9 +46,6 @@ public function select(): void } /** - * @param string ...$fields - * - * @return array * @throws ClassAlreadyExistsException * @throws ClassIsFinalException * @throws DuplicateMethodException @@ -57,6 +55,7 @@ public function select(): void * @throws RuntimeException * @throws UnknownTypeException * @throws \PHPUnit\Framework\InvalidArgumentException + * @throws ClassIsReadonlyException */ protected function getActual(string ...$fields): array { diff --git a/tests/SizeTest.php b/tests/SizeTest.php new file mode 100755 index 0000000..0191103 --- /dev/null +++ b/tests/SizeTest.php @@ -0,0 +1,79 @@ +getExpected(15), $this->getActual(15)); + } + + + /** + * Get The expected results. + */ + protected function getExpected(int $size): array + { + $query = $this->getQueryArray(); + $query['size'] = $size; + + return $query; + } + + + /** + * Get The actual results. + * + * @throws \PHPUnit\Framework\InvalidArgumentException + * @throws ClassAlreadyExistsException + * @throws ClassIsFinalException + * @throws ClassIsReadonlyException + * @throws DuplicateMethodException + * @throws InvalidMethodNameException + * @throws OriginalConstructorInvocationRequiredException + * @throws ReflectionException + * @throws RuntimeException + * @throws UnknownTypeException + */ + protected function getActual(int $size): array + { + return $this->getQueryObject()->take($size)->toArray(); + } +} diff --git a/tests/SkipTest.php b/tests/SkipTest.php index cf4a08b..03fc15f 100755 --- a/tests/SkipTest.php +++ b/tests/SkipTest.php @@ -1,9 +1,20 @@ getQueryArray(); - - $query["from"] = $from; + $query['from'] = $from; return $query; } /** - * @param string $from - * - * @return array + * @throws \PHPUnit\Framework\InvalidArgumentException + * @throws ClassAlreadyExistsException + * @throws ClassIsFinalException + * @throws ClassIsReadonlyException + * @throws DuplicateMethodException + * @throws InvalidMethodNameException + * @throws OriginalConstructorInvocationRequiredException + * @throws ReflectionException + * @throws RuntimeException + * @throws UnknownTypeException */ - protected function getActual(string $from): array + protected function getActual(int $from): array { - return $this->getQueryObject()->skip($from)->query(); + return $this->getQueryObject()->skip($from)->toArray(); } } diff --git a/tests/TakeTest.php b/tests/TakeTest.php deleted file mode 100755 index ea9e0cc..0000000 --- a/tests/TakeTest.php +++ /dev/null @@ -1,48 +0,0 @@ -getExpected(15), $this->getActual(15)); - } - - - /** - * Get The expected results. - * @param $take - * @return array - */ - protected function getExpected($take) - { - $query = $this->getQueryArray(); - - $query["size"] = $take; - - return $query; - } - - - /** - * Get The actual results. - * @param $take - * @return mixed - */ - protected function getActual($take) - { - return $this->getQueryObject()->take($take)->query(); - } -} diff --git a/tests/TypeTest.php b/tests/TypeTest.php deleted file mode 100755 index 343f450..0000000 --- a/tests/TypeTest.php +++ /dev/null @@ -1,48 +0,0 @@ -getExpected("type_1"), $this->getActual("type_1")); - } - - - /** - * Get The expected results. - * @param $type - * @return array - */ - protected function getExpected($type) - { - $query = $this->getQueryArray(); - - $query["type"] = $type; - - return $query; - } - - - /** - * Get The actual results. - * @param $type - * @return mixed - */ - protected function getActual($type) - { - return $this->getQueryObject()->type($type)->query(); - } -} diff --git a/tests/WhereBetweenTest.php b/tests/WhereBetweenTest.php index 2c2f007..d8848ef 100755 --- a/tests/WhereBetweenTest.php +++ b/tests/WhereBetweenTest.php @@ -9,6 +9,7 @@ use PHPUnit\Framework\InvalidArgumentException; use PHPUnit\Framework\MockObject\ClassAlreadyExistsException; use PHPUnit\Framework\MockObject\ClassIsFinalException; +use PHPUnit\Framework\MockObject\ClassIsReadonlyException; use PHPUnit\Framework\MockObject\DuplicateMethodException; use PHPUnit\Framework\MockObject\InvalidMethodNameException; use PHPUnit\Framework\MockObject\OriginalConstructorInvocationRequiredException; @@ -24,14 +25,15 @@ class WhereBetweenTest extends TestCase /** * @throws ClassAlreadyExistsException * @throws ClassIsFinalException + * @throws ClassIsReadonlyException * @throws DuplicateMethodException + * @throws ExpectationFailedException * @throws InvalidArgumentException * @throws InvalidMethodNameException * @throws OriginalConstructorInvocationRequiredException * @throws ReflectionException * @throws RuntimeException * @throws UnknownTypeException - * @throws ExpectationFailedException * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException * @test */ @@ -49,22 +51,20 @@ public function whereBetween(): void } /** - * @param $name - * @param $first - * @param null $last + * @param int|array{int, int} $first * - * @return array - * @throws InvalidArgumentException * @throws ClassAlreadyExistsException * @throws ClassIsFinalException * @throws DuplicateMethodException + * @throws InvalidArgumentException * @throws InvalidMethodNameException * @throws OriginalConstructorInvocationRequiredException * @throws ReflectionException * @throws RuntimeException * @throws UnknownTypeException + * @throws ClassIsReadonlyException */ - protected function getActual($name, $first, $last = null): array + protected function getActual(string $name, int|array $first, int|null $last = null): array { return $this ->getQueryObject() @@ -72,14 +72,7 @@ protected function getActual($name, $first, $last = null): array ->toArray(); } - /** - * @param $name - * @param $first - * @param $last - * - * @return array - */ - protected function getExpected($name, $first, $last = null): array + protected function getExpected(string $name, int|array $first, int|null $last = null): array { $query = $this->getQueryArray(); diff --git a/tests/WhereInTest.php b/tests/WhereInTest.php index 4ccc23e..abaaea4 100755 --- a/tests/WhereInTest.php +++ b/tests/WhereInTest.php @@ -8,6 +8,7 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\MockObject\ClassAlreadyExistsException; use PHPUnit\Framework\MockObject\ClassIsFinalException; +use PHPUnit\Framework\MockObject\ClassIsReadonlyException; use PHPUnit\Framework\MockObject\DuplicateMethodException; use PHPUnit\Framework\MockObject\InvalidMethodNameException; use PHPUnit\Framework\MockObject\OriginalConstructorInvocationRequiredException; @@ -22,9 +23,9 @@ class WhereInTest extends TestCase use ESQueryTrait; /** - * @return void * @throws ClassAlreadyExistsException * @throws ClassIsFinalException + * @throws ClassIsReadonlyException * @throws DuplicateMethodException * @throws ExpectationFailedException * @throws InvalidArgumentException @@ -45,11 +46,6 @@ public function whereIn(): void } /** - * @param string $name - * @param array $value - * - * @return array - * @throws \PHPUnit\Framework\InvalidArgumentException * @throws ClassAlreadyExistsException * @throws ClassIsFinalException * @throws DuplicateMethodException @@ -58,6 +54,8 @@ public function whereIn(): void * @throws ReflectionException * @throws RuntimeException * @throws UnknownTypeException + * @throws \PHPUnit\Framework\InvalidArgumentException + * @throws ClassIsReadonlyException */ protected function getActual(string $name, array $value = []): array { diff --git a/tests/WhereNotBetweenTest.php b/tests/WhereNotBetweenTest.php index c0f5b94..7423799 100755 --- a/tests/WhereNotBetweenTest.php +++ b/tests/WhereNotBetweenTest.php @@ -1,10 +1,23 @@ getExpected("views", 500, 1000), - $this->getActual("views", 500, 1000) + $this->getExpected('views', 500, 1000), + $this->getActual('views', 500, 1000) ); self::assertEquals( - $this->getExpected("views", [500, 1000]), - $this->getActual("views", [500, 1000]) + $this->getExpected('views', [500, 1000]), + $this->getActual('views', [500, 1000]) ); } @@ -33,12 +58,8 @@ public function testWhereNotBetweenMethod(): void /** * Get The expected results. - * @param $name - * @param $first_value - * @param $second_value - * @return array */ - protected function getExpected($name, $first_value, $second_value = null) + protected function getExpected($name, $first_value, $second_value = null): array { $query = $this->getQueryArray(); @@ -47,7 +68,7 @@ protected function getExpected($name, $first_value, $second_value = null) $first_value = $first_value[0]; } - $query["body"]["query"]["bool"]["must_not"][] = ["range" => [$name => ["gte" => $first_value, "lte" => $second_value]]]; + $query['body']['query']['bool']['must_not'][] = ['range' => [$name => ['gte' => $first_value, 'lte' => $second_value]]]; return $query; } @@ -55,13 +76,20 @@ protected function getExpected($name, $first_value, $second_value = null) /** * Get The actual results. - * @param $name - * @param $first_value - * @param $second_value - * @return mixed + * + * @throws \PHPUnit\Framework\InvalidArgumentException + * @throws ClassAlreadyExistsException + * @throws ClassIsFinalException + * @throws ClassIsReadonlyException + * @throws DuplicateMethodException + * @throws InvalidMethodNameException + * @throws OriginalConstructorInvocationRequiredException + * @throws ReflectionException + * @throws RuntimeException + * @throws UnknownTypeException */ - protected function getActual($name, $first_value, $second_value = null) + protected function getActual($name, $first_value, $second_value = null): array { - return $this->getQueryObject()->whereNotBetween($name, $first_value, $second_value)->query(); + return $this->getQueryObject()->whereNotBetween($name, $first_value, $second_value)->toArray(); } } diff --git a/tests/WhereNotInTest.php b/tests/WhereNotInTest.php index 1fe578e..006fbea 100755 --- a/tests/WhereNotInTest.php +++ b/tests/WhereNotInTest.php @@ -1,9 +1,20 @@ getExpected("status", ["pending", "draft"]), - $this->getActual("status", ["pending", "draft"]) + $this->getExpected('status', ['pending', 'draft']), + $this->getActual('status', ['pending', 'draft']) ); } @@ -37,24 +57,30 @@ protected function getExpected(string $name, array $value = []): array { $query = $this->getQueryArray(); - $query["body"]["query"]["bool"]["must_not"][] = [ - "terms" => [$name => $value], + $query['body']['query']['bool']['must_not'][] = [ + 'terms' => [$name => $value], ]; return $query; } /** - * @param $name - * @param array $value - * - * @return mixed + * @throws \PHPUnit\Framework\InvalidArgumentException + * @throws ClassAlreadyExistsException + * @throws ClassIsFinalException + * @throws ClassIsReadonlyException + * @throws DuplicateMethodException + * @throws InvalidMethodNameException + * @throws OriginalConstructorInvocationRequiredException + * @throws ReflectionException + * @throws RuntimeException + * @throws UnknownTypeException */ - protected function getActual($name, $value = []) + protected function getActual(string $name, array $value = []): array { return $this ->getQueryObject() ->whereNotIn($name, $value) - ->query(); + ->toArray(); } } diff --git a/tests/WhereNotTest.php b/tests/WhereNotTest.php index c11e4c1..648b89f 100755 --- a/tests/WhereNotTest.php +++ b/tests/WhereNotTest.php @@ -1,134 +1,146 @@ ", - ">=", - "<", - "<=", - "like", - "exists", + protected array $operators = [ + '=', + '!=', + '>', + '>=', + '<', + '<=', + 'like', + 'exists', ]; /** * Test the whereNot() method. * - * @return void + * @throws ClassAlreadyExistsException + * @throws ClassIsFinalException + * @throws ClassIsReadonlyException + * @throws DuplicateMethodException + * @throws ExpectationFailedException + * @throws InvalidArgumentException + * @throws InvalidMethodNameException + * @throws OriginalConstructorInvocationRequiredException + * @throws ReflectionException + * @throws RuntimeException + * @throws UnknownTypeException + * @throws \PHPUnit\Framework\InvalidArgumentException */ public function testWhereNotMethod(): void { self::assertEquals( - $this->getExpected("status", "published"), - $this->getActual("status", "published") + $this->getExpected('status', 'published'), + $this->getActual('status', 'published') ); self::assertEquals( - $this->getExpected("status", "=", "published"), - $this->getActual("status", "=", "published") + $this->getExpected('status', '=', 'published'), + $this->getActual('status', '=', 'published') ); self::assertEquals( - $this->getExpected("views", ">", 1000), - $this->getActual("views", ">", 1000) + $this->getExpected('views', '>', 1000), + $this->getActual('views', '>', 1000) ); self::assertEquals( - $this->getExpected("views", ">=", 1000), - $this->getActual("views", ">=", 1000) + $this->getExpected('views', '>=', 1000), + $this->getActual('views', '>=', 1000) ); self::assertEquals( - $this->getExpected("views", "<=", 1000), - $this->getActual("views", "<=", 1000) + $this->getExpected('views', '<=', 1000), + $this->getActual('views', '<=', 1000) ); self::assertEquals( - $this->getExpected("content", "like", "hello"), - $this->getActual("content", "like", "hello") + $this->getExpected('content', 'like', 'hello'), + $this->getActual('content', 'like', 'hello') ); self::assertEquals( - $this->getExpected("website", "exists", true), - $this->getActual("website", "exists", true) + $this->getExpected('website', 'exists', true), + $this->getActual('website', 'exists', true) ); self::assertEquals( - $this->getExpected("website", "exists", false), - $this->getActual("website", "exists", false) + $this->getExpected('website', 'exists', false), + $this->getActual('website', 'exists', false) ); } - /** - * @param $name - * @param string $operator - * @param null $value - * - * @return array - */ protected function getExpected( string $name, - string $operator = "=", - $value = null + string $operator = '=', + mixed $value = null ): array { $query = $this->getQueryArray(); - if ( ! in_array( + if (!in_array( $operator, $this->operators, true )) { $value = $operator; - $operator = "="; + $operator = '='; } $must = []; $must_not = []; - if ($operator === "=") { - $must_not[] = ["term" => [$name => $value]]; + if ($operator === '=') { + $must_not[] = ['term' => [$name => $value]]; } - if ($operator === ">") { - $must_not[] = ["range" => [$name => ["gt" => $value]]]; + if ($operator === '>') { + $must_not[] = ['range' => [$name => ['gt' => $value]]]; } - if ($operator === ">=") { - $must_not[] = ["range" => [$name => ["gte" => $value]]]; + if ($operator === '>=') { + $must_not[] = ['range' => [$name => ['gte' => $value]]]; } - if ($operator === "<") { - $must_not[] = ["range" => [$name => ["lt" => $value]]]; + if ($operator === '<') { + $must_not[] = ['range' => [$name => ['lt' => $value]]]; } - if ($operator === "<=") { - $must_not[] = ["range" => [$name => ["lte" => $value]]]; + if ($operator === '<=') { + $must_not[] = ['range' => [$name => ['lte' => $value]]]; } - if ($operator === "like") { - $must_not[] = ["match" => [$name => $value]]; + if ($operator === 'like') { + $must_not[] = ['match' => [$name => $value]]; } - if ($operator === "exists") { + if ($operator === 'exists') { if ($value) { - $must_not[] = ["exists" => ["field" => $name]]; + $must_not[] = ['exists' => ['field' => $name]]; } else { - $must[] = ["exists" => ["field" => $name]]; + $must[] = ['exists' => ['field' => $name]]; } } @@ -137,27 +149,32 @@ protected function getExpected( $bool = []; if (count($must)) { - $bool["must"] = $must; + $bool['must'] = $must; } if (count($must_not)) { - $bool["must_not"] = $must_not; + $bool['must_not'] = $must_not; } - $query["body"]["query"]["bool"] = $bool; + $query['body']['query']['bool'] = $bool; return $query; } /** - * @param $name - * @param string $operator - * @param null $value - * - * @return mixed + * @throws \PHPUnit\Framework\InvalidArgumentException + * @throws ClassAlreadyExistsException + * @throws ClassIsFinalException + * @throws ClassIsReadonlyException + * @throws DuplicateMethodException + * @throws InvalidMethodNameException + * @throws OriginalConstructorInvocationRequiredException + * @throws ReflectionException + * @throws RuntimeException + * @throws UnknownTypeException */ - protected function getActual($name, $operator = "=", $value = null) + protected function getActual(string $name, string|null $operator = '=', mixed $value = null): array { - return $this->getQueryObject()->whereNot($name, $operator, $value)->query(); + return $this->getQueryObject()->whereNot($name, $operator, $value)->toArray(); } } diff --git a/tests/WhereTest.php b/tests/WhereTest.php index 27fc439..dc43575 100755 --- a/tests/WhereTest.php +++ b/tests/WhereTest.php @@ -8,6 +8,7 @@ use PHPUnit\Framework\ExpectationFailedException; use PHPUnit\Framework\MockObject\ClassAlreadyExistsException; use PHPUnit\Framework\MockObject\ClassIsFinalException; +use PHPUnit\Framework\MockObject\ClassIsReadonlyException; use PHPUnit\Framework\MockObject\DuplicateMethodException; use PHPUnit\Framework\MockObject\InvalidMethodNameException; use PHPUnit\Framework\MockObject\OriginalConstructorInvocationRequiredException; @@ -21,12 +22,7 @@ class WhereTest extends TestCase { use ESQueryTrait; - /** - * Filter operators - * - * @var array - */ - protected $operators = [ + protected array $operators = [ '=', '!=', '>', @@ -40,9 +36,9 @@ class WhereTest extends TestCase /** * Test the where() method. * - * @return void * @throws ClassAlreadyExistsException * @throws ClassIsFinalException + * @throws ClassIsReadonlyException * @throws DuplicateMethodException * @throws ExpectationFailedException * @throws InvalidArgumentException @@ -98,13 +94,7 @@ public function testWhereMethod(): void } /** - * @param string $name - * @param string $operator * @param mixed|null $value - * - * @return array - * @throws \InvalidArgumentException - * @throws \PHPUnit\Framework\InvalidArgumentException * @throws ClassAlreadyExistsException * @throws ClassIsFinalException * @throws DuplicateMethodException @@ -113,11 +103,14 @@ public function testWhereMethod(): void * @throws ReflectionException * @throws RuntimeException * @throws UnknownTypeException + * @throws \InvalidArgumentException + * @throws \PHPUnit\Framework\InvalidArgumentException + * @throws ClassIsReadonlyException */ protected function getActual( string $name, string $operator = '=', - $value = null + mixed $value = null ): array { return $this ->getQueryObject() @@ -126,20 +119,17 @@ protected function getActual( } /** - * @param string $name - * @param string $operator * @param mixed|null $value * - * @return array */ protected function getExpected( string $name, string $operator = '=', - $value = null + mixed $value = null ): array { $query = $this->getQueryArray(); - if ( ! in_array( + if (!in_array( $operator, $this->operators, true