diff --git a/src/Models/PaginatedResult.php b/src/Models/PaginatedResult.php index 7faf731..7ec7c06 100644 --- a/src/Models/PaginatedResult.php +++ b/src/Models/PaginatedResult.php @@ -35,7 +35,8 @@ class PaginatedResult { * @param array $headers Headers to be sent with the request * @throws AblyException */ - public function __construct( \Ably\AblyRest $ably, $model, $cipherParams, $method, $path, $params = [], $headers = [] ) { + public function __construct( \Ably\AblyRest $ably, $model, $cipherParams, + $method, $path, $params = [], $headers = [] ) { $this->ably = $ably; $this->model = $model; $this->cipherParams = $cipherParams; @@ -140,7 +141,6 @@ public function isPaginated() { * Parses HTTP headers for pagination links */ private function parsePaginationHeaders($headers) { - $path = preg_replace('/\/[^\/]*$/', '/', $this->path); preg_match_all('/Link: *\<([^\>]*)\>; *rel="([^"]*)"/i', $headers, $matches, PREG_SET_ORDER); @@ -148,7 +148,6 @@ private function parsePaginationHeaders($headers) { if (!$matches) return; $this->paginationHeaders = []; - foreach ($matches as $m) { $link = $m[1]; $rel = $m[2]; @@ -157,7 +156,10 @@ private function parsePaginationHeaders($headers) { throw new AblyException( "Server error - only relative URLs are supported in pagination" ); } - $this->paginationHeaders[$rel] = $path.substr($link, 2); + $link = explode('/', $link); + $link = $path . end($link); + + $this->paginationHeaders[$rel] = $link; } } } diff --git a/tests/AblyRestTest.php b/tests/AblyRestTest.php index 79c6bfa..1aca39d 100644 --- a/tests/AblyRestTest.php +++ b/tests/AblyRestTest.php @@ -398,13 +398,13 @@ public function testHttpTimeout() { $ablyTimeout = new AblyRest( [ 'key' => 'fake.key:veryFake', - 'httpRequestTimeout' => 50, // 50 ms + 'httpRequestTimeout' => 20, // 20 ms ]); $ably->http->get('https://cdn.ably.io/lib/ably.js'); // should work $this->expectException(AblyRequestException::class); $this->expectExceptionCode(50003); - $ablyTimeout->http->get('https://cdn.ably.io/lib/ably.js'); // guaranteed to take more than 50 ms + $ablyTimeout->http->get('https://cdn.ably.io/lib/ably.js'); // guaranteed to take more than 20 ms } } diff --git a/tests/PushDeviceRegistrationsTest.php b/tests/PushDeviceRegistrationsTest.php index 3f2f2ec..38e0782 100644 --- a/tests/PushDeviceRegistrationsTest.php +++ b/tests/PushDeviceRegistrationsTest.php @@ -87,6 +87,12 @@ public function testList() { $response = self::$ably->push->admin->deviceRegistrations->list_([ 'limit' => 2 ]); $this->assertEquals(count($response->items), 2); + // pagination + $response = self::$ably->push->admin->deviceRegistrations->list_([ 'limit' => 1 ]); + $this->assertEquals(count($response->items), 1); + $response = $response->next(); + $this->assertEquals(count($response->items), 1); + // Filter by device id $first = $datas[0]; $response = self::$ably->push->admin->deviceRegistrations->list_([ 'deviceId' => $first['id'] ]);