Skip to content

Commit 4c7d10a

Browse files
committed
Add public $results property to CollectionAdapter
1 parent dfbc0dd commit 4c7d10a

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

tests/CollectionTest.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,14 @@ final class CollectionAdapter implements Adapter
265265
{
266266
private $_request;
267267

268+
public $results = [
269+
['id' => '0', 'key' => 0],
270+
['id' => '1', 'key' => 1],
271+
['id' => '2', 'key' => 2],
272+
['id' => '3', 'key' => 3],
273+
['id' => '4', 'key' => 4],
274+
];
275+
268276
public function start(Request $request)
269277
{
270278
$this->_request = $request;
@@ -293,14 +301,6 @@ public function end($handle)
293301
}
294302

295303
if (substr_count($this->_request->getUrl(), '/basic') === 1) {
296-
$results = [
297-
['id' => '0', 'key' => 0],
298-
['id' => '1', 'key' => 1],
299-
['id' => '2', 'key' => 2],
300-
['id' => '3', 'key' => 3],
301-
['id' => '4', 'key' => 4],
302-
];
303-
304304
$queryString = parse_url($this->_request->getUrl(), PHP_URL_QUERY);
305305
$queryParams = [];
306306
parse_str($queryString, $queryParams);
@@ -309,8 +309,12 @@ public function end($handle)
309309
$limit = (int)$queryParams['limit'];
310310

311311
$result = [
312-
'pagination' => ['offset' => $offset, 'total' => 5, 'limit' => $limit],
313-
'result' => array_slice($results, $offset, $limit),
312+
'pagination' => [
313+
'offset' => $offset,
314+
'total' => count($this->results),
315+
'limit' => min($limit, count($this->results)),
316+
],
317+
'result' => array_slice($this->results, $offset, $limit),
314318
];
315319

316320
return new Response(200, ['Content-Type' => ['application/json']], $result);

0 commit comments

Comments
 (0)