Skip to content

Commit

Permalink
Updating the Pagination Service to 4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
burzum committed Mar 9, 2020
1 parent 4242f31 commit 9c945c2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
8 changes: 4 additions & 4 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ imports:

build:
nodes:
php72:
environment:
php: '7.2'

php73:
environment:
php: '7.3'
Expand All @@ -19,10 +23,6 @@ build:
file: 'coverage.xml'
format: 'clover'

php72:
environment:
php: '7.2'

filter:
excluded_paths:
- docs/
Expand Down
5 changes: 3 additions & 2 deletions src/Service/PaginationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

namespace Burzum\Cake\Service;

use Cake\Event\EventInterface;
use Cake\Http\ServerRequest;

/**
Expand Down Expand Up @@ -42,8 +43,8 @@ public function __construct(ServerRequest &$request)
$this->request = $request;

$_this = $this;
$this->getEventManager()->on('Service.afterPaginate', function () use ($_this) {
$_this->_request = $_this->addPagingParamToRequest($_this->request);
$this->getEventManager()->on('Service.afterPaginate', function (EventInterface $event) use ($_this) {
$event->setData('request', $_this->addPagingParamToRequest($_this->request));
});
}
}
11 changes: 6 additions & 5 deletions tests/TestCase/Service/PaginationServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ public function testPaginate()
$request = new ServerRequest();
$service = new PaginationService($request);

$this->assertFalse($request->getParam('paging'));
$articles = TableRegistry::getTableLocator()->get('Articles');

$articles = TableRegistry::get('Articles');
$result = $service->paginate($articles);
$request = $service->addPagingParamToRequest($request);

$params = $request->getParam('paging');
$expected = [
'Articles' => [
Expand All @@ -68,11 +69,11 @@ public function testPaginate()
'completeSort' => [],
'start' => 1,
'end' => 3,
],
false
'requestedPage' => 1
]
];

$this->assertInternalType('array', $params);
$this->assertIsArray($params);
$this->assertEquals($expected, $params);
$this->assertInstanceOf(ResultSet::class, $result);
}
Expand Down

0 comments on commit 9c945c2

Please sign in to comment.