From 74f757bc4caae6561a478ffd6b930b28ca1c528c Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 27 Nov 2026 18:41:46 +0000 Subject: [PATCH 1/2] fix: iterate Store search as one page, long timeout for Actor version uploads, deprecate Store sortBy --- CHANGELOG.md | 8 ++++++++ docs/actors.md | 3 ++- docs/misc.md | 4 ++-- docs/options.md | 10 +++++----- src/Options/StoreListOptions.php | 15 +++++++++----- src/Resource/ActorVersionClient.php | 5 +++-- src/Resource/ActorVersionCollectionClient.php | 5 +++-- src/Resource/StoreCollectionClient.php | 16 +++++++++++++++ src/Version.php | 2 +- tests/Integration/StoreIntegrationTest.php | 20 +++++++++++++++++++ tests/Unit/IterationTest.php | 17 ++++++++++++++++ tests/Unit/MethodTierTest.php | 3 ++- 12 files changed, 89 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e219910..0e2bfee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## 0.14.2 + +- Synced with the Apify OpenAPI spec `v2-2026-11-18T151559Z`, as updated: Store Actors have the new `stats` and `isVerified` fields, the run origin `APIFY_AI` exists, and some response fields can be `null`. The models return them as received. +- `StoreListOptions::$sortBy` is deprecated, as the API ignores it. +- `store()->iterate()` with `search` makes one request, as the API returns a single page of at most 100 Actors and ignores `offset`. It used to repeat that page. +- `versions()->create()` and `version()->update()` use the `long` timeout tier by default, since a version can carry its source files. +- Documented the Store `category` filter and the `search` page limit. + ## 0.14.1 - Synced with Apify OpenAPI spec `v2-2026-11-18T151559Z`: `UserClient::get()` returns only `plan.availableProxyGroups`, `effectivePlatformFeatures` and `isPaying` for a proxy password. diff --git a/docs/actors.md b/docs/actors.md index 13df8bc..93182a2 100644 --- a/docs/actors.md +++ b/docs/actors.md @@ -118,7 +118,8 @@ $response = $server->request('/search', new ActorServerRequestOptions( - Single: `get(): ?ActorVersion`, `update(mixed $newFields): ActorVersion`, `delete(): void`. The endpoint returns all versions in one response, so `list()` and `iterate()` take no options and `iterate()` -makes one request. +makes one request. `create()` and `update()` use the `long` timeout tier by default, since a version can carry its +source files. ```php $version = $client->actor('me~my-actor')->versions()->create([ diff --git a/docs/misc.md b/docs/misc.md index e6fd46e..040d3e5 100644 --- a/docs/misc.md +++ b/docs/misc.md @@ -5,14 +5,14 @@ Snippets assume `$client = new ApifyClient('my-api-token');` and imported types. ## Apify Store — `$client->store()` - `list(?StoreListOptions $options = null): PaginationList`: one page of Store Actors. -- `iterate(?StoreListOptions $options = null, ?int $chunkSize = null): iterable`: lazily yields the matching Actors. The `limit` option caps the total (unset for all), `$chunkSize` is the page size. +- `iterate(?StoreListOptions $options = null, ?int $chunkSize = null): iterable`: lazily yields the matching Actors. The `limit` option caps the total (unset for all), `$chunkSize` is the page size. With `search`, the API returns one page of at most 100 Actors and ignores `offset`, so `iterate()` makes one request and ignores `$chunkSize`. ```php $page = $client->store()->list(new StoreListOptions(search: 'scraper', limit: 10)); $shown = 0; // 50 is the page size. The limit option would cap the total. -foreach ($client->store()->iterate(new StoreListOptions(search: 'scraper'), 50) as $item) { +foreach ($client->store()->iterate(new StoreListOptions(category: 'AI_AND_ML'), 50) as $item) { echo $item->getName() . PHP_EOL; if (++$shown >= 5) { break; diff --git a/docs/options.md b/docs/options.md index 2e0ceb2..e2dac3b 100644 --- a/docs/options.md +++ b/docs/options.md @@ -80,11 +80,11 @@ Extra filters for `runs()->list()`, combined with a `ListOptions`. For `store()->list()` / `store()->iterate()`. | Field | Type | Description | |---|---|---| -| `offset` | `?int` | Number of Actors to skip. | -| `limit` | `?int` | Maximum number of Actors to return. When iterating, caps the total across all pages (the per-page size is `iterate()`'s separate `$chunkSize` argument). | -| `search` | `?string` | Full-text search query. | -| `sortBy` | `?string` | The sort field (e.g. `popularity`, `newest`). | -| `category` | `?string` | Filter Actors by category. | +| `offset` | `?int` | Number of Actors to skip. The API ignores it with `search`. | +| `limit` | `?int` | Maximum number of Actors to return. When iterating, caps the total across all pages (the per-page size is `iterate()`'s separate `$chunkSize` argument). With `search`, the API returns at most 100. | +| `search` | `?string` | Full-text search query. The API ranks the results by relevance and returns one page of at most 100 Actors. | +| `sortBy` | `?string` | Deprecated: the API accepts it and ignores it. Sort the results on the client instead. | +| `category` | `?string` | Filter Actors by one or more comma-separated category IDs, such as `AI_AND_ML`. An Actor must match all of them. | | `username` | `?string` | Filter Actors by owner username. | | `pricingModel` | `?string` | Filter by pricing model (`FREE`, `PRICE_PER_DATASET_ITEM`, `PAY_PER_EVENT`). | | `includeUnrunnableActors` | `?bool` | Include Actors the current user cannot run. | diff --git a/src/Options/StoreListOptions.php b/src/Options/StoreListOptions.php index 830c250..0a01159 100644 --- a/src/Options/StoreListOptions.php +++ b/src/Options/StoreListOptions.php @@ -10,18 +10,23 @@ final class StoreListOptions { public function __construct( - /** Number of Actors to skip. */ + /** Number of Actors to skip. The API ignores it with {@code search}. */ public readonly ?int $offset = null, /** * The maximum number of Actors. When iterating, it caps the total over all pages, not the page size - * ({@code chunkSize}). + * ({@code chunkSize}). With {@code search}, the API returns at most 100. */ public readonly ?int $limit = null, - /** Full-text search query. */ + /** Full-text search query. The API ranks the results by relevance and returns one page of at most 100 Actors. */ public readonly ?string $search = null, - /** The sort field (e.g. {@code "popularity"}, {@code "newest"}). */ + /** + * Deprecated: the API accepts it and ignores it. Results are ordered by relevance with {@code search} and by + * Store position otherwise, so sort them on the client. + * + * @deprecated + */ public readonly ?string $sortBy = null, - /** Filter Actors by category. */ + /** Filter Actors by one or more comma-separated category IDs, such as {@code AI_AND_ML}. An Actor must match all of them. */ public readonly ?string $category = null, /** Filter Actors by owner username. */ public readonly ?string $username = null, diff --git a/src/Resource/ActorVersionClient.php b/src/Resource/ActorVersionClient.php index 7d28960..927875d 100644 --- a/src/Resource/ActorVersionClient.php +++ b/src/Resource/ActorVersionClient.php @@ -31,13 +31,14 @@ public function get(int|float|string|null $timeoutSecs = null): ?ActorVersion } /** - * Updates the version and returns it. + * Updates the version and returns it. The default timeout is the {@code long} tier, since the version can + * carry its source files. * * @param mixed $newFields any JSON-serializable fields */ public function update(mixed $newFields, int|float|string|null $timeoutSecs = null): ActorVersion { - return new ActorVersion($this->ctx->updateResource('', $newFields, $this->ctx->resolveTimeout($timeoutSecs, TimeoutTiers::TIER_SHORT))); + return new ActorVersion($this->ctx->updateResource('', $newFields, $this->ctx->resolveTimeout($timeoutSecs, TimeoutTiers::TIER_LONG))); } /** Deletes the version. */ diff --git a/src/Resource/ActorVersionCollectionClient.php b/src/Resource/ActorVersionCollectionClient.php index 3e35c79..8486a9a 100644 --- a/src/Resource/ActorVersionCollectionClient.php +++ b/src/Resource/ActorVersionCollectionClient.php @@ -46,12 +46,13 @@ public function iterate(int|float|string|null $timeoutSecs = null): Generator } /** - * Creates a version of the Actor. + * Creates a version of the Actor. The default timeout is the {@code long} tier, since the version can carry + * its source files. * * @param mixed $version any JSON-serializable version definition */ public function create(mixed $version, int|float|string|null $timeoutSecs = null): ActorVersion { - return new ActorVersion($this->ctx->createResource(new QueryParams(), $version, $this->ctx->resolveTimeout($timeoutSecs, TimeoutTiers::TIER_SHORT))); + return new ActorVersion($this->ctx->createResource(new QueryParams(), $version, $this->ctx->resolveTimeout($timeoutSecs, TimeoutTiers::TIER_LONG))); } } diff --git a/src/Resource/StoreCollectionClient.php b/src/Resource/StoreCollectionClient.php index 64f9c15..973f0d1 100644 --- a/src/Resource/StoreCollectionClient.php +++ b/src/Resource/StoreCollectionClient.php @@ -40,11 +40,17 @@ public function list(?StoreListOptions $options = null, int|float|string|null $t * Lazily yields Store Actors matching the options. The {@code limit} option caps the total ({@code null} for all) and * {@code $chunkSize} sets the page size ({@code null} for the API's default). * + * With {@code search}, the API ignores {@code offset} and returns one page of at most 100 Actors, so this makes + * one request with the {@code limit} option and ignores {@code $chunkSize}. + * * @return Generator */ public function iterate(?StoreListOptions $options = null, ?int $chunkSize = null, int|float|string|null $timeoutSecs = null): Generator { $options ??= new StoreListOptions(); + if ($options->search !== null && $options->search !== '') { + return $this->iterateSearchPage($options, $timeoutSecs); + } return ResourceContext::paginateOffset( $options->offset ?? 0, $options->limit, @@ -52,4 +58,14 @@ public function iterate(?StoreListOptions $options = null, ?int $chunkSize = nul fn (int $offset, ?int $pageLimit) => $this->list($options->withPagination($offset, $pageLimit), $timeoutSecs), ); } + + /** + * Yields the single page of a search, which the API cannot continue with an offset. + * + * @return Generator + */ + private function iterateSearchPage(StoreListOptions $options, int|float|string|null $timeoutSecs): Generator + { + yield from $this->list($options->withPagination(null, $options->limit), $timeoutSecs)->getItems(); + } } diff --git a/src/Version.php b/src/Version.php index 24c1aab..4c870b7 100644 --- a/src/Version.php +++ b/src/Version.php @@ -17,7 +17,7 @@ final class Version * The semantic version of this client library (see https://semver.org/). * Changes to the public interface other than additive ones are considered breaking changes. */ - public const CLIENT_VERSION = '0.14.1'; + public const CLIENT_VERSION = '0.14.2'; /** * The version of the Apify OpenAPI specification this client was generated and verified diff --git a/tests/Integration/StoreIntegrationTest.php b/tests/Integration/StoreIntegrationTest.php index 5bfd455..107fd96 100644 --- a/tests/Integration/StoreIntegrationTest.php +++ b/tests/Integration/StoreIntegrationTest.php @@ -31,6 +31,26 @@ public function testListStoreWithInputSchema(): void self::assertNotEmpty($schemas, 'at least one Store Actor carries its input schema'); } + public function testListStoreAcceptsTheDeprecatedSortBy(): void + { + $client = $this->requireClient(); + // The API accepts `sortBy` and ignores it, so the order is not asserted. + $page = $client->store()->list(new StoreListOptions(limit: 10, sortBy: 'popularity')); + self::assertNotEmpty($page->getItems()); + } + + public function testIterateStoreSearchReturnsOnePage(): void + { + $client = $this->requireClient(); + $ids = []; + foreach ($client->store()->iterate(new StoreListOptions(search: 'website content crawler', limit: 20), 5) as $item) { + $ids[] = $item->getId(); + } + self::assertNotEmpty($ids); + self::assertLessThanOrEqual(20, count($ids)); + self::assertSame($ids, array_unique($ids), 'a search must not repeat its page'); + } + public function testIterateStore(): void { $client = $this->requireClient(); diff --git a/tests/Unit/IterationTest.php b/tests/Unit/IterationTest.php index c532da9..1828533 100644 --- a/tests/Unit/IterationTest.php +++ b/tests/Unit/IterationTest.php @@ -172,6 +172,23 @@ public function testStorePageCountIsCappedAtTheRequestedLimit(): void self::assertStringContainsString('offset=2', (string) $transport->received[1]->getUri()); } + public function testStoreSearchIsASinglePageThatIgnoresTheOffset(): void + { + // With `search` the API ignores the offset, so a second request would repeat the first page forever. + $transport = (new MockTransport()) + ->queueResponse(200, self::pageWithCount(self::actors(1, 2), 2, 0)); + $ids = []; + foreach ($this->client($transport)->store()->iterate(new StoreListOptions(search: 'scraper', limit: 50, offset: 7), 1) as $item) { + $ids[] = $item->getId(); + } + self::assertSame(['a1', 'a2'], $ids); + self::assertSame(1, $transport->callCount()); + $uri = (string) $transport->received[0]->getUri(); + self::assertStringContainsString('search=scraper', $uri); + self::assertStringContainsString('limit=50', $uri); + self::assertStringNotContainsString('offset=', $uri); + } + public function testLimitCapStopsBeforeExhaustingPages(): void { // limit=2 with a big first page: only 2 items are yielded and no second request is made. diff --git a/tests/Unit/MethodTierTest.php b/tests/Unit/MethodTierTest.php index 0cff93b..f9313f1 100644 --- a/tests/Unit/MethodTierTest.php +++ b/tests/Unit/MethodTierTest.php @@ -29,7 +29,8 @@ public static function tierCases(): iterable yield 'Actor env var list' => [static fn (ApifyClient $c) => $c->actor('a')->version('0.1')->envVars()->list(), self::SHORT, self::PAGE_BODY]; yield 'Actor env var create' => [static fn (ApifyClient $c) => $c->actor('a')->version('0.1')->envVars()->create(new ActorEnvVar('N', 'v')), self::SHORT, self::ITEM_BODY]; yield 'Actor version list' => [static fn (ApifyClient $c) => $c->actor('a')->versions()->list(), self::SHORT, self::PAGE_BODY]; - yield 'Actor version create' => [static fn (ApifyClient $c) => $c->actor('a')->versions()->create(['versionNumber' => '0.1']), self::SHORT, self::ITEM_BODY]; + yield 'Actor version create' => [static fn (ApifyClient $c) => $c->actor('a')->versions()->create(['versionNumber' => '0.1']), self::LONG, self::ITEM_BODY]; + yield 'Actor version update' => [static fn (ApifyClient $c) => $c->actor('a')->version('0.1')->update(['buildTag' => 'latest']), self::LONG, self::ITEM_BODY]; yield 'Dataset getOrCreate' => [static fn (ApifyClient $c) => $c->datasets()->getOrCreate('d'), self::SHORT, self::ITEM_BODY]; yield 'Key-value store getOrCreate' => [static fn (ApifyClient $c) => $c->keyValueStores()->getOrCreate('s'), self::SHORT, self::ITEM_BODY]; yield 'Request queue getOrCreate' => [static fn (ApifyClient $c) => $c->requestQueues()->getOrCreate('q'), self::SHORT, self::ITEM_BODY]; From 5f1748e1fe113b3a4afc60143f26bacaaa0aeb26 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 27 Nov 2026 18:56:56 +0000 Subject: [PATCH 2/2] fix: address review of Store search docs, deprecation tag, PHPStan level 9, user by ID test --- CHANGELOG.md | 2 +- composer.json | 2 +- docs/options.md | 6 +++--- phpstan.neon.dist | 4 +--- src/Options/ActorServerRequestOptions.php | 5 ++++- src/Options/StoreListOptions.php | 6 +++--- tests/Integration/ActorRunIntegrationTest.php | 2 ++ tests/Integration/DatasetIntegrationTest.php | 5 ++++- tests/Integration/UserIntegrationTest.php | 10 ++++++++++ .../ZstdCompressionIntegrationTest.php | 4 +++- tests/Unit/HttpClientTest.php | 4 +++- tests/Unit/IterationTest.php | 3 +++ tests/Unit/RunIterateDatasetItemsTest.php | 1 + tests/Unit/SpecSyncTest.php | 4 +++- tests/Unit/UrlNormalizerTest.php | 16 ++++++++++------ 15 files changed, 52 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e2bfee..46ddf46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,11 +2,11 @@ ## 0.14.2 -- Synced with the Apify OpenAPI spec `v2-2026-11-18T151559Z`, as updated: Store Actors have the new `stats` and `isVerified` fields, the run origin `APIFY_AI` exists, and some response fields can be `null`. The models return them as received. - `StoreListOptions::$sortBy` is deprecated, as the API ignores it. - `store()->iterate()` with `search` makes one request, as the API returns a single page of at most 100 Actors and ignores `offset`. It used to repeat that page. - `versions()->create()` and `version()->update()` use the `long` timeout tier by default, since a version can carry its source files. - Documented the Store `category` filter and the `search` page limit. +- Raised PHPStan to level 9 and added an integration test for `user($id)->get()`. ## 0.14.1 diff --git a/composer.json b/composer.json index 21e2893..f43a68c 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "apify/apify-client", - "description": "Official, experimental (AI-generated and AI-maintained) Apify API client for PHP: run Actors, manage storages (datasets, key-value stores, request queues), schedules, webhooks and more.", + "description": "Apify API client for PHP: run Actors, manage storages (datasets, key-value stores, request queues), schedules, webhooks and more.", "type": "library", "keywords": [ "apify", diff --git a/docs/options.md b/docs/options.md index e2dac3b..36117c9 100644 --- a/docs/options.md +++ b/docs/options.md @@ -17,11 +17,11 @@ The offset-based options classes — `ListOptions`, `ActorListOptions`, `Storage It returns a copy of the options with the given `offset` and `limit`, preserving every other field. The `iterate()` helpers use it internally to request successive pages, but you can also call it to -page manually through `list()` results — most useful for the Apify Store, whose collection is -otherwise only pageable via `iterate()`: +page manually through `list()` results, for example the Apify Store. A Store `search` is one page that ignores +`offset`, so page by a filter such as `category`: ```php -$options = new StoreListOptions(search: 'scraper'); +$options = new StoreListOptions(category: 'AI_AND_ML'); for ($offset = 0; ; $offset += 100) { $page = $client->store()->list($options->withPagination($offset, 100)); foreach ($page->getItems() as $item) { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 21a6f5b..42888f2 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,7 +1,5 @@ -# Level 8 checks types, nullable access, and union types. Level 9 adds strict `mixed` handling. The client exposes -# `mixed` on purpose at the API boundary (JSON input, record values, `toArray()`), so it stays at level 8. parameters: - level: 8 + level: 9 paths: - src - tests diff --git a/src/Options/ActorServerRequestOptions.php b/src/Options/ActorServerRequestOptions.php index 62835f8..f54b212 100644 --- a/src/Options/ActorServerRequestOptions.php +++ b/src/Options/ActorServerRequestOptions.php @@ -86,7 +86,10 @@ public function appendTo(QueryParams $q): void } } - /** @param list $values */ + /** + * @param list $values + * @phpstan-assert-if-true list $values + */ private static function isScalarList(array $values): bool { foreach ($values as $value) { diff --git a/src/Options/StoreListOptions.php b/src/Options/StoreListOptions.php index 0a01159..13665f6 100644 --- a/src/Options/StoreListOptions.php +++ b/src/Options/StoreListOptions.php @@ -20,10 +20,10 @@ public function __construct( /** Full-text search query. The API ranks the results by relevance and returns one page of at most 100 Actors. */ public readonly ?string $search = null, /** - * Deprecated: the API accepts it and ignores it. Results are ordered by relevance with {@code search} and by - * Store position otherwise, so sort them on the client. + * The sort field. * - * @deprecated + * @deprecated The API ignores it. Results are ordered by relevance with {@code search} and by Store position + * otherwise, so sort them on the client. */ public readonly ?string $sortBy = null, /** Filter Actors by one or more comma-separated category IDs, such as {@code AI_AND_ML}. An Actor must match all of them. */ diff --git a/tests/Integration/ActorRunIntegrationTest.php b/tests/Integration/ActorRunIntegrationTest.php index 98f84bf..52a178a 100644 --- a/tests/Integration/ActorRunIntegrationTest.php +++ b/tests/Integration/ActorRunIntegrationTest.php @@ -139,6 +139,7 @@ public function testIterateDatasetItemsReadsItemsWhileTheRunIsStillRunning(): vo $statusWhenReceived = []; $items = []; foreach ($runClient->iterateDatasetItems(new RunIterateDatasetItemsOptions(pollIntervalSecs: 1)) as $item) { + /** @var array $item */ $items[] = $item['n']; $statusWhenReceived[] = $runClient->get()?->getStatus(); } @@ -223,6 +224,7 @@ public function testMetamorphWithTheRunsOwnTokenTransformsTheRunKeepingItsId(): */ private function createBuiltActor(ApifyClient $client, string $label, string $mainJs): string { + /** @var array{versions: list>}>} $definition */ $definition = self::minimalActor(self::uniqueName($label)); $definition['versions'][0]['sourceFiles'][1]['content'] = $mainJs; $actorId = (string) $client->actors()->create($definition)->getId(); diff --git a/tests/Integration/DatasetIntegrationTest.php b/tests/Integration/DatasetIntegrationTest.php index 1c3bdb6..35db547 100644 --- a/tests/Integration/DatasetIntegrationTest.php +++ b/tests/Integration/DatasetIntegrationTest.php @@ -70,6 +70,7 @@ public function testIterateDatasetItems(): void $values = []; // chunkSize=2 across 5 items => three pages (2, 2, 1). foreach ($dataset->iterateItems(new DatasetListItemsOptions(), 2) as $item) { + /** @var array $item */ $values[] = $item['n']; } sort($values); @@ -140,7 +141,9 @@ public function testDatasetCrudFlow(): void $page = $dataset->listItems(new DatasetListItemsOptions()); self::assertSame(3, $page->getCount()); self::assertCount(3, $page->getItems()); - self::assertSame(1, $page->getItems()[0]['n']); + /** @var array $first */ + $first = $page->getItems()[0]; + self::assertSame(1, $first['n']); // isDesc() is sourced from the server's X-Apify-Pagination-Desc response header. self::assertFalse($page->isDesc()); diff --git a/tests/Integration/UserIntegrationTest.php b/tests/Integration/UserIntegrationTest.php index fd6d5e4..d0d0b12 100644 --- a/tests/Integration/UserIntegrationTest.php +++ b/tests/Integration/UserIntegrationTest.php @@ -15,6 +15,16 @@ public function testGetOwnAccount(): void self::assertNotSame('', $user->getId()); } + public function testGetAccountById(): void + { + $client = $this->requireClient(); + $id = $client->me()->get()?->getId(); + self::assertNotNull($id); + $user = $client->user($id)->get(); + self::assertNotNull($user); + self::assertSame($id, $user->getId()); + } + public function testGetMonthlyUsage(): void { $client = $this->requireClient(); diff --git a/tests/Integration/ZstdCompressionIntegrationTest.php b/tests/Integration/ZstdCompressionIntegrationTest.php index 3cc40f4..d6c36bc 100644 --- a/tests/Integration/ZstdCompressionIntegrationTest.php +++ b/tests/Integration/ZstdCompressionIntegrationTest.php @@ -64,7 +64,9 @@ public function testDatasetItemsAreStoredFromAZstdBody(): void self::waitForDatasetItemCount($items, 2); $stored = $items->listItems()->getItems(); self::assertSame([1, 2], array_column($stored, 'n')); - self::assertSame($padding, $stored[0]['padding']); + /** @var array $firstStored */ + $firstStored = $stored[0]; + self::assertSame($padding, $firstStored['padding']); self::assertContains('zstd', $this->recorder->encodings); } finally { $client->dataset((string) $dataset->getId())->delete(); diff --git a/tests/Unit/HttpClientTest.php b/tests/Unit/HttpClientTest.php index 7a9968c..2e999b6 100644 --- a/tests/Unit/HttpClientTest.php +++ b/tests/Unit/HttpClientTest.php @@ -256,7 +256,9 @@ public function testDatasetItemsUseHeaderPagination(): void self::assertSame(42, $page->getTotal()); self::assertSame(3, $page->getCount()); - self::assertSame(1, $page->getItems()[0]['n']); + /** @var array $first */ + $first = $page->getItems()[0]; + self::assertSame(1, $first['n']); self::assertFalse($page->isDesc()); } diff --git a/tests/Unit/IterationTest.php b/tests/Unit/IterationTest.php index 1828533..f6f6c65 100644 --- a/tests/Unit/IterationTest.php +++ b/tests/Unit/IterationTest.php @@ -225,6 +225,7 @@ public function testDatasetIterateItemsPagesViaHeaders(): void ]); $values = []; foreach ($this->client($transport)->dataset('ds')->iterateItems(null, 2) as $item) { + /** @var array $item */ $values[] = $item['n']; } self::assertSame([1, 2, 3], $values); @@ -261,6 +262,7 @@ public function testDatasetIterateItemsAdvancesByScannedCountNotItemCount(): voi ]); $values = []; foreach ($this->client($transport)->dataset('ds')->iterateItems(new DatasetListItemsOptions(skipEmpty: true), 3) as $item) { + /** @var array $item */ $values[] = $item['n']; } self::assertSame([0, 1, 3, 4, 5], $values); @@ -296,6 +298,7 @@ public function testDatasetIterateItemsCapsScannedCountWhenUnwindInflatesItemsPa ]); $values = []; foreach ($this->client($transport)->dataset('ds')->iterateItems(new DatasetListItemsOptions(unwind: ['parts']), 2) as $item) { + /** @var array $item */ $values[] = $item['n']; } self::assertSame(range(0, 11), $values); diff --git a/tests/Unit/RunIterateDatasetItemsTest.php b/tests/Unit/RunIterateDatasetItemsTest.php index 4b42774..f6c8b79 100644 --- a/tests/Unit/RunIterateDatasetItemsTest.php +++ b/tests/Unit/RunIterateDatasetItemsTest.php @@ -61,6 +61,7 @@ private static function ids(iterable $items): array { $ids = []; foreach ($items as $item) { + /** @var array{id: int} $item */ $ids[] = $item['id']; } return $ids; diff --git a/tests/Unit/SpecSyncTest.php b/tests/Unit/SpecSyncTest.php index 8f33308..6d1a067 100644 --- a/tests/Unit/SpecSyncTest.php +++ b/tests/Unit/SpecSyncTest.php @@ -157,7 +157,9 @@ public function testUserFetchedWithAProxyPasswordHasNoIdOrUsername(): void self::assertNotNull($user); self::assertNull($user->getId()); self::assertNull($user->getUsername()); - self::assertSame(200, $user->toArray()['plan']['availableProxyGroups']['GOOGLE_SERP']); + /** @var array{plan: array{availableProxyGroups: array}} $fields */ + $fields = $user->toArray(); + self::assertSame(200, $fields['plan']['availableProxyGroups']['GOOGLE_SERP']); self::assertTrue($user->get('isPaying')); } diff --git a/tests/Unit/UrlNormalizerTest.php b/tests/Unit/UrlNormalizerTest.php index af3b436..b2fe32e 100644 --- a/tests/Unit/UrlNormalizerTest.php +++ b/tests/Unit/UrlNormalizerTest.php @@ -123,6 +123,7 @@ public function testNormalizeFieldsFollowsPathsAndWildcards(): void 'notAString' => 5, ]; + /** @var array{a: string, nested: array, map: array, notAString: int} $normalized */ $normalized = UrlNormalizer::normalizeFields($data, ['a', 'nested.b', 'map.*', 'notAString', 'missing.key']); self::assertSame('https://example.com/', $normalized['a']); @@ -141,7 +142,9 @@ public function testModelsNormalizeTheirUrlFields(): void ]); self::assertSame('https://abc.runs.apify.net/', $run->getContainerUrl()); self::assertSame('https://abc.runs.apify.net/', $run->get('containerUrl')); - self::assertSame('https://api.apify.com/v2/datasets/d1/items', $run->toArray()['output']['results']); + /** @var array{output: array{results: string}} $runFields */ + $runFields = $run->toArray(); + self::assertSame('https://api.apify.com/v2/datasets/d1/items', $runFields['output']['results']); self::assertSame('https://x.example/', (new Dataset(['itemsPublicUrl' => 'https://X.example']))->get('itemsPublicUrl')); self::assertSame('https://x.example/', (new KeyValueStore(['keysPublicUrl' => 'https://X.example']))->get('keysPublicUrl')); @@ -149,11 +152,12 @@ public function testModelsNormalizeTheirUrlFields(): void self::assertSame('https://x.example/', (new KeyValueStoreKey(['recordPublicUrl' => 'https://X.example']))->get('recordPublicUrl')); self::assertSame('https://x.example/', (new Task(['standbyUrl' => 'https://X.example']))->get('standbyUrl')); self::assertSame('https://x.example/hook', (new Webhook(['requestUrl' => 'https://X.example:443/hook']))->getRequestUrl()); - self::assertSame( - 'https://x.example/hook', - (new WebhookDispatch(['webhook' => ['requestUrl' => 'https://X.example/hook']]))->toArray()['webhook']['requestUrl'], - ); + /** @var array{webhook: array{requestUrl: string}} $dispatchFields */ + $dispatchFields = (new WebhookDispatch(['webhook' => ['requestUrl' => 'https://X.example/hook']]))->toArray(); + self::assertSame('https://x.example/hook', $dispatchFields['webhook']['requestUrl']); $user = new User(['profile' => ['pictureUrl' => 'https://X.example', 'websiteUrl' => 'https://Y.example', 'name' => 'Not A URL']]); - self::assertSame(['https://x.example/', 'https://y.example/', 'Not A URL'], array_values($user->toArray()['profile'])); + /** @var array{profile: array} $userFields */ + $userFields = $user->toArray(); + self::assertSame(['https://x.example/', 'https://y.example/', 'Not A URL'], array_values($userFields['profile'])); } }