From 31109689908def2fe796ed9ec085fd118ec45c2a Mon Sep 17 00:00:00 2001 From: Strift Date: Wed, 4 Dec 2024 18:50:27 +0800 Subject: [PATCH 01/11] Add method to retrieve all batches --- src/Client.php | 4 + src/Contracts/BatchesResults.php | 94 ++++++++++++++++++++++ src/Endpoints/Batches.php | 24 ++++++ src/Endpoints/Delegates/HandlesBatches.php | 28 +++++++ tests/Endpoints/BatchesTest.php | 29 +++++++ 5 files changed, 179 insertions(+) create mode 100644 src/Contracts/BatchesResults.php create mode 100644 src/Endpoints/Batches.php create mode 100644 src/Endpoints/Delegates/HandlesBatches.php create mode 100644 tests/Endpoints/BatchesTest.php diff --git a/src/Client.php b/src/Client.php index 9eda1bcc..4247af6d 100644 --- a/src/Client.php +++ b/src/Client.php @@ -11,6 +11,7 @@ use Meilisearch\Endpoints\Delegates\HandlesSnapshots; use Meilisearch\Endpoints\Delegates\HandlesSystem; use Meilisearch\Endpoints\Delegates\HandlesTasks; +use Meilisearch\Endpoints\Delegates\HandlesBatches; use Meilisearch\Endpoints\Dumps; use Meilisearch\Endpoints\Health; use Meilisearch\Endpoints\Indexes; @@ -18,6 +19,7 @@ use Meilisearch\Endpoints\Snapshots; use Meilisearch\Endpoints\Stats; use Meilisearch\Endpoints\Tasks; +use Meilisearch\Endpoints\Batches; use Meilisearch\Endpoints\TenantToken; use Meilisearch\Endpoints\Version; use Meilisearch\Http\Client as MeilisearchClientAdapter; @@ -34,6 +36,7 @@ class Client use HandlesSnapshots; use HandlesSystem; use HandlesMultiSearch; + use HandlesBatches; /** * @param array $clientAgents @@ -52,6 +55,7 @@ public function __construct( $this->version = new Version($this->http); $this->stats = new Stats($this->http); $this->tasks = new Tasks($this->http); + $this->batches = new Batches($this->http); $this->keys = new Keys($this->http); $this->dumps = new Dumps($this->http); $this->snapshots = new Snapshots($this->http); diff --git a/src/Contracts/BatchesResults.php b/src/Contracts/BatchesResults.php new file mode 100644 index 00000000..5f4cabc2 --- /dev/null +++ b/src/Contracts/BatchesResults.php @@ -0,0 +1,94 @@ +from = $params['from'] ?? 0; + $this->limit = $params['limit'] ?? 0; + $this->next = $params['next'] ?? 0; + $this->total = $params['total'] ?? 0; + } + + /** + * @return array + */ + 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; + } + + public function toArray(): array + { + return [ + 'results' => $this->data, + 'next' => $this->next, + 'limit' => $this->limit, + 'from' => $this->from, + 'total' => $this->total, + ]; + } + + public function count(): int + { + return \count($this->data); + } +} diff --git a/src/Endpoints/Batches.php b/src/Endpoints/Batches.php new file mode 100644 index 00000000..2a9f3bd5 --- /dev/null +++ b/src/Endpoints/Batches.php @@ -0,0 +1,24 @@ +http->get(self::PATH . '/' . $batchUid); + } + + public function all(array $query = []): array + { + return $this->http->get(self::PATH . '/', $query); + } +} diff --git a/src/Endpoints/Delegates/HandlesBatches.php b/src/Endpoints/Delegates/HandlesBatches.php new file mode 100644 index 00000000..4323aaf9 --- /dev/null +++ b/src/Endpoints/Delegates/HandlesBatches.php @@ -0,0 +1,28 @@ +batches->get($uid); + } + + public function getBatches(?BatchesQuery $options = null): BatchesResults + { + $query = isset($options) ? $options->toArray() : []; + + $response = $this->batches->all($query); + + return new BatchesResults($response); + } +} diff --git a/tests/Endpoints/BatchesTest.php b/tests/Endpoints/BatchesTest.php new file mode 100644 index 00000000..8fa89588 --- /dev/null +++ b/tests/Endpoints/BatchesTest.php @@ -0,0 +1,29 @@ +indexName = $this->safeIndexName(); + $this->index = $this->createEmptyIndex($this->indexName); + } + + public function testGetAllBatches(): void + { + $response = $this->client->getBatches(); + self::assertIsArray($response->getResults()); + } +} From 3783e043233c4e972917f6737d575f62d843210a Mon Sep 17 00:00:00 2001 From: Strift Date: Wed, 4 Dec 2024 19:13:30 +0800 Subject: [PATCH 02/11] Add tests for fetching batches --- src/Contracts/BatchesQuery.php | 88 +++++++++++++++++++++++++++++++++ tests/Endpoints/BatchesTest.php | 35 ++++++++++++- 2 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 src/Contracts/BatchesQuery.php diff --git a/src/Contracts/BatchesQuery.php b/src/Contracts/BatchesQuery.php new file mode 100644 index 00000000..0c688d5d --- /dev/null +++ b/src/Contracts/BatchesQuery.php @@ -0,0 +1,88 @@ +|null + */ + private ?array $canceledBy = null; + + /** + * @var bool|null + */ + private ?bool $reverse = null; + + /** + * @return $this + */ + public function setFrom(int $from): self + { + $this->from = $from; + + return $this; + } + + /** + * @param non-empty-list $canceledBy + * + * @return $this + */ + public function setCanceledBy(array $canceledBy): self + { + $this->canceledBy = $canceledBy; + + return $this; + } + + /** + * @return $this + */ + public function setLimit(int $limit): self + { + $this->limit = $limit; + + return $this; + } + + /** + * @return $this + */ + public function setReverse(bool $reverse): self + { + $this->reverse = $reverse; + + return $this; + } + + public function toArray(): array + { + return array_filter( + array_merge( + $this->baseArray(), + [ + 'from' => $this->from, + 'limit' => $this->limit, + 'reverse' => (null !== $this->reverse ? ($this->reverse ? 'true' : 'false') : null), + ] + ), + static function ($item) { + return null !== $item; + } + ); + } +} diff --git a/tests/Endpoints/BatchesTest.php b/tests/Endpoints/BatchesTest.php index 8fa89588..62d81aef 100644 --- a/tests/Endpoints/BatchesTest.php +++ b/tests/Endpoints/BatchesTest.php @@ -4,21 +4,23 @@ namespace Tests\Endpoints; +use Meilisearch\Contracts\TasksQuery; use Meilisearch\Contracts\BatchesQuery; use Meilisearch\Endpoints\Indexes; use Meilisearch\Exceptions\ApiException; use Tests\TestCase; +use function PHPUnit\Framework\assertNotNull; + final class BatchesTest extends TestCase { - private Indexes $index; private string $indexName; protected function setUp(): void { parent::setUp(); $this->indexName = $this->safeIndexName(); - $this->index = $this->createEmptyIndex($this->indexName); + $this->createEmptyIndex($this->indexName); } public function testGetAllBatches(): void @@ -26,4 +28,33 @@ public function testGetAllBatches(): void $response = $this->client->getBatches(); self::assertIsArray($response->getResults()); } + + public function testGetAllBatchesWithIndexUidFilters(): void + { + $response = $this->client->getBatches((new BatchesQuery())->setIndexUids([$this->indexName])); + foreach ($response->getResults() as $result) { + self::assertArrayHasKey($this->indexName, $result['stats']['indexUids']); + } + } + + public function testGetAllBatchesWithTasksFilters(): void + { + $tasks = $this->client->getTasks(new TasksQuery())->getResults(); + $response = $this->client->getBatches((new BatchesQuery())->setUids([$tasks[0]['uid']])); + self::assertNotNull($response->getResults()); + } + + public function testGetAllBatchesInReverseOrder(): void + { + $startDate = new \DateTimeImmutable('now'); + + $batches = $this->client->getBatches((new BatchesQuery()) + ->setAfterEnqueuedAt($startDate) + ); + $reversedBatches = $this->client->getBatches((new BatchesQuery()) + ->setAfterEnqueuedAt($startDate) + ->setReverse(true) + ); + self::assertEquals($batches->getResults(), array_reverse($reversedBatches->getResults())); + } } From 02c8e8168a1ceb9488200a12f08d451bba40ca65 Mon Sep 17 00:00:00 2001 From: Strift Date: Wed, 4 Dec 2024 19:30:03 +0800 Subject: [PATCH 03/11] Add tests for getBatch() --- tests/Endpoints/BatchesTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/Endpoints/BatchesTest.php b/tests/Endpoints/BatchesTest.php index 62d81aef..51b60dd0 100644 --- a/tests/Endpoints/BatchesTest.php +++ b/tests/Endpoints/BatchesTest.php @@ -57,4 +57,20 @@ public function testGetAllBatchesInReverseOrder(): void ); self::assertEquals($batches->getResults(), array_reverse($reversedBatches->getResults())); } + + public function testGetOneBatch(): void + { + $batches = $this->client->getBatches(); + $response = $this->client->getBatch($batches->getResults()[0]['uid']); + + self::assertEquals($batches->getResults()[0]['uid'], $response['uid']); + self::assertArrayHasKey('details', $response); + self::assertArrayHasKey('totalNbTasks', $response['stats']); + self::assertArrayHasKey('status', $response['stats']); + self::assertArrayHasKey('types', $response['stats']); + self::assertArrayHasKey('indexUids', $response['stats']); + self::assertArrayHasKey('duration', $response); + self::assertArrayHasKey('startedAt', $response); + self::assertArrayHasKey('finishedAt', $response); + } } From f1ca12179ec227b6f0f5a331b7316736d4c6f853 Mon Sep 17 00:00:00 2001 From: Strift Date: Wed, 4 Dec 2024 19:32:54 +0800 Subject: [PATCH 04/11] Run lint:fix --- src/Client.php | 4 +- src/Contracts/BatchesQuery.php | 151 ++++++++++----------- src/Contracts/BatchesResults.php | 146 ++++++++++---------- src/Endpoints/Batches.php | 20 ++- src/Endpoints/Delegates/HandlesBatches.php | 22 +-- tests/Endpoints/BatchesTest.php | 106 +++++++-------- 6 files changed, 220 insertions(+), 229 deletions(-) diff --git a/src/Client.php b/src/Client.php index 4247af6d..51271314 100644 --- a/src/Client.php +++ b/src/Client.php @@ -4,6 +4,8 @@ namespace Meilisearch; +use Meilisearch\Endpoints\Batches; +use Meilisearch\Endpoints\Delegates\HandlesBatches; use Meilisearch\Endpoints\Delegates\HandlesDumps; use Meilisearch\Endpoints\Delegates\HandlesIndex; use Meilisearch\Endpoints\Delegates\HandlesKeys; @@ -11,7 +13,6 @@ use Meilisearch\Endpoints\Delegates\HandlesSnapshots; use Meilisearch\Endpoints\Delegates\HandlesSystem; use Meilisearch\Endpoints\Delegates\HandlesTasks; -use Meilisearch\Endpoints\Delegates\HandlesBatches; use Meilisearch\Endpoints\Dumps; use Meilisearch\Endpoints\Health; use Meilisearch\Endpoints\Indexes; @@ -19,7 +20,6 @@ use Meilisearch\Endpoints\Snapshots; use Meilisearch\Endpoints\Stats; use Meilisearch\Endpoints\Tasks; -use Meilisearch\Endpoints\Batches; use Meilisearch\Endpoints\TenantToken; use Meilisearch\Endpoints\Version; use Meilisearch\Http\Client as MeilisearchClientAdapter; diff --git a/src/Contracts/BatchesQuery.php b/src/Contracts/BatchesQuery.php index 0c688d5d..9f119c61 100644 --- a/src/Contracts/BatchesQuery.php +++ b/src/Contracts/BatchesQuery.php @@ -8,81 +8,78 @@ class BatchesQuery { - use TasksQueryTrait; - - private ?int $from = null; - - /** - * @var non-negative-int|null - */ - private ?int $limit = null; - - /** - * @var non-empty-list|null - */ - private ?array $canceledBy = null; - - /** - * @var bool|null - */ - private ?bool $reverse = null; - - /** - * @return $this - */ - public function setFrom(int $from): self - { - $this->from = $from; - - return $this; - } - - /** - * @param non-empty-list $canceledBy - * - * @return $this - */ - public function setCanceledBy(array $canceledBy): self - { - $this->canceledBy = $canceledBy; - - return $this; - } - - /** - * @return $this - */ - public function setLimit(int $limit): self - { - $this->limit = $limit; - - return $this; - } - - /** - * @return $this - */ - public function setReverse(bool $reverse): self - { - $this->reverse = $reverse; - - return $this; - } - - public function toArray(): array - { - return array_filter( - array_merge( - $this->baseArray(), - [ - 'from' => $this->from, - 'limit' => $this->limit, - 'reverse' => (null !== $this->reverse ? ($this->reverse ? 'true' : 'false') : null), - ] - ), - static function ($item) { - return null !== $item; - } - ); - } + use TasksQueryTrait; + + private ?int $from = null; + + /** + * @var non-negative-int|null + */ + private ?int $limit = null; + + /** + * @var non-empty-list|null + */ + private ?array $canceledBy = null; + + private ?bool $reverse = null; + + /** + * @return $this + */ + public function setFrom(int $from): self + { + $this->from = $from; + + return $this; + } + + /** + * @param non-empty-list $canceledBy + * + * @return $this + */ + public function setCanceledBy(array $canceledBy): self + { + $this->canceledBy = $canceledBy; + + return $this; + } + + /** + * @return $this + */ + public function setLimit(int $limit): self + { + $this->limit = $limit; + + return $this; + } + + /** + * @return $this + */ + public function setReverse(bool $reverse): self + { + $this->reverse = $reverse; + + return $this; + } + + public function toArray(): array + { + return array_filter( + array_merge( + $this->baseArray(), + [ + 'from' => $this->from, + 'limit' => $this->limit, + 'reverse' => (null !== $this->reverse ? ($this->reverse ? 'true' : 'false') : null), + ] + ), + static function ($item) { + return null !== $item; + } + ); + } } diff --git a/src/Contracts/BatchesResults.php b/src/Contracts/BatchesResults.php index 5f4cabc2..38fc4d40 100644 --- a/src/Contracts/BatchesResults.php +++ b/src/Contracts/BatchesResults.php @@ -6,89 +6,89 @@ class BatchesResults extends Data { - /** - * @var non-negative-int - */ - private int $next; + /** + * @var non-negative-int + */ + private int $next; - /** - * @var non-negative-int - */ - private int $limit; + /** + * @var non-negative-int + */ + private int $limit; - /** - * @var non-negative-int - */ - private int $from; + /** + * @var non-negative-int + */ + private int $from; - /** - * @var non-negative-int - */ - private int $total; + /** + * @var non-negative-int + */ + private int $total; - public function __construct(array $params) - { - parent::__construct($params['results'] ?? []); + public function __construct(array $params) + { + parent::__construct($params['results'] ?? []); - $this->from = $params['from'] ?? 0; - $this->limit = $params['limit'] ?? 0; - $this->next = $params['next'] ?? 0; - $this->total = $params['total'] ?? 0; - } + $this->from = $params['from'] ?? 0; + $this->limit = $params['limit'] ?? 0; + $this->next = $params['next'] ?? 0; + $this->total = $params['total'] ?? 0; + } - /** - * @return array - */ - public function getResults(): array - { - return $this->data; - } + /** + * @return array + */ + public function getResults(): array + { + return $this->data; + } - /** - * @return non-negative-int - */ - public function getNext(): int - { - return $this->next; - } + /** + * @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 getLimit(): int + { + return $this->limit; + } - /** - * @return non-negative-int - */ - public function getFrom(): int - { - return $this->from; - } + /** + * @return non-negative-int + */ + public function getFrom(): int + { + return $this->from; + } - /** - * @return non-negative-int - */ - public function getTotal(): int - { - return $this->total; - } + /** + * @return non-negative-int + */ + public function getTotal(): int + { + return $this->total; + } - public function toArray(): array - { - return [ - 'results' => $this->data, - 'next' => $this->next, - 'limit' => $this->limit, - 'from' => $this->from, - 'total' => $this->total, - ]; - } + public function toArray(): array + { + return [ + 'results' => $this->data, + 'next' => $this->next, + 'limit' => $this->limit, + 'from' => $this->from, + 'total' => $this->total, + ]; + } - public function count(): int - { - return \count($this->data); - } + public function count(): int + { + return \count($this->data); + } } diff --git a/src/Endpoints/Batches.php b/src/Endpoints/Batches.php index 2a9f3bd5..1a00b475 100644 --- a/src/Endpoints/Batches.php +++ b/src/Endpoints/Batches.php @@ -8,17 +8,15 @@ class Batches extends Endpoint { - protected const PATH = '/batches'; + protected const PATH = '/batches'; + public function get($batchUid): array + { + return $this->http->get(self::PATH.'/'.$batchUid); + } - - public function get($batchUid): array - { - return $this->http->get(self::PATH . '/' . $batchUid); - } - - public function all(array $query = []): array - { - return $this->http->get(self::PATH . '/', $query); - } + public function all(array $query = []): array + { + return $this->http->get(self::PATH.'/', $query); + } } diff --git a/src/Endpoints/Delegates/HandlesBatches.php b/src/Endpoints/Delegates/HandlesBatches.php index 4323aaf9..2e4bf112 100644 --- a/src/Endpoints/Delegates/HandlesBatches.php +++ b/src/Endpoints/Delegates/HandlesBatches.php @@ -10,19 +10,19 @@ trait HandlesBatches { - protected Batches $batches; + protected Batches $batches; - public function getBatch($uid): array - { - return $this->batches->get($uid); - } + public function getBatch($uid): array + { + return $this->batches->get($uid); + } - public function getBatches(?BatchesQuery $options = null): BatchesResults - { - $query = isset($options) ? $options->toArray() : []; + public function getBatches(?BatchesQuery $options = null): BatchesResults + { + $query = isset($options) ? $options->toArray() : []; - $response = $this->batches->all($query); + $response = $this->batches->all($query); - return new BatchesResults($response); - } + return new BatchesResults($response); + } } diff --git a/tests/Endpoints/BatchesTest.php b/tests/Endpoints/BatchesTest.php index 51b60dd0..d673436f 100644 --- a/tests/Endpoints/BatchesTest.php +++ b/tests/Endpoints/BatchesTest.php @@ -4,73 +4,69 @@ namespace Tests\Endpoints; -use Meilisearch\Contracts\TasksQuery; use Meilisearch\Contracts\BatchesQuery; -use Meilisearch\Endpoints\Indexes; -use Meilisearch\Exceptions\ApiException; +use Meilisearch\Contracts\TasksQuery; use Tests\TestCase; -use function PHPUnit\Framework\assertNotNull; - final class BatchesTest extends TestCase { - private string $indexName; + private string $indexName; - protected function setUp(): void - { - parent::setUp(); - $this->indexName = $this->safeIndexName(); - $this->createEmptyIndex($this->indexName); - } + protected function setUp(): void + { + parent::setUp(); + $this->indexName = $this->safeIndexName(); + $this->createEmptyIndex($this->indexName); + } - public function testGetAllBatches(): void - { - $response = $this->client->getBatches(); - self::assertIsArray($response->getResults()); - } + public function testGetAllBatches(): void + { + $response = $this->client->getBatches(); + self::assertIsArray($response->getResults()); + } - public function testGetAllBatchesWithIndexUidFilters(): void - { - $response = $this->client->getBatches((new BatchesQuery())->setIndexUids([$this->indexName])); - foreach ($response->getResults() as $result) { - self::assertArrayHasKey($this->indexName, $result['stats']['indexUids']); + public function testGetAllBatchesWithIndexUidFilters(): void + { + $response = $this->client->getBatches((new BatchesQuery())->setIndexUids([$this->indexName])); + foreach ($response->getResults() as $result) { + self::assertArrayHasKey($this->indexName, $result['stats']['indexUids']); + } } - } - public function testGetAllBatchesWithTasksFilters(): void - { - $tasks = $this->client->getTasks(new TasksQuery())->getResults(); - $response = $this->client->getBatches((new BatchesQuery())->setUids([$tasks[0]['uid']])); - self::assertNotNull($response->getResults()); - } + public function testGetAllBatchesWithTasksFilters(): void + { + $tasks = $this->client->getTasks(new TasksQuery())->getResults(); + $response = $this->client->getBatches((new BatchesQuery())->setUids([$tasks[0]['uid']])); + self::assertNotNull($response->getResults()); + } - public function testGetAllBatchesInReverseOrder(): void - { - $startDate = new \DateTimeImmutable('now'); + public function testGetAllBatchesInReverseOrder(): void + { + $startDate = new \DateTimeImmutable('now'); - $batches = $this->client->getBatches((new BatchesQuery()) - ->setAfterEnqueuedAt($startDate) - ); - $reversedBatches = $this->client->getBatches((new BatchesQuery()) - ->setAfterEnqueuedAt($startDate) - ->setReverse(true) - ); - self::assertEquals($batches->getResults(), array_reverse($reversedBatches->getResults())); - } + $batches = $this->client->getBatches((new BatchesQuery()) + ->setAfterEnqueuedAt($startDate) + ); + $reversedBatches = $this->client->getBatches((new BatchesQuery()) + ->setAfterEnqueuedAt($startDate) + ->setReverse(true) + ); + self::assertSame($batches->getResults(), array_reverse($reversedBatches->getResults())); + } - public function testGetOneBatch(): void - { - $batches = $this->client->getBatches(); - $response = $this->client->getBatch($batches->getResults()[0]['uid']); + public function testGetOneBatch(): void + { + $batches = $this->client->getBatches(); + $response = $this->client->getBatch($batches->getResults()[0]['uid']); - self::assertEquals($batches->getResults()[0]['uid'], $response['uid']); - self::assertArrayHasKey('details', $response); - self::assertArrayHasKey('totalNbTasks', $response['stats']); - self::assertArrayHasKey('status', $response['stats']); - self::assertArrayHasKey('types', $response['stats']); - self::assertArrayHasKey('indexUids', $response['stats']); - self::assertArrayHasKey('duration', $response); - self::assertArrayHasKey('startedAt', $response); - self::assertArrayHasKey('finishedAt', $response); - } + self::assertSame($batches->getResults()[0]['uid'], $response['uid']); + self::assertArrayHasKey('details', $response); + self::assertArrayHasKey('totalNbTasks', $response['stats']); + self::assertArrayHasKey('status', $response['stats']); + self::assertArrayHasKey('types', $response['stats']); + self::assertArrayHasKey('indexUids', $response['stats']); + self::assertArrayHasKey('duration', $response); + self::assertArrayHasKey('startedAt', $response); + self::assertArrayHasKey('finishedAt', $response); + } } From 6504e83b63dcb01f093b3a3ef8395da37043ff5f Mon Sep 17 00:00:00 2001 From: Strift Date: Wed, 4 Dec 2024 19:38:45 +0800 Subject: [PATCH 05/11] Add filtering by batchUid for getTasks --- src/Contracts/TasksQuery.php | 22 +++++++++++++++++++++- tests/Endpoints/TasksTest.php | 16 +++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/Contracts/TasksQuery.php b/src/Contracts/TasksQuery.php index 174fdffe..235bf6d2 100644 --- a/src/Contracts/TasksQuery.php +++ b/src/Contracts/TasksQuery.php @@ -22,6 +22,12 @@ class TasksQuery */ private ?array $canceledBy = null; + + /** + * @var int|null + */ + private ?int $batchUid = null; + /** * @return $this */ @@ -54,6 +60,16 @@ public function setLimit(int $limit): self return $this; } + /** + * @return $this + */ + public function setBatchUid(int $batchUid): self + { + $this->batchUid = $batchUid; + + return $this; + } + public function toArray(): array { return array_filter( @@ -63,8 +79,12 @@ public function toArray(): array 'from' => $this->from, 'limit' => $this->limit, 'canceledBy' => $this->formatArray($this->canceledBy), + 'batchUid' => $this->batchUid, ] - ), static function ($item) { return null !== $item; } + ), + static function ($item) { + return null !== $item; + } ); } } diff --git a/tests/Endpoints/TasksTest.php b/tests/Endpoints/TasksTest.php index c3bb6405..5d5fe4f5 100644 --- a/tests/Endpoints/TasksTest.php +++ b/tests/Endpoints/TasksTest.php @@ -126,6 +126,20 @@ public function testGetAllTasksByIndexWithFilter(): void self::assertGreaterThan(0, $response->getTotal()); } + public function getAllTasksByBatchFilter(): void + { + [$promise, $response] = $this->seedIndex(); + + self::assertIsArray($promise); + $task = $this->client->getTask($promise['taskUid']); + + $response = $this->client->getTasks((new TasksQuery()) + ->setBatchUid($task['uid']) + ); + + self::assertIsArray($response->getResults()); + } + public function testCancelTasksWithFilter(): void { $date = new \DateTime('yesterday'); @@ -135,7 +149,7 @@ public function testCancelTasksWithFilter(): void self::assertSame('taskCancelation', $promise['type']); $response = $this->client->waitForTask($promise['taskUid']); - self::assertSame('?'.$query, $response['details']['originalFilter']); + self::assertSame('?' . $query, $response['details']['originalFilter']); self::assertSame('taskCancelation', $response['type']); self::assertSame('succeeded', $response['status']); } From 0ab176413c51256e592eada33065fa76d57a2683 Mon Sep 17 00:00:00 2001 From: Strift Date: Wed, 4 Dec 2024 19:40:19 +0800 Subject: [PATCH 06/11] Rename test --- tests/Endpoints/TasksTest.php | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/tests/Endpoints/TasksTest.php b/tests/Endpoints/TasksTest.php index 5d5fe4f5..d8595c4a 100644 --- a/tests/Endpoints/TasksTest.php +++ b/tests/Endpoints/TasksTest.php @@ -76,6 +76,18 @@ public function testGetAllTasksClientWithPagination(): void self::assertSame([], $response->getResults()); } + public function getAllTasksClientWithBatchFilter(): void + { + [$promise, $response] = $this->seedIndex(); + $task = $this->client->getTask($promise['taskUid']); + + $response = $this->client->getTasks((new TasksQuery()) + ->setBatchUid($task['uid']) + ); + + self::assertIsArray($response->getResults()); + } + public function testGetOneTaskIndex(): void { [$promise, $response] = $this->seedIndex(); @@ -126,20 +138,6 @@ public function testGetAllTasksByIndexWithFilter(): void self::assertGreaterThan(0, $response->getTotal()); } - public function getAllTasksByBatchFilter(): void - { - [$promise, $response] = $this->seedIndex(); - - self::assertIsArray($promise); - $task = $this->client->getTask($promise['taskUid']); - - $response = $this->client->getTasks((new TasksQuery()) - ->setBatchUid($task['uid']) - ); - - self::assertIsArray($response->getResults()); - } - public function testCancelTasksWithFilter(): void { $date = new \DateTime('yesterday'); From 2e409e36dbda649525bd9cf56e19e147a8b8b130 Mon Sep 17 00:00:00 2001 From: Strift Date: Wed, 4 Dec 2024 19:40:37 +0800 Subject: [PATCH 07/11] Run lint:fix --- src/Contracts/TasksQuery.php | 4 ---- tests/Endpoints/TasksTest.php | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Contracts/TasksQuery.php b/src/Contracts/TasksQuery.php index 235bf6d2..16cc353c 100644 --- a/src/Contracts/TasksQuery.php +++ b/src/Contracts/TasksQuery.php @@ -22,10 +22,6 @@ class TasksQuery */ private ?array $canceledBy = null; - - /** - * @var int|null - */ private ?int $batchUid = null; /** diff --git a/tests/Endpoints/TasksTest.php b/tests/Endpoints/TasksTest.php index d8595c4a..d41cd5f8 100644 --- a/tests/Endpoints/TasksTest.php +++ b/tests/Endpoints/TasksTest.php @@ -147,7 +147,7 @@ public function testCancelTasksWithFilter(): void self::assertSame('taskCancelation', $promise['type']); $response = $this->client->waitForTask($promise['taskUid']); - self::assertSame('?' . $query, $response['details']['originalFilter']); + self::assertSame('?'.$query, $response['details']['originalFilter']); self::assertSame('taskCancelation', $response['type']); self::assertSame('succeeded', $response['status']); } From aab82edda30acabc2ba7e977d08cd40e92ba1ff6 Mon Sep 17 00:00:00 2001 From: Strift Date: Wed, 4 Dec 2024 19:48:33 +0800 Subject: [PATCH 08/11] Update tests based on PHPstan feedback --- src/Contracts/BatchesQuery.php | 17 ----------------- tests/Endpoints/BatchesTest.php | 10 +++++----- tests/Endpoints/TasksTest.php | 2 +- 3 files changed, 6 insertions(+), 23 deletions(-) diff --git a/src/Contracts/BatchesQuery.php b/src/Contracts/BatchesQuery.php index 9f119c61..08fd36b3 100644 --- a/src/Contracts/BatchesQuery.php +++ b/src/Contracts/BatchesQuery.php @@ -17,11 +17,6 @@ class BatchesQuery */ private ?int $limit = null; - /** - * @var non-empty-list|null - */ - private ?array $canceledBy = null; - private ?bool $reverse = null; /** @@ -34,18 +29,6 @@ public function setFrom(int $from): self return $this; } - /** - * @param non-empty-list $canceledBy - * - * @return $this - */ - public function setCanceledBy(array $canceledBy): self - { - $this->canceledBy = $canceledBy; - - return $this; - } - /** * @return $this */ diff --git a/tests/Endpoints/BatchesTest.php b/tests/Endpoints/BatchesTest.php index d673436f..fc6d0780 100644 --- a/tests/Endpoints/BatchesTest.php +++ b/tests/Endpoints/BatchesTest.php @@ -22,7 +22,7 @@ protected function setUp(): void public function testGetAllBatches(): void { $response = $this->client->getBatches(); - self::assertIsArray($response->getResults()); + self::assertGreaterThan(0, $response->getTotal()); } public function testGetAllBatchesWithIndexUidFilters(): void @@ -37,7 +37,7 @@ public function testGetAllBatchesWithTasksFilters(): void { $tasks = $this->client->getTasks(new TasksQuery())->getResults(); $response = $this->client->getBatches((new BatchesQuery())->setUids([$tasks[0]['uid']])); - self::assertNotNull($response->getResults()); + self::assertGreaterThan(0, $response->getTotal()); } public function testGetAllBatchesInReverseOrder(): void @@ -45,11 +45,11 @@ public function testGetAllBatchesInReverseOrder(): void $startDate = new \DateTimeImmutable('now'); $batches = $this->client->getBatches((new BatchesQuery()) - ->setAfterEnqueuedAt($startDate) + ->setAfterEnqueuedAt($startDate) ); $reversedBatches = $this->client->getBatches((new BatchesQuery()) - ->setAfterEnqueuedAt($startDate) - ->setReverse(true) + ->setAfterEnqueuedAt($startDate) + ->setReverse(true) ); self::assertSame($batches->getResults(), array_reverse($reversedBatches->getResults())); } diff --git a/tests/Endpoints/TasksTest.php b/tests/Endpoints/TasksTest.php index d41cd5f8..61cc3c67 100644 --- a/tests/Endpoints/TasksTest.php +++ b/tests/Endpoints/TasksTest.php @@ -85,7 +85,7 @@ public function getAllTasksClientWithBatchFilter(): void ->setBatchUid($task['uid']) ); - self::assertIsArray($response->getResults()); + self::assertGreaterThan(0, $response->getTotal()); } public function testGetOneTaskIndex(): void From 1cd2719d3413efb4c029d338a49fc00b5bf38cd8 Mon Sep 17 00:00:00 2001 From: Laurent Cazanove Date: Thu, 5 Dec 2024 08:04:58 +0100 Subject: [PATCH 09/11] Update src/Endpoints/Delegates/HandlesBatches.php MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tomas Norkūnas --- src/Endpoints/Delegates/HandlesBatches.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Endpoints/Delegates/HandlesBatches.php b/src/Endpoints/Delegates/HandlesBatches.php index 2e4bf112..5c53bc9d 100644 --- a/src/Endpoints/Delegates/HandlesBatches.php +++ b/src/Endpoints/Delegates/HandlesBatches.php @@ -19,7 +19,7 @@ public function getBatch($uid): array public function getBatches(?BatchesQuery $options = null): BatchesResults { - $query = isset($options) ? $options->toArray() : []; + $query = null !== $options ? $options->toArray() : []; $response = $this->batches->all($query); From 94ed6046d7f53e3b06b009639305b29c7a5c650b Mon Sep 17 00:00:00 2001 From: Strift Date: Thu, 5 Dec 2024 16:20:59 +0800 Subject: [PATCH 10/11] Remove missing results check --- src/Contracts/BatchesResults.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Contracts/BatchesResults.php b/src/Contracts/BatchesResults.php index 38fc4d40..7a9e7dbc 100644 --- a/src/Contracts/BatchesResults.php +++ b/src/Contracts/BatchesResults.php @@ -28,7 +28,7 @@ class BatchesResults extends Data public function __construct(array $params) { - parent::__construct($params['results'] ?? []); + parent::__construct($params['results']); $this->from = $params['from'] ?? 0; $this->limit = $params['limit'] ?? 0; From 1e46daef8617b78321c902add7d279c0b332cbce Mon Sep 17 00:00:00 2001 From: Strift Date: Thu, 5 Dec 2024 16:38:57 +0800 Subject: [PATCH 11/11] Run lint:fix --- src/Contracts/TasksQuery.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Contracts/TasksQuery.php b/src/Contracts/TasksQuery.php index c109de3a..6022e70d 100644 --- a/src/Contracts/TasksQuery.php +++ b/src/Contracts/TasksQuery.php @@ -22,14 +22,8 @@ class TasksQuery */ private ?array $canceledBy = null; - /** - * @var int|null - */ private ?int $batchUid = null; - /** - * @var bool|null - */ private ?bool $reverse = null; /**