Skip to content

Commit c820cd6

Browse files
authored
Merge pull request #3 from styks1987/master
remove 5.4, upgrade to cakephp 3.6, upgrade phpunit to 5
2 parents 63857c1 + b0df963 commit c820cd6

File tree

4 files changed

+29
-25
lines changed

4 files changed

+29
-25
lines changed

Diff for: .travis.yml

+1-5
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ env:
66
- RUN_TESTS=1
77

88
php:
9-
- 5.4
10-
- 5.5
119
- 5.6
1210
- 7.0
1311
- hhvm
@@ -16,8 +14,6 @@ sudo: false
1614

1715
matrix:
1816
include:
19-
- php: 5.4
20-
env: 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"'
2117
- php: 5.6
2218
env: PHPCS=1 RUN_TESTS=0
2319

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

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

3228
after_script:

Diff for: composer.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
}
1717
],
1818
"require": {
19-
"php": ">=5.4.16",
20-
"cakephp/cakephp": "~3.0"
19+
"php": ">=5.6",
20+
"cakephp/cakephp": "~3.6"
2121
},
2222
"require-dev": {
23-
"phpunit/phpunit" : "~4.0",
24-
"scrutinizer/ocular": "~1.1",
23+
"phpunit/phpunit" : "~5.0",
24+
"scrutinizer/ocular": "1.1",
2525
"squizlabs/php_codesniffer": "~2.3.0"
2626
},
2727
"autoload": {

Diff for: src/Controller/Component/ApiPaginationComponent.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public function beforeRender(Event $event)
4242
return;
4343
}
4444

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

