Skip to content

Commit 5d4c283

Browse files
committed
Fix custom pagination
Fixes #172
1 parent c2a9005 commit 5d4c283

File tree

8 files changed

+54
-13
lines changed

8 files changed

+54
-13
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7+
## [0.3.1] - 10 Sep 2018
8+
### Changed
9+
- use of `cache()` helper method to `app("cache")` to allow for better Lumen compatibility. Thanks @nope7777!
10+
11+
### Updated
12+
- test script for Laravel 5.7 to use non-dev version of test dependency.
13+
14+
### Removed
15+
- `codedungeon/phpunit-result-printer` unit test output printer.
16+
17+
### Fixed
18+
- use of custom pagination name.
19+
720
## [0.3.0] - 10 Sep 2018
821
### Added
922
- Laravel 5.7 compatibility.

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,10 @@
1818
"php": ">=7.1.3"
1919
},
2020
"require-dev": {
21-
"codedungeon/phpunit-result-printer": "*",
2221
"fzaninotto/faker": "*",
2322
"mockery/mockery": "*",
24-
"orchestra/database": "3.7.x-dev",
25-
"orchestra/testbench-browser-kit": "3.7.x-dev",
23+
"orchestra/database": "3.7.x-dev@dev",
24+
"orchestra/testbench-browser-kit": "3.7.*",
2625
"orchestra/testbench": "3.7.*",
2726
"php-coveralls/php-coveralls" : "*",
2827
"phpmd/phpmd": "*",

phpunit.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
convertErrorsToExceptions="true"
88
convertNoticesToExceptions="true"
99
convertWarningsToExceptions="true"
10-
printerClass="Codedungeon\PHPUnitPrettyResultPrinter\Printer"
1110
processIsolation="false"
1211
stopOnFailure="false"
1312
>

src/CachedBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function paginate(
126126
return parent::paginate($perPage, $columns, $pageName, $page);
127127
}
128128

129-
$page = request("page", $page ?: 1);
129+
$page = request($pageName, $page ?: 1);
130130

131131
if (is_array($page)) {
132132
$page = $this->recursiveImplodeWithKey($page);

src/Traits/Caching.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ protected function makeCacheTags() : array
8888
return $tags;
8989
}
9090

91-
public function getModelCacheCooldown(Model $instance)
91+
public function getModelCacheCooldown(Model $instance) : array
9292
{
9393
$cachePrefix = $this->getCachePrefix();
9494
$modelClassName = get_class($instance);
@@ -99,11 +99,7 @@ public function getModelCacheCooldown(Model $instance)
9999
return [null, null, null];
100100
}
101101

102-
return [
103-
$cacheCooldown,
104-
$invalidatedAt,
105-
$savedAt,
106-
];
102+
return [$cacheCooldown, $invalidatedAt, $savedAt];
107103
}
108104

109105
protected function getCacheCooldownDetails(

tests/Feature/PaginationTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,28 @@ public function testAdvancedPagination()
5959

6060
$response->see($page1ActiveLink);
6161
}
62+
63+
public function testCustomPagination()
64+
{
65+
if (starts_with(app()->version(), "5.6")
66+
|| starts_with(app()->version(), "5.7")
67+
) {
68+
$page1ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">1</span></li>';
69+
$page2ActiveLink = '<li class="page-item active" aria-current="page"><span class="page-link">2</span></li>';
70+
}
71+
72+
if (starts_with(app()->version(), "5.5")) {
73+
$page1ActiveLink = '<li class="active"><span>1</span></li>';
74+
$page2ActiveLink = '<li class="active"><span>2</span></li>';
75+
}
76+
77+
if (starts_with(app()->version(), "5.4")) {
78+
$page1ActiveLink = '<li class="active"><span>1</span></li>';
79+
$page2ActiveLink = '<li class="active"><span>2</span></li>';
80+
}
81+
82+
$response = $this->visit("pagination-test2?custom-page=2");
83+
84+
$response->see($page2ActiveLink);
85+
}
6286
}

tests/pu-57.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
cp composer.json original-composer.json
44

55
composer require codedungeon/phpunit-result-printer --no-update --dev
6-
composer require "orchestra/database:3.7.x-dev" --no-update --dev
6+
composer require "orchestra/database:3.7.x-dev@dev" --no-update --dev
77
composer require "orchestra/testbench:3.7.*" --no-update --dev
8-
composer require "orchestra/testbench-browser-kit:3.7.x-dev" --no-update --dev
8+
composer require "orchestra/testbench-browser-kit:3.7.*" --no-update --dev
99
composer require "illuminate/cache:5.7.*" --no-update
1010
composer require "illuminate/config:5.7.*" --no-update
1111
composer require "illuminate/console:5.7.*" --no-update

tests/routes/web.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,13 @@
1111
'books'
1212
));
1313
});
14+
15+
Route::get('pagination-test2', function () {
16+
$books = (new Book)
17+
->paginate(10, ["*"], "custom-page");
18+
19+
return view("model-caching-tests.pagination")
20+
->with(compact(
21+
'books'
22+
));
23+
});

0 commit comments

Comments
 (0)