diff --git a/src/Contracts/DeleteTasksQuery.php b/src/Contracts/DeleteTasksQuery.php index 19b08923..4a1b7493 100644 --- a/src/Contracts/DeleteTasksQuery.php +++ b/src/Contracts/DeleteTasksQuery.php @@ -10,9 +10,17 @@ class DeleteTasksQuery { use TasksQueryTrait; - private array $canceledBy; - - public function setCanceledBy(array $canceledBy) + /** + * @var non-empty-list|null + */ + private ?array $canceledBy = null; + + /** + * @param non-empty-list $canceledBy + * + * @return $this + */ + public function setCanceledBy(array $canceledBy): self { $this->canceledBy = $canceledBy; @@ -24,8 +32,8 @@ public function toArray(): array return array_filter( array_merge( $this->baseArray(), - ['canceledBy' => $this->formatArray($this->canceledBy ?? null)] - ), function ($item) { return null != $item || is_numeric($item); } + ['canceledBy' => $this->formatArray($this->canceledBy)] + ), static function ($item) { return null !== $item; } ); } } diff --git a/src/Contracts/DocumentsQuery.php b/src/Contracts/DocumentsQuery.php index 223986ba..86211d7e 100644 --- a/src/Contracts/DocumentsQuery.php +++ b/src/Contracts/DocumentsQuery.php @@ -6,27 +6,58 @@ class DocumentsQuery { - private int $offset; - private int $limit; - private array $fields; - private array $filter; + /** + * @var non-negative-int|null + */ + private ?int $offset = null; + + /** + * @var non-negative-int|null + */ + private ?int $limit = null; + + /** + * @var non-empty-list|null + */ + private ?array $fields = null; + + /** + * @var list>|null + */ + private ?array $filter = null; + private ?bool $retrieveVectors = null; - public function setOffset(int $offset): DocumentsQuery + /** + * @param non-negative-int $offset + * + * @return $this + */ + public function setOffset(int $offset): self { $this->offset = $offset; return $this; } - public function setLimit(int $limit): DocumentsQuery + /** + * @param non-negative-int $limit + * + * @return $this + */ + public function setLimit(int $limit): self { $this->limit = $limit; return $this; } - public function setFields(array $fields): DocumentsQuery + /** + * @param non-empty-list $fields + * + * @return $this + */ + public function setFields(array $fields): self { $this->fields = $fields; @@ -38,9 +69,9 @@ public function setFields(array $fields): DocumentsQuery * * @param list> $filter a filter expression written as an array of strings * - * @return DocumentsQuery the updated DocumentsQuery instance + * @return $this */ - public function setFilter(array $filter): DocumentsQuery + public function setFilter(array $filter): self { $this->filter = $filter; @@ -49,8 +80,10 @@ public function setFilter(array $filter): DocumentsQuery /** * @param bool|null $retrieveVectors boolean value to show _vector details + * + * @return $this */ - public function setRetrieveVectors(?bool $retrieveVectors): DocumentsQuery + public function setRetrieveVectors(?bool $retrieveVectors): self { $this->retrieveVectors = $retrieveVectors; @@ -64,7 +97,27 @@ public function setRetrieveVectors(?bool $retrieveVectors): DocumentsQuery */ public function hasFilter(): bool { - return isset($this->filter); + return null !== $this->filter; + } + + /** + * @return array{ + * offset?: non-negative-int, + * limit?: non-negative-int, + * fields?: non-empty-list|non-empty-string, + * filter?: list>, + * retrieveVectors?: 'true'|'false' + * } + */ + public function toArray(): array + { + return array_filter([ + 'offset' => $this->offset, + 'limit' => $this->limit, + 'fields' => $this->getFields(), + 'filter' => $this->filter, + 'retrieveVectors' => (null !== $this->retrieveVectors ? ($this->retrieveVectors ? 'true' : 'false') : null), + ], static function ($item) { return null !== $item; }); } /** @@ -75,27 +128,16 @@ public function hasFilter(): bool * * @return array|string|null */ - private function fields() + private function getFields() { - if (!isset($this->fields)) { + if (null === $this->fields) { return null; } - if ($this->hasFilter()) { + if (null !== $this->filter) { return $this->fields; - } else { - return implode(',', $this->fields); } - } - public function toArray(): array - { - return array_filter([ - 'offset' => $this->offset ?? null, - 'limit' => $this->limit ?? null, - 'filter' => $this->filter ?? null, - 'fields' => $this->fields(), - 'retrieveVectors' => (null !== $this->retrieveVectors ? ($this->retrieveVectors ? 'true' : 'false') : null), - ], function ($item) { return null !== $item; }); + return implode(',', $this->fields); } } diff --git a/src/Contracts/FacetSearchQuery.php b/src/Contracts/FacetSearchQuery.php index c9a1e87a..db2566b1 100644 --- a/src/Contracts/FacetSearchQuery.php +++ b/src/Contracts/FacetSearchQuery.php @@ -6,55 +6,118 @@ class FacetSearchQuery { + /** + * @var non-empty-string|null + */ + private ?string $facetName = null; + + /** + * @var non-empty-string|null + */ + private ?string $facetQuery = null; + private ?string $q = null; - private ?string $matchingStrategy = null; + + /** + * @var list>|null + */ private ?array $filter = null; - private ?string $facetQuery = null; - private ?string $facetName = null; - public function setQuery(string $q): FacetSearchQuery + /** + * @var 'last'|'all'|'frequency'|null + */ + private ?string $matchingStrategy = null; + + /** + * @var non-empty-list|null + */ + private ?array $attributesToSearchOn = null; + + /** + * @return $this + */ + public function setFacetName(string $facetName): self { - $this->q = $q; + $this->facetName = $facetName; return $this; } - public function setMatchingStrategy(string $matchingStrategy): FacetSearchQuery + /** + * @return $this + */ + public function setFacetQuery(string $facetQuery): self { - $this->matchingStrategy = $matchingStrategy; + $this->facetQuery = $facetQuery; return $this; } - public function setFilter(array $filter): FacetSearchQuery + /** + * @return $this + */ + public function setQuery(string $q): self + { + $this->q = $q; + + return $this; + } + + /** + * @param list> $filter + * + * @return $this + */ + public function setFilter(array $filter): self { $this->filter = $filter; return $this; } - public function setFacetQuery(string $facetQuery): FacetSearchQuery + /** + * @param 'last'|'all'|'frequency' $matchingStrategy + * + * @return $this + */ + public function setMatchingStrategy(string $matchingStrategy): self { - $this->facetQuery = $facetQuery; + $this->matchingStrategy = $matchingStrategy; return $this; } - public function setFacetName(string $facetName): FacetSearchQuery + /** + * @param non-empty-list $attributesToSearchOn + * + * @return $this + */ + public function setAttributesToSearchOn(array $attributesToSearchOn): self { - $this->facetName = $facetName; + $this->attributesToSearchOn = $attributesToSearchOn; return $this; } + /** + * @return array{ + * facetName?: non-empty-string, + * facetQuery?: non-empty-string, + * q?: string, + * filter?: list>, + * matchingStrategy?: 'last'|'all'|'frequency'|null, + * attributesToSearchOn?: non-empty-list + * } + */ public function toArray(): array { return array_filter([ + 'facetName' => $this->facetName, + 'facetQuery' => $this->facetQuery, 'q' => $this->q, - 'matchingStrategy' => $this->matchingStrategy, 'filter' => $this->filter, - 'facetQuery' => $this->facetQuery, - 'facetName' => $this->facetName, - ], function ($item) { return null !== $item; }); + 'matchingStrategy' => $this->matchingStrategy, + 'attributesToSearchOn' => $this->attributesToSearchOn, + ], static function ($item) { return null !== $item; }); } } diff --git a/src/Contracts/FederationOptions.php b/src/Contracts/FederationOptions.php index 770e484f..43fda7bc 100644 --- a/src/Contracts/FederationOptions.php +++ b/src/Contracts/FederationOptions.php @@ -8,13 +8,21 @@ class FederationOptions { private ?float $weight = null; - public function setWeight(float $weight): FederationOptions + /** + * @return $this + */ + public function setWeight(float $weight): self { $this->weight = $weight; return $this; } + /** + * @return array{ + * weight?: float, + * } + */ public function toArray(): array { return array_filter([ diff --git a/src/Contracts/HybridSearchOptions.php b/src/Contracts/HybridSearchOptions.php index 654b7535..affe8458 100644 --- a/src/Contracts/HybridSearchOptions.php +++ b/src/Contracts/HybridSearchOptions.php @@ -13,7 +13,10 @@ class HybridSearchOptions */ private ?string $embedder = null; - public function setSemanticRatio(float $ratio): HybridSearchOptions + /** + * @return $this + */ + public function setSemanticRatio(float $ratio): self { $this->semanticRatio = $ratio; @@ -22,8 +25,10 @@ public function setSemanticRatio(float $ratio): HybridSearchOptions /** * @param non-empty-string $embedder + * + * @return $this */ - public function setEmbedder(string $embedder): HybridSearchOptions + public function setEmbedder(string $embedder): self { $this->embedder = $embedder; diff --git a/src/Contracts/IndexesQuery.php b/src/Contracts/IndexesQuery.php index e4fd08c3..5cebe88f 100644 --- a/src/Contracts/IndexesQuery.php +++ b/src/Contracts/IndexesQuery.php @@ -6,28 +6,51 @@ class IndexesQuery { - private int $offset; - private int $limit; - - public function setOffset(int $offset): IndexesQuery + /** + * @var non-negative-int|null + */ + private ?int $offset = null; + + /** + * @var non-negative-int|null + */ + private ?int $limit = null; + + /** + * @param non-negative-int $offset + * + * @return $this + */ + public function setOffset(int $offset): self { $this->offset = $offset; return $this; } - public function setLimit(int $limit): IndexesQuery + /** + * @param non-negative-int $limit + * + * @return $this + */ + public function setLimit(int $limit): self { $this->limit = $limit; return $this; } + /** + * @return array{ + * offset?: non-negative-int, + * limit?: non-negative-int + * } + */ public function toArray(): array { return array_filter([ - 'offset' => $this->offset ?? null, - 'limit' => $this->limit ?? null, - ], function ($item) { return null != $item || is_numeric($item); }); + 'offset' => $this->offset, + 'limit' => $this->limit, + ], static function ($item) { return null !== $item; }); } } diff --git a/src/Contracts/KeysQuery.php b/src/Contracts/KeysQuery.php index 8fff6acb..1f56f668 100644 --- a/src/Contracts/KeysQuery.php +++ b/src/Contracts/KeysQuery.php @@ -6,28 +6,51 @@ class KeysQuery { - private int $offset; - private int $limit; - - public function setOffset(int $offset): KeysQuery + /** + * @var non-negative-int|null + */ + private ?int $offset = null; + + /** + * @var non-negative-int|null + */ + private ?int $limit = null; + + /** + * @param non-negative-int $offset + * + * @return $this + */ + public function setOffset(int $offset): self { $this->offset = $offset; return $this; } - public function setLimit(int $limit): KeysQuery + /** + * @param non-negative-int $limit + * + * @return $this + */ + public function setLimit(int $limit): self { $this->limit = $limit; return $this; } + /** + * @return array{ + * offset?: non-negative-int, + * limit?: non-negative-int + * } + */ public function toArray(): array { return array_filter([ - 'offset' => $this->offset ?? null, - 'limit' => $this->limit ?? null, - ], function ($item) { return null != $item || is_numeric($item); }); + 'offset' => $this->offset, + 'limit' => $this->limit, + ], static function ($item) { return null !== $item; }); } } diff --git a/src/Contracts/MultiSearchFederation.php b/src/Contracts/MultiSearchFederation.php index 8ab60de5..3f9db1ec 100644 --- a/src/Contracts/MultiSearchFederation.php +++ b/src/Contracts/MultiSearchFederation.php @@ -6,23 +6,46 @@ class MultiSearchFederation { + /** + * @var non-negative-int|null + */ private ?int $limit = null; + + /** + * @var non-negative-int|null + */ private ?int $offset = null; - public function setLimit(int $limit): MultiSearchFederation + /** + * @param non-negative-int $limit + * + * @return $this + */ + public function setLimit(int $limit): self { $this->limit = $limit; return $this; } - public function setOffset(int $offset): MultiSearchFederation + /** + * @param non-negative-int $offset + * + * @return $this + */ + public function setOffset(int $offset): self { $this->offset = $offset; return $this; } + /** + * @return array{ + * limit?: non-negative-int, + * offset?: non-negative-int + * } + */ public function toArray(): array { return array_filter([ diff --git a/src/Contracts/SearchQuery.php b/src/Contracts/SearchQuery.php index 79db1575..da71dc2e 100644 --- a/src/Contracts/SearchQuery.php +++ b/src/Contracts/SearchQuery.php @@ -6,43 +6,127 @@ class SearchQuery { - private string $indexUid; - - private string $q; - private array $filter; - private array $locales; - private array $attributesToRetrieve; - private array $attributesToCrop; - private ?int $cropLength; - private array $attributesToHighlight; - private string $cropMarker; - private string $highlightPreTag; - private string $highlightPostTag; - private array $facets; - private ?bool $showMatchesPosition; - private array $sort; - private string $matchingStrategy; - private ?int $offset; - private ?int $limit; - private ?int $hitsPerPage; - private ?int $page; - private ?array $vector; + /** + * @var non-empty-string|null + */ + private ?string $indexUid = null; + + private ?string $q = null; + + /** + * @var list>|null + */ + private ?array $filter = null; + + /** + * @var list|null + */ + private ?array $locales = null; + + /** + * @var list|null + */ + private ?array $attributesToRetrieve = null; + + /** + * @var list|null + */ + private ?array $attributesToCrop = null; + + /** + * @var positive-int|null + */ + private ?int $cropLength = null; + + /** + * @var list|null + */ + private ?array $attributesToHighlight = null; + + private ?string $cropMarker = null; + + private ?string $highlightPreTag = null; + + private ?string $highlightPostTag = null; + + /** + * @var list|null + */ + private ?array $facets = null; + + private ?bool $showMatchesPosition = null; + + /** + * @var list|null + */ + private ?array $sort = null; + + /** + * @var 'last'|'all'|'frequency'|null + */ + private ?string $matchingStrategy = null; + + /** + * @var non-negative-int|null + */ + private ?int $offset = null; + + /** + * @var non-negative-int|null + */ + private ?int $limit = null; + + /** + * @var non-negative-int|null + */ + private ?int $hitsPerPage = null; + + /** + * @var non-negative-int|null + */ + private ?int $page = null; + + /** + * @var non-empty-list>|null + */ + private ?array $vector = null; + private ?HybridSearchOptions $hybrid = null; + + /** + * @var non-empty-list|null + */ private ?array $attributesToSearchOn = null; + private ?bool $showRankingScore = null; + private ?bool $showRankingScoreDetails = null; + private ?float $rankingScoreThreshold = null; + + /** + * @var non-empty-string|null + */ private ?string $distinct = null; + private ?FederationOptions $federationOptions = null; - public function setQuery(string $q): SearchQuery + /** + * @return $this + */ + public function setQuery(string $q): self { $this->q = $q; return $this; } - public function setFilter(array $filter): SearchQuery + /** + * @param list> $filter + * + * @return $this + */ + public function setFilter(array $filter): self { $this->filter = $filter; @@ -51,78 +135,116 @@ public function setFilter(array $filter): SearchQuery /** * @param list $locales + * + * @return $this */ - public function setLocales(array $locales): SearchQuery + public function setLocales(array $locales): self { $this->locales = $locales; return $this; } - public function setAttributesToRetrieve(array $attributesToRetrieve): SearchQuery + /** + * @return $this + */ + public function setAttributesToRetrieve(array $attributesToRetrieve): self { $this->attributesToRetrieve = $attributesToRetrieve; return $this; } - public function setAttributesToCrop(array $attributesToCrop): SearchQuery + /** + * @return $this + */ + public function setAttributesToCrop(array $attributesToCrop): self { $this->attributesToCrop = $attributesToCrop; return $this; } - public function setCropLength(?int $cropLength): SearchQuery + /** + * @param positive-int|null $cropLength + * + * @return $this + */ + public function setCropLength(?int $cropLength): self { $this->cropLength = $cropLength; return $this; } - public function setAttributesToHighlight(array $attributesToHighlight): SearchQuery + /** + * @param list $attributesToHighlight + * + * @return $this + */ + public function setAttributesToHighlight(array $attributesToHighlight): self { $this->attributesToHighlight = $attributesToHighlight; return $this; } - public function setCropMarker(string $cropMarker): SearchQuery + /** + * @return $this + */ + public function setCropMarker(string $cropMarker): self { $this->cropMarker = $cropMarker; return $this; } - public function setHighlightPreTag(string $highlightPreTag): SearchQuery + /** + * @return $this + */ + public function setHighlightPreTag(string $highlightPreTag): self { $this->highlightPreTag = $highlightPreTag; return $this; } - public function setHighlightPostTag(string $highlightPostTag): SearchQuery + /** + * @return $this + */ + public function setHighlightPostTag(string $highlightPostTag): self { $this->highlightPostTag = $highlightPostTag; return $this; } - public function setFacets(array $facets): SearchQuery + /** + * @param list $facets + * + * @return $this + */ + public function setFacets(array $facets): self { $this->facets = $facets; return $this; } - public function setShowMatchesPosition(?bool $showMatchesPosition): SearchQuery + /** + * @return $this + */ + public function setShowMatchesPosition(?bool $showMatchesPosition): self { $this->showMatchesPosition = $showMatchesPosition; return $this; } - public function setShowRankingScore(?bool $showRankingScore): SearchQuery + /** + * @return $this + */ + public function setShowRankingScore(?bool $showRankingScore): self { $this->showRankingScore = $showRankingScore; @@ -137,15 +259,20 @@ public function setShowRankingScore(?bool $showRankingScore): SearchQuery * More info: https://www.meilisearch.com/docs/reference/api/experimental-features * * @param bool $showRankingScoreDetails whether the feature is enabled or not + * + * @return $this */ - public function setShowRankingScoreDetails(?bool $showRankingScoreDetails): SearchQuery + public function setShowRankingScoreDetails(?bool $showRankingScoreDetails): self { $this->showRankingScoreDetails = $showRankingScoreDetails; return $this; } - public function setRankingScoreThreshold(?float $rankingScoreThreshold): SearchQuery + /** + * @return $this + */ + public function setRankingScoreThreshold(?float $rankingScoreThreshold): self { $this->rankingScoreThreshold = $rankingScoreThreshold; @@ -154,57 +281,88 @@ public function setRankingScoreThreshold(?float $rankingScoreThreshold): SearchQ /** * @param non-empty-string|null $distinct + * + * @return $this */ - public function setDistinct(?string $distinct): SearchQuery + public function setDistinct(?string $distinct): self { $this->distinct = $distinct; return $this; } - public function setSort(array $sort): SearchQuery + /** + * @return $this + */ + public function setSort(array $sort): self { $this->sort = $sort; return $this; } - public function setMatchingStrategy(string $matchingStrategy): SearchQuery + /** + * @param 'last'|'all'|'frequency' $matchingStrategy + * + * @return $this + */ + public function setMatchingStrategy(string $matchingStrategy): self { $this->matchingStrategy = $matchingStrategy; return $this; } - public function setOffset(?int $offset): SearchQuery + /** + * @param non-negative-int|null $offset + * + * @return $this + */ + public function setOffset(?int $offset): self { $this->offset = $offset; return $this; } - public function setLimit(?int $limit): SearchQuery + /** + * @param non-negative-int|null $limit + * + * @return $this + */ + public function setLimit(?int $limit): self { $this->limit = $limit; return $this; } - public function setHitsPerPage(?int $hitsPerPage): SearchQuery + /** + * @param non-negative-int|null $hitsPerPage + * + * @return $this + */ + public function setHitsPerPage(?int $hitsPerPage): self { $this->hitsPerPage = $hitsPerPage; return $this; } - public function setPage(?int $page): SearchQuery + /** + * @return $this + */ + public function setPage(?int $page): self { $this->page = $page; return $this; } - public function setIndexUid(string $uid): SearchQuery + /** + * @return $this + */ + public function setIndexUid(string $uid): self { $this->indexUid = $uid; @@ -214,8 +372,10 @@ public function setIndexUid(string $uid): SearchQuery /** * This option is only available while doing a federated search. * If used in another context an error will be returned by Meilisearch. + * + * @return $this */ - public function setFederationOptions(FederationOptions $federationOptions): SearchQuery + public function setFederationOptions(FederationOptions $federationOptions): self { $this->federationOptions = $federationOptions; @@ -229,9 +389,11 @@ public function setFederationOptions(FederationOptions $federationOptions): Sear * * More info: https://www.meilisearch.com/docs/reference/api/experimental-features * - * @param list> $vector a multi-level array floats + * @param non-empty-list> $vector a multi-level array floats + * + * @return $this */ - public function setVector(array $vector): SearchQuery + public function setVector(array $vector): self { $this->vector = $vector; @@ -245,8 +407,10 @@ public function setVector(array $vector): SearchQuery * (new HybridSearchOptions()) * ->setSemanticRatio(0.8) * ->setEmbedder('manual'); + * + * @return $this */ - public function setHybrid(HybridSearchOptions $hybridOptions): SearchQuery + public function setHybrid(HybridSearchOptions $hybridOptions): self { $this->hybrid = $hybridOptions; @@ -254,38 +418,71 @@ public function setHybrid(HybridSearchOptions $hybridOptions): SearchQuery } /** - * @param list $attributesToSearchOn + * @param non-empty-list $attributesToSearchOn + * + * @return $this */ - public function setAttributesToSearchOn(array $attributesToSearchOn): SearchQuery + public function setAttributesToSearchOn(array $attributesToSearchOn): self { $this->attributesToSearchOn = $attributesToSearchOn; return $this; } + /** + * @return array{ + * indexUid?: non-empty-string, + * q?: string, + * filter?: list>, + * locales?: list, + * attributesToRetrieve?: list, + * attributesToCrop?: list, + * cropLength?: positive-int, + * attributesToHighlight?: list, + * cropMarker?: string, + * highlightPreTag?: string, + * highlightPostTag?: string, + * facets?: list, + * showMatchesPosition?: bool, + * sort?: list, + * matchingStrategy?: 'last'|'all'|'frequency', + * offset?: non-negative-int, + * limit?: non-negative-int, + * hitsPerPage?: non-negative-int, + * page?: non-negative-int, + * vector?: non-empty-list>, + * hybrid?: array, + * attributesToSearchOn?: non-empty-list, + * showRankingScore?: bool, + * showRankingScoreDetails?: bool, + * rankingScoreThreshold?: float, + * distinct?: non-empty-string, + * federationOptions?: array + * } + */ public function toArray(): array { return array_filter([ - 'indexUid' => $this->indexUid ?? null, - 'q' => $this->q ?? null, - 'filter' => $this->filter ?? null, - 'locales' => $this->locales ?? null, - 'attributesToRetrieve' => $this->attributesToRetrieve ?? null, - 'attributesToCrop' => $this->attributesToCrop ?? null, - 'cropLength' => $this->cropLength ?? null, - 'attributesToHighlight' => $this->attributesToHighlight ?? null, - 'cropMarker' => $this->cropMarker ?? null, - 'highlightPreTag' => $this->highlightPreTag ?? null, - 'highlightPostTag' => $this->highlightPostTag ?? null, - 'facets' => $this->facets ?? null, - 'showMatchesPosition' => $this->showMatchesPosition ?? null, - 'sort' => $this->sort ?? null, - 'matchingStrategy' => $this->matchingStrategy ?? null, - 'offset' => $this->offset ?? null, - 'limit' => $this->limit ?? null, - 'hitsPerPage' => $this->hitsPerPage ?? null, - 'page' => $this->page ?? null, - 'vector' => $this->vector ?? null, + 'indexUid' => $this->indexUid, + 'q' => $this->q, + 'filter' => $this->filter, + 'locales' => $this->locales, + 'attributesToRetrieve' => $this->attributesToRetrieve, + 'attributesToCrop' => $this->attributesToCrop, + 'cropLength' => $this->cropLength, + 'attributesToHighlight' => $this->attributesToHighlight, + 'cropMarker' => $this->cropMarker, + 'highlightPreTag' => $this->highlightPreTag, + 'highlightPostTag' => $this->highlightPostTag, + 'facets' => $this->facets, + 'showMatchesPosition' => $this->showMatchesPosition, + 'sort' => $this->sort, + 'matchingStrategy' => $this->matchingStrategy, + 'offset' => $this->offset, + 'limit' => $this->limit, + 'hitsPerPage' => $this->hitsPerPage, + 'page' => $this->page, + 'vector' => $this->vector, 'hybrid' => null !== $this->hybrid ? $this->hybrid->toArray() : null, 'attributesToSearchOn' => $this->attributesToSearchOn, 'showRankingScore' => $this->showRankingScore, @@ -293,6 +490,6 @@ public function toArray(): array 'rankingScoreThreshold' => $this->rankingScoreThreshold, 'distinct' => $this->distinct, 'federationOptions' => null !== $this->federationOptions ? $this->federationOptions->toArray() : null, - ], function ($item) { return null !== $item; }); + ], static function ($item) { return null !== $item; }); } } diff --git a/src/Contracts/SimilarDocumentsQuery.php b/src/Contracts/SimilarDocumentsQuery.php index 531610c8..ab6dc95b 100644 --- a/src/Contracts/SimilarDocumentsQuery.php +++ b/src/Contracts/SimilarDocumentsQuery.php @@ -57,8 +57,10 @@ public function __construct($id) /** * @param non-negative-int|null $offset + * + * @return $this */ - public function setOffset(?int $offset): SimilarDocumentsQuery + public function setOffset(?int $offset): self { $this->offset = $offset; @@ -67,8 +69,10 @@ public function setOffset(?int $offset): SimilarDocumentsQuery /** * @param positive-int|null $limit + * + * @return $this */ - public function setLimit(?int $limit): SimilarDocumentsQuery + public function setLimit(?int $limit): self { $this->limit = $limit; @@ -77,8 +81,10 @@ public function setLimit(?int $limit): SimilarDocumentsQuery /** * @param array|string> $filter an array of arrays representing filter conditions + * + * @return $this */ - public function setFilter(array $filter): SimilarDocumentsQuery + public function setFilter(array $filter): self { $this->filter = $filter; @@ -87,8 +93,10 @@ public function setFilter(array $filter): SimilarDocumentsQuery /** * @param non-empty-string $embedder + * + * @return $this */ - public function setEmbedder(string $embedder): SimilarDocumentsQuery + public function setEmbedder(string $embedder): self { $this->embedder = $embedder; @@ -97,8 +105,10 @@ public function setEmbedder(string $embedder): SimilarDocumentsQuery /** * @param list $attributesToRetrieve an array of attribute names to retrieve + * + * @return $this */ - public function setAttributesToRetrieve(array $attributesToRetrieve): SimilarDocumentsQuery + public function setAttributesToRetrieve(array $attributesToRetrieve): self { $this->attributesToRetrieve = $attributesToRetrieve; @@ -107,8 +117,10 @@ public function setAttributesToRetrieve(array $attributesToRetrieve): SimilarDoc /** * @param bool|null $showRankingScore boolean value to show ranking score + * + * @return $this */ - public function setShowRankingScore(?bool $showRankingScore): SimilarDocumentsQuery + public function setShowRankingScore(?bool $showRankingScore): self { $this->showRankingScore = $showRankingScore; @@ -117,8 +129,10 @@ public function setShowRankingScore(?bool $showRankingScore): SimilarDocumentsQu /** * @param bool|null $showRankingScoreDetails boolean value to show ranking score details + * + * @return $this */ - public function setShowRankingScoreDetails(?bool $showRankingScoreDetails): SimilarDocumentsQuery + public function setShowRankingScoreDetails(?bool $showRankingScoreDetails): self { $this->showRankingScoreDetails = $showRankingScoreDetails; @@ -127,8 +141,10 @@ public function setShowRankingScoreDetails(?bool $showRankingScoreDetails): Simi /** * @param bool|null $retrieveVectors boolean value to show _vector details + * + * @return $this */ - public function setRetrieveVectors(?bool $retrieveVectors): SimilarDocumentsQuery + public function setRetrieveVectors(?bool $retrieveVectors): self { $this->retrieveVectors = $retrieveVectors; @@ -137,8 +153,10 @@ public function setRetrieveVectors(?bool $retrieveVectors): SimilarDocumentsQuer /** * @param int|float|null $rankingScoreThreshold + * + * @return $this */ - public function setRankingScoreThreshold($rankingScoreThreshold): SimilarDocumentsQuery + public function setRankingScoreThreshold($rankingScoreThreshold): self { $this->rankingScoreThreshold = $rankingScoreThreshold; @@ -172,8 +190,6 @@ public function toArray(): array 'showRankingScoreDetails' => $this->showRankingScoreDetails, 'retrieveVectors' => $this->retrieveVectors, 'rankingScoreThreshold' => $this->rankingScoreThreshold, - ], static function ($item) { - return null !== $item; - }); + ], static function ($item) {return null !== $item; }); } } diff --git a/src/Contracts/TasksQuery.php b/src/Contracts/TasksQuery.php index 6baa6e76..174fdffe 100644 --- a/src/Contracts/TasksQuery.php +++ b/src/Contracts/TasksQuery.php @@ -10,25 +10,44 @@ class TasksQuery { use TasksQueryTrait; - private int $from; - private int $limit; - private array $canceledBy; + private ?int $from = null; - public function setFrom(int $from): TasksQuery + /** + * @var non-negative-int|null + */ + private ?int $limit = null; + + /** + * @var non-empty-list|null + */ + private ?array $canceledBy = null; + + /** + * @return $this + */ + public function setFrom(int $from): self { $this->from = $from; return $this; } - public function setCanceledBy(array $canceledBy): TasksQuery + /** + * @param non-empty-list $canceledBy + * + * @return $this + */ + public function setCanceledBy(array $canceledBy): self { $this->canceledBy = $canceledBy; return $this; } - public function setLimit(int $limit): TasksQuery + /** + * @return $this + */ + public function setLimit(int $limit): self { $this->limit = $limit; @@ -41,11 +60,11 @@ public function toArray(): array array_merge( $this->baseArray(), [ - 'from' => $this->from ?? null, - 'limit' => $this->limit ?? null, - 'canceledBy' => $this->formatArray($this->canceledBy ?? null), + 'from' => $this->from, + 'limit' => $this->limit, + 'canceledBy' => $this->formatArray($this->canceledBy), ] - ), function ($item) { return null != $item || is_numeric($item); } + ), static function ($item) { return null !== $item; } ); } } diff --git a/src/Contracts/TasksResults.php b/src/Contracts/TasksResults.php index a77cb8bd..97b7ac8e 100644 --- a/src/Contracts/TasksResults.php +++ b/src/Contracts/TasksResults.php @@ -7,19 +7,22 @@ class TasksResults extends Data { /** - * @var int<0, max> + * @var non-negative-int */ private int $next; + /** - * @var int<0, max> + * @var non-negative-int */ private int $limit; + /** - * @var int<0, max> + * @var non-negative-int */ private int $from; + /** - * @var int<0, max> + * @var non-negative-int */ private int $total; @@ -41,21 +44,33 @@ public function getResults(): array return $this->data; } + /** + * @return non-negative-int + */ public function getNext(): int { return $this->next; } + /** + * @return non-negative-int + */ public function getLimit(): int { return $this->limit; } + /** + * @return non-negative-int + */ public function getFrom(): int { return $this->from; } + /** + * @return non-negative-int + */ public function getTotal(): int { return $this->total; diff --git a/src/Endpoints/Delegates/HandlesDocuments.php b/src/Endpoints/Delegates/HandlesDocuments.php index 085a0f5d..f461d2bf 100644 --- a/src/Endpoints/Delegates/HandlesDocuments.php +++ b/src/Endpoints/Delegates/HandlesDocuments.php @@ -61,6 +61,7 @@ public function addDocumentsNdjson(string $documents, ?string $primaryKey = null public function addDocumentsInBatches(array $documents, ?int $batchSize = 1000, ?string $primaryKey = null) { $promises = []; + foreach (self::batch($documents, $batchSize) as $batch) { $promises[] = $this->addDocuments($batch, $primaryKey); } @@ -82,6 +83,7 @@ public function addDocumentsCsvInBatches(string $documents, ?int $batchSize = 10 public function addDocumentsNdjsonInBatches(string $documents, ?int $batchSize = 1000, ?string $primaryKey = null) { $promises = []; + foreach (self::batchNdjsonString($documents, $batchSize) as $batch) { $promises[] = $this->addDocumentsNdjson($batch, $primaryKey); } @@ -112,6 +114,7 @@ public function updateDocumentsNdjson(string $documents, ?string $primaryKey = n public function updateDocumentsInBatches(array $documents, ?int $batchSize = 1000, ?string $primaryKey = null) { $promises = []; + foreach (self::batch($documents, $batchSize) as $batch) { $promises[] = $this->updateDocuments($batch, $primaryKey); } @@ -122,6 +125,7 @@ public function updateDocumentsInBatches(array $documents, ?int $batchSize = 100 public function updateDocumentsCsvInBatches(string $documents, ?int $batchSize = 1000, ?string $primaryKey = null, ?string $delimiter = null) { $promises = []; + foreach (self::batchCsvString($documents, $batchSize) as $batch) { $promises[] = $this->updateDocumentsCsv($batch, $primaryKey, $delimiter); } @@ -132,6 +136,7 @@ public function updateDocumentsCsvInBatches(string $documents, ?int $batchSize = public function updateDocumentsNdjsonInBatches(string $documents, ?int $batchSize = 1000, ?string $primaryKey = null) { $promises = []; + foreach (self::batchNdjsonString($documents, $batchSize) as $batch) { $promises[] = $this->updateDocumentsNdjson($batch, $primaryKey); } @@ -194,10 +199,10 @@ private function assertValidDocumentId($documentId): void private static function batchCsvString(string $documents, int $batchSize): \Generator { - $documents = preg_split("/\r\n|\n|\r/", trim($documents)); - $csvHeader = $documents[0]; - array_shift($documents); - $batches = array_chunk($documents, $batchSize); + $parsedDocuments = preg_split("/\r\n|\n|\r/", trim($documents)); + $csvHeader = $parsedDocuments[0]; + array_shift($parsedDocuments); + $batches = array_chunk($parsedDocuments, $batchSize); /** @var array $batch */ foreach ($batches as $batch) { @@ -210,8 +215,8 @@ private static function batchCsvString(string $documents, int $batchSize): \Gene private static function batchNdjsonString(string $documents, int $batchSize): \Generator { - $documents = preg_split("/\r\n|\n|\r/", trim($documents)); - $batches = array_chunk($documents, $batchSize); + $parsedDocuments = preg_split("/\r\n|\n|\r/", trim($documents)); + $batches = array_chunk($parsedDocuments, $batchSize); /** @var array $batch */ foreach ($batches as $batch) { @@ -224,6 +229,7 @@ private static function batchNdjsonString(string $documents, int $batchSize): \G private static function batch(array $documents, int $batchSize): \Generator { $batches = array_chunk($documents, $batchSize); + foreach ($batches as $batch) { yield $batch; } diff --git a/src/Endpoints/Delegates/TasksQueryTrait.php b/src/Endpoints/Delegates/TasksQueryTrait.php index 1c87d823..058f5bbc 100644 --- a/src/Endpoints/Delegates/TasksQueryTrait.php +++ b/src/Endpoints/Delegates/TasksQueryTrait.php @@ -10,28 +10,37 @@ trait TasksQueryTrait private array $statuses; private array $indexUids; private array $uids; - private \DateTime $beforeEnqueuedAt; - private \DateTime $afterEnqueuedAt; - private \DateTime $beforeStartedAt; - private \DateTime $afterStartedAt; - private \DateTime $beforeFinishedAt; - private \DateTime $afterFinishedAt; - - public function setTypes(array $types) + private \DateTimeInterface $beforeEnqueuedAt; + private \DateTimeInterface $afterEnqueuedAt; + private \DateTimeInterface $beforeStartedAt; + private \DateTimeInterface $afterStartedAt; + private \DateTimeInterface $beforeFinishedAt; + private \DateTimeInterface $afterFinishedAt; + + /** + * @return $this + */ + public function setTypes(array $types): self { $this->types = $types; return $this; } - public function setStatuses(array $statuses) + /** + * @return $this + */ + public function setStatuses(array $statuses): self { $this->statuses = $statuses; return $this; } - public function setIndexUids(array $indexUids) + /** + * @return $this + */ + public function setIndexUids(array $indexUids): self { $this->indexUids = $indexUids; @@ -43,49 +52,70 @@ public function getIndexUids(): array return $this->indexUids ?? []; } - public function setUids(array $uids) + /** + * @return $this + */ + public function setUids(array $uids): self { $this->uids = $uids; return $this; } - public function setBeforeEnqueuedAt(\DateTime $date) + /** + * @return $this + */ + public function setBeforeEnqueuedAt(\DateTimeInterface $date): self { $this->beforeEnqueuedAt = $date; return $this; } - public function setAfterEnqueuedAt(\DateTime $date) + /** + * @return $this + */ + public function setAfterEnqueuedAt(\DateTimeInterface $date): self { $this->afterEnqueuedAt = $date; return $this; } - public function setBeforeStartedAt(\DateTime $date) + /** + * @return $this + */ + public function setBeforeStartedAt(\DateTimeInterface $date): self { $this->beforeStartedAt = $date; return $this; } - public function setAfterStartedAt(\DateTime $date) + /** + * @return $this + */ + public function setAfterStartedAt(\DateTimeInterface $date): self { $this->afterStartedAt = $date; return $this; } - public function setBeforeFinishedAt(\DateTime $date) + /** + * @return $this + */ + public function setBeforeFinishedAt(\DateTimeInterface $date): self { $this->beforeFinishedAt = $date; return $this; } - public function setAfterFinishedAt(\DateTime $date) + /** + * @return $this + */ + public function setAfterFinishedAt(\DateTimeInterface $date): self { $this->afterFinishedAt = $date; @@ -96,7 +126,7 @@ public function toArray(): array { return array_filter( $this->baseArray(), - function ($item) { return null != $item || is_numeric($item); } + static function ($item) { return null !== $item; } ); } @@ -116,13 +146,13 @@ protected function baseArray(): array ]; } - private function formatDate(?\DateTime $date) + private function formatDate(?\DateTimeInterface $date): ?string { - return isset($date) ? $date->format(\DateTime::RFC3339) : null; + return null !== $date ? $date->format(\DateTimeInterface::RFC3339) : null; } - private function formatArray(?array $arr) + private function formatArray(?array $array): ?string { - return isset($arr) ? implode(',', $arr) : null; + return null !== $array ? implode(',', $array) : null; } } diff --git a/src/Endpoints/Indexes.php b/src/Endpoints/Indexes.php index 969fcb3c..3af12493 100644 --- a/src/Endpoints/Indexes.php +++ b/src/Endpoints/Indexes.php @@ -31,10 +31,10 @@ class Indexes extends Endpoint private ?string $uid; private ?string $primaryKey; - private ?\DateTime $createdAt; - private ?\DateTime $updatedAt; + private ?\DateTimeInterface $createdAt; + private ?\DateTimeInterface $updatedAt; - public function __construct(Http $http, $uid = null, $primaryKey = null, $createdAt = null, $updatedAt = null) + public function __construct(Http $http, ?string $uid = null, ?string $primaryKey = null, ?\DateTimeInterface $createdAt = null, ?\DateTimeInterface $updatedAt = null) { $this->uid = $uid; $this->primaryKey = $primaryKey; @@ -114,12 +114,12 @@ public function getUid(): ?string return $this->uid; } - public function getCreatedAt(): ?\DateTime + public function getCreatedAt(): ?\DateTimeInterface { return $this->createdAt; } - public function getUpdatedAt(): ?\DateTime + public function getUpdatedAt(): ?\DateTimeInterface { return $this->updatedAt; } @@ -259,20 +259,20 @@ public function resetSettings(): array /** * @throws \Exception */ - public static function parseDate(?string $dateTime): ?\DateTime + public static function parseDate(?string $dateTime): ?\DateTimeInterface { if (null === $dateTime) { return null; } try { - return new \DateTime($dateTime); + return new \DateTimeImmutable($dateTime); } catch (\Exception $e) { // Trim 9th+ digit from fractional seconds. Meilisearch server can send 9 digits; PHP supports up to 8 $trimPattern = '/(^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{1,8})(?:\d{1,})?(Z|[\+-]\d{2}:\d{2})$/'; $trimmedDate = preg_replace($trimPattern, '$1$2', $dateTime); - return new \DateTime($trimmedDate); + return new \DateTimeImmutable($trimmedDate); } } } diff --git a/src/Endpoints/Keys.php b/src/Endpoints/Keys.php index 6b9be96a..bfe09efe 100644 --- a/src/Endpoints/Keys.php +++ b/src/Endpoints/Keys.php @@ -22,11 +22,11 @@ class Keys extends Endpoint private ?string $description; private ?array $actions; private ?array $indexes; - private ?\DateTime $expiresAt; - private ?\DateTime $createdAt; - private ?\DateTime $updatedAt; + private ?\DateTimeInterface $expiresAt; + private ?\DateTimeInterface $createdAt; + private ?\DateTimeInterface $updatedAt; - public function __construct(Http $http, $uid = null, $name = null, $key = null, $description = null, $actions = null, $indexes = null, $expiresAt = null, $createdAt = null, $updatedAt = null) + public function __construct(Http $http, ?string $uid = null, ?string $name = null, ?string $key = null, ?string $description = null, ?array $actions = null, ?array $indexes = null, ?\DateTimeInterface $expiresAt = null, ?\DateTimeInterface $createdAt = null, ?\DateTimeInterface $updatedAt = null) { $this->uid = $uid; $this->name = $name; @@ -89,17 +89,17 @@ protected function fill(array $attributes): self return $this; } - protected function createDate($attribute): ?\DateTime + protected function createDate($attribute): ?\DateTimeInterface { if (!\is_string($attribute)) { return null; } if (false === strpos($attribute, '.')) { - $date = date_create_from_format(\DateTime::ATOM, $attribute); + $date = \DateTimeImmutable::createFromFormat(\DateTimeInterface::ATOM, $attribute); } else { $attribute = preg_replace('/(\.\d{6})\d+/', '$1', $attribute, 1); - $date = date_create_from_format('Y-m-d\TH:i:s.uP', $attribute); + $date = \DateTimeImmutable::createFromFormat('Y-m-d\TH:i:s.uP', $attribute); } return false === $date ? null : $date; @@ -135,17 +135,17 @@ public function getIndexes(): ?array return $this->indexes; } - public function getExpiresAt(): ?\DateTime + public function getExpiresAt(): ?\DateTimeInterface { return $this->expiresAt; } - public function getCreatedAt(): ?\DateTime + public function getCreatedAt(): ?\DateTimeInterface { return $this->createdAt; } - public function getUpdatedAt(): ?\DateTime + public function getUpdatedAt(): ?\DateTimeInterface { return $this->updatedAt; } @@ -180,7 +180,7 @@ public function allRaw(array $options = []): array public function create(array $options = []): self { - if (isset($options['expiresAt']) && $options['expiresAt'] instanceof \DateTime) { + if (isset($options['expiresAt']) && $options['expiresAt'] instanceof \DateTimeInterface) { $options['expiresAt'] = $options['expiresAt']->format('Y-m-d\TH:i:s.vu\Z'); } $response = $this->http->post(self::PATH, $options); diff --git a/src/Endpoints/Tasks.php b/src/Endpoints/Tasks.php index 30b4a920..1d6d2b3f 100644 --- a/src/Endpoints/Tasks.php +++ b/src/Endpoints/Tasks.php @@ -26,17 +26,15 @@ public function all(array $query = []): array public function cancelTasks(?CancelTasksQuery $options): array { $options = $options ?? new CancelTasksQuery(); - $response = $this->http->post('/tasks/cancel', null, $options->toArray()); - return $response; + return $this->http->post('/tasks/cancel', null, $options->toArray()); } public function deleteTasks(?DeleteTasksQuery $options): array { $options = $options ?? new DeleteTasksQuery(); - $response = $this->http->delete(self::PATH, $options->toArray()); - return $response; + return $this->http->delete(self::PATH, $options->toArray()); } /** @@ -44,15 +42,19 @@ public function deleteTasks(?DeleteTasksQuery $options): array */ public function waitTask($taskUid, int $timeoutInMs, int $intervalInMs): array { - $timeout_temp = 0; - while ($timeoutInMs > $timeout_temp) { + $timeoutTemp = 0; + + while ($timeoutInMs > $timeoutTemp) { $res = $this->get($taskUid); - if ('enqueued' != $res['status'] && 'processing' != $res['status']) { + + if ('enqueued' !== $res['status'] && 'processing' !== $res['status']) { return $res; } - $timeout_temp += $intervalInMs; + + $timeoutTemp += $intervalInMs; usleep(1000 * $intervalInMs); } + throw new TimeOutException(); } @@ -62,6 +64,7 @@ public function waitTask($taskUid, int $timeoutInMs, int $intervalInMs): array public function waitTasks(array $taskUids, int $timeoutInMs, int $intervalInMs): array { $tasks = []; + foreach ($taskUids as $taskUid) { $tasks[] = $this->waitTask($taskUid, $timeoutInMs, $intervalInMs); } diff --git a/src/Endpoints/TenantToken.php b/src/Endpoints/TenantToken.php index d52b7951..4bf4f9c0 100644 --- a/src/Endpoints/TenantToken.php +++ b/src/Endpoints/TenantToken.php @@ -4,7 +4,6 @@ namespace Meilisearch\Endpoints; -use DateTime; use Meilisearch\Contracts\Endpoint; use Meilisearch\Exceptions\InvalidArgumentException; use Meilisearch\Http\Serialize\Json; @@ -27,7 +26,7 @@ private function validateTenantTokenArguments($searchRules, array $options = []) if ((!\is_array($searchRules) || [] === $searchRules) && !\is_object($searchRules)) { throw InvalidArgumentException::emptyArgument('search rules'); } - if (isset($options['expiresAt']) && new \DateTime() > $options['expiresAt']) { + if (isset($options['expiresAt']) && new \DateTimeImmutable() > $options['expiresAt']) { throw InvalidArgumentException::dateIsExpired($options['expiresAt']); } } diff --git a/src/Http/Client.php b/src/Http/Client.php index a1e0c2c7..afffc154 100644 --- a/src/Http/Client.php +++ b/src/Http/Client.php @@ -196,9 +196,9 @@ private function parseResponse(ResponseInterface $response) * * @return bool true if any header value contains 'application/json', otherwise false */ - private function isJSONResponse(array $headerValues) + private function isJSONResponse(array $headerValues): bool { - $filteredHeaders = array_filter($headerValues, function (string $headerValue) { + $filteredHeaders = array_filter($headerValues, static function (string $headerValue) { return false !== strpos($headerValue, 'application/json'); }); diff --git a/src/Http/Serialize/SerializerInterface.php b/src/Http/Serialize/SerializerInterface.php index 3c4ca3df..c39e1fab 100644 --- a/src/Http/Serialize/SerializerInterface.php +++ b/src/Http/Serialize/SerializerInterface.php @@ -12,7 +12,7 @@ interface SerializerInterface /** * Serialize data into string. * - * @param string|int|float|bool|array|null $data + * @param string|int|float|bool|array|null $data * * @return string|bool * @@ -23,7 +23,7 @@ public function serialize($data); /** * Unserialize the given string. * - * @return string|int|float|bool|array|null + * @return string|int|float|bool|array|null * * @throws JsonDecodingException */ diff --git a/src/Meilisearch.php b/src/Meilisearch.php index 08531c88..058da49b 100644 --- a/src/Meilisearch.php +++ b/src/Meilisearch.php @@ -8,7 +8,10 @@ class Meilisearch { public const VERSION = '1.10.1'; - public static function qualifiedVersion() + /** + * @return non-empty-string + */ + public static function qualifiedVersion(): string { return \sprintf('Meilisearch PHP (v%s)', self::VERSION); } diff --git a/src/Search/FacetSearchResult.php b/src/Search/FacetSearchResult.php index 2500cb07..24d3774d 100644 --- a/src/Search/FacetSearchResult.php +++ b/src/Search/FacetSearchResult.php @@ -4,6 +4,9 @@ namespace Meilisearch\Search; +/** + * @implements \IteratorAggregate>> + */ class FacetSearchResult implements \Countable, \IteratorAggregate { /** diff --git a/src/Search/SearchResult.php b/src/Search/SearchResult.php index 01afb99d..d54c9bea 100644 --- a/src/Search/SearchResult.php +++ b/src/Search/SearchResult.php @@ -4,6 +4,9 @@ namespace Meilisearch\Search; +/** + * @implements \IteratorAggregate>> + */ class SearchResult implements \Countable, \IteratorAggregate { /** diff --git a/src/Search/SimilarDocumentsSearchResult.php b/src/Search/SimilarDocumentsSearchResult.php index bfcacc44..c3b1032c 100644 --- a/src/Search/SimilarDocumentsSearchResult.php +++ b/src/Search/SimilarDocumentsSearchResult.php @@ -4,6 +4,9 @@ namespace Meilisearch\Search; +/** + * @implements \IteratorAggregate>> + */ class SimilarDocumentsSearchResult implements \Countable, \IteratorAggregate { /** diff --git a/tests/Contracts/CancelTasksQueryTest.php b/tests/Contracts/CancelTasksQueryTest.php index b44e7f5f..df9a6950 100644 --- a/tests/Contracts/CancelTasksQueryTest.php +++ b/tests/Contracts/CancelTasksQueryTest.php @@ -7,8 +7,15 @@ use Meilisearch\Contracts\CancelTasksQuery; use PHPUnit\Framework\TestCase; -class CancelTasksQueryTest extends TestCase +final class CancelTasksQueryTest extends TestCase { + public function testEmptyQuery(): void + { + $data = new CancelTasksQuery(); + + self::assertSame([], $data->toArray()); + } + public function testSetTypes(): void { $data = (new CancelTasksQuery())->setTypes(['abc', 'xyz']); @@ -16,18 +23,72 @@ public function testSetTypes(): void self::assertSame(['types' => 'abc,xyz'], $data->toArray()); } - public function testSetAnyDateFilter(): void + public function testSetStatuses(): void + { + $data = (new CancelTasksQuery())->setStatuses(['failed', 'canceled']); + + self::assertSame(['statuses' => 'failed,canceled'], $data->toArray()); + } + + public function testSetIndexUids(): void + { + $data = (new CancelTasksQuery())->setIndexUids(['uid1', 'uid2']); + + self::assertSame(['indexUids' => 'uid1,uid2'], $data->toArray()); + } + + public function testSetUids(): void + { + $data = (new CancelTasksQuery())->setUids(['uid1', 'uid2']); + + self::assertSame(['uids' => 'uid1,uid2'], $data->toArray()); + } + + public function testSetBeforeEnqueuedAt(): void { - $date = new \DateTime(); + $date = new \DateTimeImmutable(); $data = (new CancelTasksQuery())->setBeforeEnqueuedAt($date); - self::assertSame(['beforeEnqueuedAt' => $date->format(\DateTime::RFC3339)], $data->toArray()); + self::assertSame(['beforeEnqueuedAt' => $date->format(\DateTimeInterface::RFC3339)], $data->toArray()); + } + + public function testSetAfterEnqueuedAt(): void + { + $date = new \DateTimeImmutable(); + $data = (new CancelTasksQuery())->setAfterEnqueuedAt($date); + + self::assertSame(['afterEnqueuedAt' => $date->format(\DateTimeInterface::RFC3339)], $data->toArray()); + } + + public function testSetBeforeStartedAt(): void + { + $date = new \DateTimeImmutable(); + $data = (new CancelTasksQuery())->setBeforeStartedAt($date); + + self::assertSame(['beforeStartedAt' => $date->format(\DateTimeInterface::RFC3339)], $data->toArray()); + } + + public function testSetAfterStartedAt(): void + { + $date = new \DateTimeImmutable(); + $data = (new CancelTasksQuery())->setAfterStartedAt($date); + + self::assertSame(['afterStartedAt' => $date->format(\DateTimeInterface::RFC3339)], $data->toArray()); + } + + public function testSetBeforeFinishedAt(): void + { + $date = new \DateTimeImmutable(); + $data = (new CancelTasksQuery())->setBeforeFinishedAt($date); + + self::assertSame(['beforeFinishedAt' => $date->format(\DateTimeInterface::RFC3339)], $data->toArray()); } - public function testToArrayWithDifferentSets(): void + public function testSetAfterFinishedAt(): void { - $data = (new CancelTasksQuery())->setUids([1, 2, 3])->setStatuses(['enqueued']); + $date = new \DateTimeImmutable(); + $data = (new CancelTasksQuery())->setAfterFinishedAt($date); - self::assertSame(['statuses' => 'enqueued', 'uids' => '1,2,3'], $data->toArray()); + self::assertSame(['afterFinishedAt' => $date->format(\DateTimeInterface::RFC3339)], $data->toArray()); } } diff --git a/tests/Contracts/DeleteTasksQueryTest.php b/tests/Contracts/DeleteTasksQueryTest.php index 38836eba..75711b6b 100644 --- a/tests/Contracts/DeleteTasksQueryTest.php +++ b/tests/Contracts/DeleteTasksQueryTest.php @@ -7,8 +7,15 @@ use Meilisearch\Contracts\DeleteTasksQuery; use PHPUnit\Framework\TestCase; -class DeleteTasksQueryTest extends TestCase +final class DeleteTasksQueryTest extends TestCase { + public function testEmptyQuery(): void + { + $data = new DeleteTasksQuery(); + + self::assertSame([], $data->toArray()); + } + public function testSetTypes(): void { $data = (new DeleteTasksQuery())->setTypes(['abc', 'xyz']); @@ -16,18 +23,72 @@ public function testSetTypes(): void self::assertSame(['types' => 'abc,xyz'], $data->toArray()); } - public function testSetAnyDateFilter(): void + public function testSetStatuses(): void + { + $data = (new DeleteTasksQuery())->setStatuses(['failed', 'canceled']); + + self::assertSame(['statuses' => 'failed,canceled'], $data->toArray()); + } + + public function testSetIndexUids(): void + { + $data = (new DeleteTasksQuery())->setIndexUids(['uid1', 'uid2']); + + self::assertSame(['indexUids' => 'uid1,uid2'], $data->toArray()); + } + + public function testSetUids(): void + { + $data = (new DeleteTasksQuery())->setUids(['uid1', 'uid2']); + + self::assertSame(['uids' => 'uid1,uid2'], $data->toArray()); + } + + public function testSetBeforeEnqueuedAt(): void + { + $date = new \DateTimeImmutable(); + $data = (new DeleteTasksQuery())->setBeforeEnqueuedAt($date); + + self::assertSame(['beforeEnqueuedAt' => $date->format(\DateTimeInterface::RFC3339)], $data->toArray()); + } + + public function testSetAfterEnqueuedAt(): void + { + $date = new \DateTimeImmutable(); + $data = (new DeleteTasksQuery())->setAfterEnqueuedAt($date); + + self::assertSame(['afterEnqueuedAt' => $date->format(\DateTimeInterface::RFC3339)], $data->toArray()); + } + + public function testSetBeforeStartedAt(): void + { + $date = new \DateTimeImmutable(); + $data = (new DeleteTasksQuery())->setBeforeStartedAt($date); + + self::assertSame(['beforeStartedAt' => $date->format(\DateTimeInterface::RFC3339)], $data->toArray()); + } + + public function testSetAfterStartedAt(): void + { + $date = new \DateTimeImmutable(); + $data = (new DeleteTasksQuery())->setAfterStartedAt($date); + + self::assertSame(['afterStartedAt' => $date->format(\DateTimeInterface::RFC3339)], $data->toArray()); + } + + public function testSetBeforeFinishedAt(): void { - $date = new \DateTime(); - $data = (new DeleteTasksQuery())->setCanceledBy([null])->setBeforeEnqueuedAt($date); + $date = new \DateTimeImmutable(); + $data = (new DeleteTasksQuery())->setBeforeFinishedAt($date); - self::assertSame(['beforeEnqueuedAt' => $date->format(\DateTime::RFC3339)], $data->toArray()); + self::assertSame(['beforeFinishedAt' => $date->format(\DateTimeInterface::RFC3339)], $data->toArray()); } - public function testToArrayWithDifferentSets(): void + public function testSetAfterFinishedAt(): void { - $data = (new DeleteTasksQuery())->setCanceledBy([1, 2])->setStatuses(['enqueued']); + $date = new \DateTimeImmutable(); + $data = (new DeleteTasksQuery())->setAfterFinishedAt($date); - self::assertSame(['statuses' => 'enqueued', 'canceledBy' => '1,2'], $data->toArray()); + self::assertSame(['afterFinishedAt' => $date->format(\DateTimeInterface::RFC3339)], $data->toArray()); } } diff --git a/tests/Contracts/DocumentsQueryTest.php b/tests/Contracts/DocumentsQueryTest.php index 465badd3..c78f364e 100644 --- a/tests/Contracts/DocumentsQueryTest.php +++ b/tests/Contracts/DocumentsQueryTest.php @@ -7,8 +7,15 @@ use Meilisearch\Contracts\DocumentsQuery; use PHPUnit\Framework\TestCase; -class DocumentsQueryTest extends TestCase +final class DocumentsQueryTest extends TestCase { + public function testEmptyQuery(): void + { + $data = new DocumentsQuery(); + + self::assertSame([], $data->toArray()); + } + public function testSetFields(): void { $data = (new DocumentsQuery())->setLimit(10)->setFields(['abc', 'xyz']); @@ -16,24 +23,17 @@ public function testSetFields(): void self::assertSame(['limit' => 10, 'fields' => 'abc,xyz'], $data->toArray()); } - public function testToArrayWithoutSetFields(): void + public function testSetLimit(): void { $data = (new DocumentsQuery())->setLimit(10); self::assertSame(['limit' => 10], $data->toArray()); } - public function testToArrayWithoutSetOffset(): void - { - $data = (new DocumentsQuery())->setOffset(10); - - self::assertSame(['offset' => 10], $data->toArray()); - } - - public function testToArrayWithZeros(): void + public function testSetOffset(): void { - $data = (new DocumentsQuery())->setLimit(0)->setOffset(0); + $data = (new DocumentsQuery())->setOffset(5); - self::assertSame(['offset' => 0, 'limit' => 0], $data->toArray()); + self::assertSame(['offset' => 5], $data->toArray()); } } diff --git a/tests/Contracts/FacetSearchQueryTest.php b/tests/Contracts/FacetSearchQueryTest.php new file mode 100644 index 00000000..86ba488f --- /dev/null +++ b/tests/Contracts/FacetSearchQueryTest.php @@ -0,0 +1,67 @@ +toArray()); + } + + public function testSetFacetName(): void + { + $data = (new FacetSearchQuery())->setFacetName('genres'); + + self::assertSame(['facetName' => 'genres'], $data->toArray()); + } + + public function testSetFacetQuery(): void + { + $data = (new FacetSearchQuery())->setFacetQuery('fiction'); + + self::assertSame(['facetQuery' => 'fiction'], $data->toArray()); + } + + public function testSetQ(): void + { + $data = (new FacetSearchQuery())->setQuery('a=b'); + + self::assertSame(['q' => 'a=b'], $data->toArray()); + } + + public function testSetFilter(): void + { + $data = (new FacetSearchQuery())->setFilter(['rating > 3']); + + self::assertSame(['filter' => ['rating > 3']], $data->toArray()); + } + + /** + * @param 'last'|'all'|'frequency' $strategy + * + * @testWith ["last"] + * ["all"] + * ["frequency"] + */ + public function testSetMatchingStrategy(string $strategy): void + { + $data = (new FacetSearchQuery())->setMatchingStrategy($strategy); + + self::assertSame(['matchingStrategy' => $strategy], $data->toArray()); + } + + public function testSetAttributesToSearchOn(): void + { + $data = (new FacetSearchQuery())->setAttributesToSearchOn(['overview']); + + self::assertSame(['attributesToSearchOn' => ['overview']], $data->toArray()); + } +} diff --git a/tests/Contracts/FederationOptionsTest.php b/tests/Contracts/FederationOptionsTest.php new file mode 100644 index 00000000..a10d23d3 --- /dev/null +++ b/tests/Contracts/FederationOptionsTest.php @@ -0,0 +1,25 @@ +toArray()); + } + + public function testSetWeight(): void + { + $data = (new FederationOptions())->setWeight(2.369); + + self::assertSame(['weight' => 2.369], $data->toArray()); + } +} diff --git a/tests/Contracts/HybridSearchOptionsTest.php b/tests/Contracts/HybridSearchOptionsTest.php new file mode 100644 index 00000000..8dad6d11 --- /dev/null +++ b/tests/Contracts/HybridSearchOptionsTest.php @@ -0,0 +1,32 @@ +toArray()); + } + + public function testSetSemanticRatio(): void + { + $data = (new HybridSearchOptions())->setSemanticRatio(0.5); + + self::assertSame(['semanticRatio' => 0.5], $data->toArray()); + } + + public function testSetEmbedder(): void + { + $data = (new HybridSearchOptions())->setEmbedder('default'); + + self::assertSame(['embedder' => 'default'], $data->toArray()); + } +} diff --git a/tests/Contracts/IndexesQueryTest.php b/tests/Contracts/IndexesQueryTest.php index d2112a2e..f96da284 100644 --- a/tests/Contracts/IndexesQueryTest.php +++ b/tests/Contracts/IndexesQueryTest.php @@ -7,33 +7,26 @@ use Meilisearch\Contracts\IndexesQuery; use PHPUnit\Framework\TestCase; -class IndexesQueryTest extends TestCase +final class IndexesQueryTest extends TestCase { - public function testToArrayWithSetOffsetAndSetLimit(): void + public function testEmptyQuery(): void { - $data = (new IndexesQuery())->setLimit(10)->setOffset(18); - - self::assertSame(['offset' => 18, 'limit' => 10], $data->toArray()); - } - - public function testToArrayWithSetOffset(): void - { - $data = (new IndexesQuery())->setOffset(5); + $data = new IndexesQuery(); - self::assertSame(['offset' => 5], $data->toArray()); + self::assertSame([], $data->toArray()); } - public function testToArrayWithoutSet(): void + public function testSetLimit(): void { - $data = new IndexesQuery(); + $data = (new IndexesQuery())->setLimit(10); - self::assertEmpty($data->toArray()); + self::assertSame(['limit' => 10], $data->toArray()); } - public function testToArrayWithZeros(): void + public function testSetOffset(): void { - $data = (new IndexesQuery())->setLimit(0)->setOffset(0); + $data = (new IndexesQuery())->setOffset(5); - self::assertSame(['offset' => 0, 'limit' => 0], $data->toArray()); + self::assertSame(['offset' => 5], $data->toArray()); } } diff --git a/tests/Contracts/KeysQueryTest.php b/tests/Contracts/KeysQueryTest.php index b23cc757..202a152a 100644 --- a/tests/Contracts/KeysQueryTest.php +++ b/tests/Contracts/KeysQueryTest.php @@ -7,33 +7,26 @@ use Meilisearch\Contracts\KeysQuery; use PHPUnit\Framework\TestCase; -class KeysQueryTest extends TestCase +final class KeysQueryTest extends TestCase { - public function testToArrayWithSetOffsetAndSetLimit(): void + public function testEmptyQuery(): void { - $data = (new KeysQuery())->setLimit(10)->setOffset(18); - - self::assertSame(['offset' => 18, 'limit' => 10], $data->toArray()); - } - - public function testToArrayWithSetOffset(): void - { - $data = (new KeysQuery())->setOffset(5); + $data = new KeysQuery(); - self::assertSame(['offset' => 5], $data->toArray()); + self::assertSame([], $data->toArray()); } - public function testToArrayWithoutSet(): void + public function testSetLimit(): void { - $data = new KeysQuery(); + $data = (new KeysQuery())->setLimit(10); - self::assertEmpty($data->toArray()); + self::assertSame(['limit' => 10], $data->toArray()); } - public function testToArrayWithZeros(): void + public function testSetOffset(): void { - $data = (new KeysQuery())->setLimit(0)->setOffset(0); + $data = (new KeysQuery())->setOffset(5); - self::assertSame(['offset' => 0, 'limit' => 0], $data->toArray()); + self::assertSame(['offset' => 5], $data->toArray()); } } diff --git a/tests/Contracts/MultiSearchFederationTest.php b/tests/Contracts/MultiSearchFederationTest.php new file mode 100644 index 00000000..191b3692 --- /dev/null +++ b/tests/Contracts/MultiSearchFederationTest.php @@ -0,0 +1,32 @@ +toArray()); + } + + public function testSetLimit(): void + { + $data = (new MultiSearchFederation())->setLimit(10); + + self::assertSame(['limit' => 10], $data->toArray()); + } + + public function testSetOffset(): void + { + $data = (new MultiSearchFederation())->setOffset(5); + + self::assertSame(['offset' => 5], $data->toArray()); + } +} diff --git a/tests/Contracts/SearchQueryTest.php b/tests/Contracts/SearchQueryTest.php new file mode 100644 index 00000000..992a0a8c --- /dev/null +++ b/tests/Contracts/SearchQueryTest.php @@ -0,0 +1,239 @@ +toArray()); + } + + public function testSetIndexUid(): void + { + $data = (new SearchQuery())->setIndexUid('movies'); + + self::assertSame(['indexUid' => 'movies'], $data->toArray()); + } + + public function testSetQuery(): void + { + $data = (new SearchQuery())->setQuery('shifu'); + + self::assertSame(['q' => 'shifu'], $data->toArray()); + } + + public function testSetFilter(): void + { + $data = (new SearchQuery())->setFilter(['rating > 3']); + + self::assertSame(['filter' => ['rating > 3']], $data->toArray()); + } + + public function testSetLocales(): void + { + $data = (new SearchQuery())->setLocales(['en', 'fr']); + + self::assertSame(['locales' => ['en', 'fr']], $data->toArray()); + } + + public function testSetAttributesToRetrieve(): void + { + $data = (new SearchQuery())->setAttributesToRetrieve(['overview', 'title']); + + self::assertSame(['attributesToRetrieve' => ['overview', 'title']], $data->toArray()); + } + + public function testSetAttributesToCrop(): void + { + $data = (new SearchQuery())->setAttributesToCrop(['attributeNameA:5', 'attributeNameB:9']); + + self::assertSame(['attributesToCrop' => ['attributeNameA:5', 'attributeNameB:9']], $data->toArray()); + } + + public function testSetCropLength(): void + { + $data = (new SearchQuery())->setCropLength(10); + + self::assertSame(['cropLength' => 10], $data->toArray()); + } + + public function testSetAttributesToHighlight(): void + { + $data = (new SearchQuery())->setAttributesToHighlight(['overview', 'title']); + + self::assertSame(['attributesToHighlight' => ['overview', 'title']], $data->toArray()); + } + + /** + * @testWith [""] + * ["[…]"] + */ + public function testSetCropMarker(string $marker): void + { + $data = (new SearchQuery())->setCropMarker($marker); + + self::assertSame(['cropMarker' => $marker], $data->toArray()); + } + + /** + * @testWith [""] + * ["*"] + * ["__"] + * [""] + * [""] + */ + public function testSetHighlightPreTag(string $tag): void + { + $data = (new SearchQuery())->setHighlightPreTag($tag); + + self::assertSame(['highlightPreTag' => $tag], $data->toArray()); + } + + /** + * @testWith [""] + * ["*"] + * ["__"] + * [""] + * [""] + */ + public function testSetHighlightPostTag(string $tag): void + { + $data = (new SearchQuery())->setHighlightPostTag($tag); + + self::assertSame(['highlightPostTag' => $tag], $data->toArray()); + } + + public function testSetFacets(): void + { + $data = (new SearchQuery())->setFacets(['attributeA', 'attributeB']); + + self::assertSame(['facets' => ['attributeA', 'attributeB']], $data->toArray()); + } + + /** + * @testWith [true] + * [false] + */ + public function testSetShowMatchesPosition(?bool $value): void + { + $data = (new SearchQuery())->setShowMatchesPosition($value); + + self::assertSame(['showMatchesPosition' => $value], $data->toArray()); + } + + public function testSetSort(): void + { + $data = (new SearchQuery())->setSort(['price:asc']); + + self::assertSame(['sort' => ['price:asc']], $data->toArray()); + } + + /** + * @param 'last'|'all'|'frequency' $strategy + * + * @testWith ["last"] + * ["all"] + * ["frequency"] + */ + public function testSetMatchingStrategy(string $strategy): void + { + $data = (new SearchQuery())->setMatchingStrategy($strategy); + + self::assertSame(['matchingStrategy' => $strategy], $data->toArray()); + } + + public function testSetLimit(): void + { + $data = (new SearchQuery())->setLimit(10); + + self::assertSame(['limit' => 10], $data->toArray()); + } + + public function testSetOffset(): void + { + $data = (new SearchQuery())->setOffset(5); + + self::assertSame(['offset' => 5], $data->toArray()); + } + + public function testSetHitsPerPage(): void + { + $data = (new SearchQuery())->setHitsPerPage(0); + + self::assertSame(['hitsPerPage' => 0], $data->toArray()); + } + + public function testSetPage(): void + { + $data = (new SearchQuery())->setPage(0); + + self::assertSame(['page' => 0], $data->toArray()); + } + + public function testSetHybrid(): void + { + $data = (new SearchQuery())->setHybrid((new HybridSearchOptions())->setSemanticRatio(0.5)); + + self::assertSame(['hybrid' => ['semanticRatio' => 0.5]], $data->toArray()); + } + + public function testSetAttributesToSearchOn(): void + { + $data = (new SearchQuery())->setAttributesToSearchOn(['overview']); + + self::assertSame(['attributesToSearchOn' => ['overview']], $data->toArray()); + } + + /** + * @testWith [true] + * [false] + */ + public function testSetShowRankingScore(?bool $value): void + { + $data = (new SearchQuery())->setShowRankingScore($value); + + self::assertSame(['showRankingScore' => $value], $data->toArray()); + } + + /** + * @testWith [true] + * [false] + */ + public function testSetShowRankingScoreDetails(?bool $value): void + { + $data = (new SearchQuery())->setShowRankingScoreDetails($value); + + self::assertSame(['showRankingScoreDetails' => $value], $data->toArray()); + } + + public function testSetRankingScoreThreshold(): void + { + $data = (new SearchQuery())->setRankingScoreThreshold(0.123); + + self::assertSame(['rankingScoreThreshold' => 0.123], $data->toArray()); + } + + public function testSetDistinct(): void + { + $data = (new SearchQuery())->setDistinct('genre'); + + self::assertSame(['distinct' => 'genre'], $data->toArray()); + } + + public function testSetFederationOptions(): void + { + $data = (new SearchQuery())->setFederationOptions((new FederationOptions())->setWeight(0.5)); + + self::assertSame(['federationOptions' => ['weight' => 0.5]], $data->toArray()); + } +} diff --git a/tests/Contracts/TasksQueryTest.php b/tests/Contracts/TasksQueryTest.php index 6fd13d89..73dc2f99 100644 --- a/tests/Contracts/TasksQueryTest.php +++ b/tests/Contracts/TasksQueryTest.php @@ -7,8 +7,15 @@ use Meilisearch\Contracts\TasksQuery; use PHPUnit\Framework\TestCase; -class TasksQueryTest extends TestCase +final class TasksQueryTest extends TestCase { + public function testEmptyQuery(): void + { + $data = new TasksQuery(); + + self::assertSame([], $data->toArray()); + } + public function testSetTypes(): void { $data = (new TasksQuery())->setTypes(['abc', 'xyz']); @@ -16,32 +23,90 @@ public function testSetTypes(): void self::assertSame(['types' => 'abc,xyz'], $data->toArray()); } - public function testSetAnyDateFilter(): void + public function testSetStatuses(): void + { + $data = (new TasksQuery())->setStatuses(['failed', 'canceled']); + + self::assertSame(['statuses' => 'failed,canceled'], $data->toArray()); + } + + public function testSetIndexUids(): void + { + $data = (new TasksQuery())->setIndexUids(['uid1', 'uid2']); + + self::assertSame(['indexUids' => 'uid1,uid2'], $data->toArray()); + } + + public function testSetUids(): void + { + $data = (new TasksQuery())->setUids(['uid1', 'uid2']); + + self::assertSame(['uids' => 'uid1,uid2'], $data->toArray()); + } + + public function testSetBeforeEnqueuedAt(): void { - $date = new \DateTime(); + $date = new \DateTimeImmutable(); $data = (new TasksQuery())->setBeforeEnqueuedAt($date); - self::assertSame(['beforeEnqueuedAt' => $date->format(\DateTime::RFC3339)], $data->toArray()); + self::assertSame(['beforeEnqueuedAt' => $date->format(\DateTimeInterface::RFC3339)], $data->toArray()); + } + + public function testSetAfterEnqueuedAt(): void + { + $date = new \DateTimeImmutable(); + $data = (new TasksQuery())->setAfterEnqueuedAt($date); + + self::assertSame(['afterEnqueuedAt' => $date->format(\DateTimeInterface::RFC3339)], $data->toArray()); + } + + public function testSetBeforeStartedAt(): void + { + $date = new \DateTimeImmutable(); + $data = (new TasksQuery())->setBeforeStartedAt($date); + + self::assertSame(['beforeStartedAt' => $date->format(\DateTimeInterface::RFC3339)], $data->toArray()); + } + + public function testSetAfterStartedAt(): void + { + $date = new \DateTimeImmutable(); + $data = (new TasksQuery())->setAfterStartedAt($date); + + self::assertSame(['afterStartedAt' => $date->format(\DateTimeInterface::RFC3339)], $data->toArray()); + } + + public function testSetBeforeFinishedAt(): void + { + $date = new \DateTimeImmutable(); + $data = (new TasksQuery())->setBeforeFinishedAt($date); + + self::assertSame(['beforeFinishedAt' => $date->format(\DateTimeInterface::RFC3339)], $data->toArray()); } - public function testToArrayWithSetLimit(): void + public function testSetAfterFinishedAt(): void { - $data = (new TasksQuery())->setLimit(10); + $date = new \DateTimeImmutable(); + $data = (new TasksQuery())->setAfterFinishedAt($date); - self::assertSame(['limit' => 10], $data->toArray()); + self::assertSame(['afterFinishedAt' => $date->format(\DateTimeInterface::RFC3339)], $data->toArray()); } - public function testToArrayWithSetLimitWithZero(): void + /** + * @testWith [0] + * [10] + */ + public function testSetLimit(int $limit): void { - $data = (new TasksQuery())->setLimit(0); + $data = (new TasksQuery())->setLimit($limit); - self::assertSame(['limit' => 0], $data->toArray()); + self::assertSame(['limit' => $limit], $data->toArray()); } - public function testToArrayWithDifferentSets(): void + public function testSetFrom(): void { - $data = (new TasksQuery())->setFrom(10)->setLimit(9)->setCanceledBy([1, 4])->setStatuses(['enqueued']); + $data = (new TasksQuery())->setFrom(1); - self::assertSame(['statuses' => 'enqueued', 'from' => 10, 'limit' => 9, 'canceledBy' => '1,4'], $data->toArray()); + self::assertSame(['from' => 1], $data->toArray()); } } diff --git a/tests/Endpoints/TasksTest.php b/tests/Endpoints/TasksTest.php index edd9e39d..c3bb6405 100644 --- a/tests/Endpoints/TasksTest.php +++ b/tests/Endpoints/TasksTest.php @@ -73,7 +73,7 @@ public function testGetAllTasksClientWithPagination(): void { $response = $this->client->getTasks((new TasksQuery())->setLimit(0)); - self::assertEmpty($response->getResults()); + self::assertSame([], $response->getResults()); } public function testGetOneTaskIndex(): void