Skip to content

Commit

Permalink
Merge pull request #3 from styks1987/master
Browse files Browse the repository at this point in the history
remove 5.4, upgrade to cakephp 3.6, upgrade phpunit to 5
  • Loading branch information
bcrowe authored May 17, 2018
2 parents 63857c1 + b0df963 commit c820cd6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
6 changes: 1 addition & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ env:
- RUN_TESTS=1

php:
- 5.4
- 5.5
- 5.6
- 7.0
- hhvm
Expand All @@ -16,8 +14,6 @@ sudo: false

matrix:
include:
- php: 5.4
env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"'
- php: 5.6
env: PHPCS=1 RUN_TESTS=0

Expand All @@ -26,7 +22,7 @@ before_script:
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source

script:
- sh -c "if [ '$RUN_TESTS' = '1' ]; then phpunit --coverage-text --coverage-clover=coverage.clover; fi"
- sh -c "if [ '$RUN_TESTS' = '1' ]; then vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover; fi"
- sh -c "if [ '$PHPCS' = '1' ]; then vendor/bin/phpcs -p -n --extensions=php --standard=psr2 ./src ./tests; fi"

after_script:
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
}
],
"require": {
"php": ">=5.4.16",
"cakephp/cakephp": "~3.0"
"php": ">=5.6",
"cakephp/cakephp": "~3.6"
},
"require-dev": {
"phpunit/phpunit" : "~4.0",
"scrutinizer/ocular": "~1.1",
"phpunit/phpunit" : "~5.0",
"scrutinizer/ocular": "1.1",
"squizlabs/php_codesniffer": "~2.3.0"
},
"autoload": {
Expand Down
12 changes: 6 additions & 6 deletions src/Controller/Component/ApiPaginationComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public function beforeRender(Event $event)
return;
}

$subject = $event->subject();
$this->pagingInfo = $this->request->params['paging'][$subject->name];
$config = $this->config();
$subject = $event->getSubject();
$this->pagingInfo = $this->request->getParam('paging')[$subject->getName()];
$config = $this->getConfig();

if (!empty($config['aliases'])) {
$this->setAliases();
Expand All @@ -66,7 +66,7 @@ public function beforeRender(Event $event)
*/
protected function setAliases()
{
foreach ($this->config('aliases') as $key => $value) {
foreach ($this->getConfig('aliases') as $key => $value) {
$this->pagingInfo[$value] = $this->pagingInfo[$key];
unset($this->pagingInfo[$key]);
}
Expand All @@ -80,7 +80,7 @@ protected function setAliases()
*/
protected function setVisibility()
{
$visible = $this->config('visible');
$visible = $this->getConfig('visible');
foreach ($this->pagingInfo as $key => $value) {
if (!in_array($key, $visible)) {
unset($this->pagingInfo[$key]);
Expand All @@ -96,7 +96,7 @@ protected function setVisibility()
*/
protected function isPaginatedApiRequest()
{
if (isset($this->request->params['paging']) &&
if ($this->request->getParam('paging') &&
$this->request->is(['json', 'xml'])
) {
return true;
Expand Down
28 changes: 18 additions & 10 deletions tests/TestCase/Controller/Component/ApiPaginationComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
use BryanCrowe\ApiPagination\Controller\Component\ApiPaginationComponent;
use BryanCrowe\ApiPagination\TestApp\Controller\ArticlesController;
use Cake\Event\Event;
use Cake\Network\Request;
use Cake\Network\Response;
use Cake\Http\ServerRequest as Request;
use Cake\Http\Response;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;

/**
* ApiPaginationComponentTest class
*
* @property ArticlesController $controller
*/
class ApiPaginationComponentTest extends TestCase
{
Expand All @@ -24,7 +26,7 @@ class ApiPaginationComponentTest extends TestCase
public function setUp()
{
$this->request = new Request('/articles');
$this->response = $this->getMock('Cake\Network\Response');
$this->response = $this->createMock('Cake\Http\Response');
$this->controller = new ArticlesController($this->request, $this->response);
$this->Articles = TableRegistry::get('BryanCrowe/ApiPagination.Articles', ['table' => 'bryancrowe_articles']);
parent::setUp();
Expand Down Expand Up @@ -61,7 +63,7 @@ public function testNonApiPaginatedRequest()
*/
public function testDefaultPaginationSettings()
{
$this->request->env('HTTP_ACCEPT', 'application/json');
$this->controller->request = $this->controller->request->withEnv('HTTP_ACCEPT', 'application/json');
$this->controller->set('data', $this->controller->paginate($this->Articles));
$apiPaginationComponent = new ApiPaginationComponent($this->controller->components());
$event = new Event('Controller.beforeRender', $this->controller);
Expand All @@ -81,7 +83,9 @@ public function testDefaultPaginationSettings()
'direction' => false,
'limit' => null,
'sortDefault' => false,
'directionDefault' => false
'directionDefault' => false,
'scope' => null,
'completeSort' => []
];

$this->assertSame($expected, $result);
Expand All @@ -94,7 +98,7 @@ public function testDefaultPaginationSettings()
*/
public function testVisibilitySettings()
{
$this->request->env('HTTP_ACCEPT', 'application/json');
$this->controller->request = $this->controller->request->withEnv('HTTP_ACCEPT', 'application/json');
$this->controller->set('data', $this->controller->paginate($this->Articles));
$apiPaginationComponent = new ApiPaginationComponent($this->controller->components(), [
'visible' => [
Expand Down Expand Up @@ -129,7 +133,7 @@ public function testVisibilitySettings()
*/
public function testAliasSettings()
{
$this->request->env('HTTP_ACCEPT', 'application/json');
$this->controller->request = $this->controller->request->withEnv('HTTP_ACCEPT', 'application/json');
$this->controller->set('data', $this->controller->paginate($this->Articles));
$apiPaginationComponent = new ApiPaginationComponent($this->controller->components(), [
'aliases' => [
Expand All @@ -153,6 +157,8 @@ public function testAliasSettings()
'limit' => null,
'sortDefault' => false,
'directionDefault' => false,
'scope' => null,
'completeSort' => [],
'curPage' => 1,
'currentCount' => 20,
'totalCount' => 23,
Expand All @@ -168,7 +174,7 @@ public function testAliasSettings()
*/
public function testKeySetting()
{
$this->request->env('HTTP_ACCEPT', 'application/json');
$this->controller->request = $this->controller->request->withEnv('HTTP_ACCEPT', 'application/json');
$this->controller->set('data', $this->controller->paginate($this->Articles));
$apiPaginationComponent = new ApiPaginationComponent($this->controller->components(), [
'key' => 'paging'
Expand All @@ -190,7 +196,9 @@ public function testKeySetting()
'direction' => false,
'limit' => null,
'sortDefault' => false,
'directionDefault' => false
'directionDefault' => false,
'scope' => null,
'completeSort' => []
];

$this->assertSame($expected, $result);
Expand All @@ -203,7 +211,7 @@ public function testKeySetting()
*/
public function testAllSettings()
{
$this->request->env('HTTP_ACCEPT', 'application/json');
$this->controller->request = $this->controller->request->withEnv('HTTP_ACCEPT', 'application/json');
$this->controller->set('data', $this->controller->paginate($this->Articles));
$apiPaginationComponent = new ApiPaginationComponent($this->controller->components(), [
'key' => 'fun',
Expand Down

0 comments on commit c820cd6

Please sign in to comment.