4949
if (!empty($config['aliases'])) {
5050
$this->setAliases();
@@ -66,7 +66,7 @@ public function beforeRender(Event $event)
6666
*/
6767
protected function setAliases()
6868
{
69-
foreach ($this->config('aliases') as $key => $value) {
69+
foreach ($this->getConfig('aliases') as $key => $value) {
7070
$this->pagingInfo[$value] = $this->pagingInfo[$key];
7171
unset($this->pagingInfo[$key]);
7272
}
@@ -80,7 +80,7 @@ protected function setAliases()
8080
*/
8181
protected function setVisibility()
8282
{
83-
$visible = $this->config('visible');
83+
$visible = $this->getConfig('visible');
8484
foreach ($this->pagingInfo as $key => $value) {
8585
if (!in_array($key, $visible)) {
8686
unset($this->pagingInfo[$key]);
@@ -96,7 +96,7 @@ protected function setVisibility()
9696
*/
9797
protected function isPaginatedApiRequest()
9898
{
99-
if (isset($this->request->params['paging']) &&
99+
if ($this->request->getParam('paging') &&
100100
$this->request->is(['json', 'xml'])
101101
) {
102102
return true;

Diff for: tests/TestCase/Controller/Component/ApiPaginationComponentTest.php

+18-10
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
use BryanCrowe\ApiPagination\Controller\Component\ApiPaginationComponent;
55
use BryanCrowe\ApiPagination\TestApp\Controller\ArticlesController;
66
use Cake\Event\Event;
7-
use Cake\Network\Request;
8-
use Cake\Network\Response;
7+
use Cake\Http\ServerRequest as Request;
8+
use Cake\Http\Response;
99
use Cake\ORM\TableRegistry;
1010
use Cake\TestSuite\TestCase;
1111

1212
/**
1313
* ApiPaginationComponentTest class
14+
*
15+
* @property ArticlesController $controller
1416
*/
1517
class ApiPaginationComponentTest extends TestCase
1618
{
@@ -24,7 +26,7 @@ class ApiPaginationComponentTest extends TestCase
2426
public function setUp()
2527
{
2628
$this->request = new Request('/articles');
27-
$this->response = $this->getMock('Cake\Network\Response');
29+
$this->response = $this->createMock('Cake\Http\Response');
2830
$this->controller = new ArticlesController($this->request, $this->response);
2931
$this->Articles = TableRegistry::get('BryanCrowe/ApiPagination.Articles', ['table' => 'bryancrowe_articles']);
3032
parent::setUp();
@@ -61,7 +63,7 @@ public function testNonApiPaginatedRequest()
6163
*/
6264
public function testDefaultPaginationSettings()
6365
{
64-
$this->request->env('HTTP_ACCEPT', 'application/json');
66+
$this->controller->request = $this->controller->request->withEnv('HTTP_ACCEPT', 'application/json');
6567
$this->controller->set('data', $this->controller->paginate($this->Articles));
6668
$apiPaginationComponent = new ApiPaginationComponent($this->controller->components());
6769
$event = new Event('Controller.beforeRender', $this->controller);
@@ -81,7 +83,9 @@ public function testDefaultPaginationSettings()
8183
'direction' => false,
8284
'limit' => null,
8385
'sortDefault' => false,
84-
'directionDefault' => false
86+
'directionDefault' => false,
87+
'scope' => null,
88+
'completeSort' => []
8589
];
8690

8791
$this->assertSame($expected, $result);
@@ -94,7 +98,7 @@ public function testDefaultPaginationSettings()
9498
*/
9599
public function testVisibilitySettings()
96100
{
97-
$this->request->env('HTTP_ACCEPT', 'application/json');
101+
$this->controller->request = $this->controller->request->withEnv('HTTP_ACCEPT', 'application/json');
98102
$this->controller->set('data', $this->controller->paginate($this->Articles));
99103
$apiPaginationComponent = new ApiPaginationComponent($this->controller->components(), [
100104
'visible' => [
@@ -129,7 +133,7 @@ public function testVisibilitySettings()
129133
*/
130134
public function testAliasSettings()
131135
{
132-
$this->request->env('HTTP_ACCEPT', 'application/json');
136+
$this->controller->request = $this->controller->request->withEnv('HTTP_ACCEPT', 'application/json');
133137
$this->controller->set('data', $this->controller->paginate($this->Articles));
134138
$apiPaginationComponent = new ApiPaginationComponent($this->controller->components(), [
135139
'aliases' => [
@@ -153,6 +157,8 @@ public function testAliasSettings()
153157
'limit' => null,
154158
'sortDefault' => false,
155159
'directionDefault' => false,
160+
'scope' => null,
161+
'completeSort' => [],
156162
'curPage' => 1,
157163
'currentCount' => 20,
158164
'totalCount' => 23,
@@ -168,7 +174,7 @@ public function testAliasSettings()
168174
*/
169175
public function testKeySetting()
170176
{
171-
$this->request->env('HTTP_ACCEPT', 'application/json');
177+
$this->controller->request = $this->controller->request->withEnv('HTTP_ACCEPT', 'application/json');
172178
$this->controller->set('data', $this->controller->paginate($this->Articles));
173179
$apiPaginationComponent = new ApiPaginationComponent($this->controller->components(), [
174180
'key' => 'paging'
@@ -190,7 +196,9 @@ public function testKeySetting()
190196
'direction' => false,
191197
'limit' => null,
192198
'sortDefault' => false,
193-
'directionDefault' => false
199+
'directionDefault' => false,
200+
'scope' => null,
201+
'completeSort' => []
194202
];
195203

196204
$this->assertSame($expected, $result);
@@ -203,7 +211,7 @@ public function testKeySetting()
203211
*/
204212
public function testAllSettings()
205213
{
206-
$this->request->env('HTTP_ACCEPT', 'application/json');
214+
$this->controller->request = $this->controller->request->withEnv('HTTP_ACCEPT', 'application/json');
207215
$this->controller->set('data', $this->controller->paginate($this->Articles));
208216
$apiPaginationComponent = new ApiPaginationComponent($this->controller->components(), [
209217
'key' => 'fun',

0 commit comments

Comments
 (0)