|
7 | 7 | use Apify\Client\ApifyClient; |
8 | 8 | use Apify\Client\Internal\Json; |
9 | 9 | use Apify\Client\Model\RequestQueueRequest; |
| 10 | +use InvalidArgumentException; |
10 | 11 | use PHPUnit\Framework\TestCase; |
11 | 12 |
|
12 | 13 | /** |
@@ -47,14 +48,16 @@ public function testListAndLockHeadReturnsTypedResult(): void |
47 | 48 | 'queueHasLockedRequests' => true, |
48 | 49 | 'clientKey' => 'my-client-key', |
49 | 50 | 'items' => [ |
50 | | - ['id' => 'r1', 'uniqueKey' => 'r1', 'url' => 'https://a.com'], |
| 51 | + ['id' => 'r1', 'uniqueKey' => 'r1', 'url' => 'https://a.com', 'retryCount' => 2, 'lockExpiresAt' => '2026-08-01T00:01:00.000Z'], |
51 | 52 | ], |
52 | 53 | ]])); |
53 | 54 |
|
54 | 55 | $locked = $this->client($transport)->requestQueue('q1')->listAndLockHead(60, 5); |
55 | 56 |
|
56 | 57 | self::assertCount(1, $locked->getItems()); |
57 | 58 | self::assertSame('r1', $locked->getItems()[0]->getId()); |
| 59 | + self::assertSame(2, $locked->getItems()[0]->getRetryCount()); |
| 60 | + self::assertSame('2026-08-01T00:01:00.000Z', $locked->getItems()[0]->getLockExpiresAt()); |
58 | 61 | self::assertSame(60, $locked->getLockSecs()); |
59 | 62 | self::assertTrue($locked->queueHasLockedRequests()); |
60 | 63 | self::assertSame('my-client-key', $locked->getClientKey()); |
@@ -125,4 +128,33 @@ public function testBatchDeleteRequestsSendsIdentifiersAndReturnsTypedResult(): |
125 | 128 | $sentBody = Json::decode(MockTransport::readBody($transport->lastRequest())); |
126 | 129 | self::assertSame([['id' => 'r1'], ['id' => 'r2']], $sentBody); |
127 | 130 | } |
| 131 | + |
| 132 | + public function testBatchDeleteRequestsRejectsEmptyInputBeforeAnyCall(): void |
| 133 | + { |
| 134 | + $transport = new MockTransport(); |
| 135 | + |
| 136 | + $this->expectException(InvalidArgumentException::class); |
| 137 | + try { |
| 138 | + $this->client($transport)->requestQueue('q1')->batchDeleteRequests([]); |
| 139 | + } finally { |
| 140 | + self::assertSame(0, $transport->callCount()); |
| 141 | + } |
| 142 | + } |
| 143 | + |
| 144 | + public function testBatchDeleteRequestsRejectsOversizedInputBeforeAnyCall(): void |
| 145 | + { |
| 146 | + $transport = new MockTransport(); |
| 147 | + $requests = array_map( |
| 148 | + static fn (int $i) => (new RequestQueueRequest())->setId('r' . $i), |
| 149 | + range(0, 25) // 26 > the 25-per-call limit |
| 150 | + ); |
| 151 | + |
| 152 | + try { |
| 153 | + $this->client($transport)->requestQueue('q1')->batchDeleteRequests($requests); |
| 154 | + self::fail('expected InvalidArgumentException'); |
| 155 | + } catch (InvalidArgumentException $e) { |
| 156 | + self::assertStringContainsString('26', $e->getMessage()); |
| 157 | + } |
| 158 | + self::assertSame(0, $transport->callCount()); |
| 159 | + } |
128 | 160 | } |
0 commit comments