Skip to content

Commit

Permalink
Update requirement to cakephp/cakephp@^4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
chitoku-k committed Apr 12, 2024
1 parent 9e4c3a2 commit 5ae4f0b
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 46 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
- 8.0
- 8.1
- 8.2
- 8.3
dsn:
- ''
- mysql://lampager_test:lampager_test@127.0.0.1/lampager_test
Expand Down Expand Up @@ -78,10 +79,12 @@ jobs:
env:
DB_DSN: ${{ matrix.dsn }}
run: |
vendor/bin/phpunit
composer test
- name: Coverage
if: ${{ matrix.php == 8.2 && matrix.dsn == '' }}
if: ${{ matrix.php == 8.3 && matrix.dsn == '' }}
env:
COVERALLS_REPO_TOKEN: ${{ github.token }}
run: |
vendor/bin/php-coveralls --verbose
export PATH=$(composer config --global home):$PATH
composer global require 'php-coveralls/php-coveralls:*'
php-coveralls --verbose
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Rapid pagination without using OFFSET
## Requirements

- PHP: ^7.4 || ^8.0
- CakePHP: ^4.4
- CakePHP: ^4.5
- [lampager/lampager][]: ^0.4

### Note
Expand Down Expand Up @@ -144,9 +144,9 @@ $drafts = $this->lampager()
->seekable()
->cursor($cursor)
->limit(10)
->orderDesc($this->query()->newExpr('modified'))
->orderDesc($this->query()->newExpr('created'))
->orderDesc($this->query()->newExpr('id'));
->orderDesc($this->selectQuery()->newExpr('modified'))
->orderDesc($this->selectQuery()->newExpr('created'))
->orderDesc($this->selectQuery()->newExpr('id'));

/** @var \Cake\ORM\Entity $sample */
$sample = $drafts->sample();
Expand Down Expand Up @@ -288,6 +288,8 @@ namespace App\Controller;

class PostsController extends AppController
{
public $Posts = null;

/**
* This method shows how to pass options by a query and array.
*/
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
},
"require": {
"php": "^7.4 || ^8.0",
"cakephp/cakephp": "^4.4",
"cakephp/cakephp": "^4.5",
"lampager/lampager": "^0.4"
},
"require-dev": {
"phpunit/phpunit": "^8.0 || ^9.0",
"php-coveralls/php-coveralls": "^2.4",
"nilportugues/sql-query-formatter": "^1.2"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected function compileSelect(Select $select): Query
$repository = $this->builder->getRepository();

/** @var Query $builder */
$builder = $repository->query()
$builder = $repository->selectQuery()
->where($this->builder->clause('where'))
->modifier($this->builder->clause('modifier'))
->join($this->builder->clause('join'))
Expand Down
4 changes: 4 additions & 0 deletions tests/TestCase/Datasource/PaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class PaginatorTest extends TestCase
public function testPaginateTable(callable $factory, PaginationResult $expected): void
{
$controller = new Controller();
$controller->Posts = null;
$controller->paginate = [
'className' => Paginator::class,
];
Expand All @@ -51,6 +52,7 @@ public function testPaginateTable(callable $factory, PaginationResult $expected)
public function testPaginateCakeQuery(callable $factory, PaginationResult $expected): void
{
$controller = new Controller();
$controller->Posts = null;
$controller->paginate = [
'className' => Paginator::class,
];
Expand All @@ -73,6 +75,7 @@ public function testPaginateLampagerCakeQuery(callable $factory): void
$this->expectExceptionMessage('Lampager\Cake\ORM\Query cannot be paginated by Lampager\Cake\Datasource\Paginator::paginate()');

$controller = new Controller();
$controller->Posts = null;
$controller->paginate = [
'className' => Paginator::class,
];
Expand All @@ -93,6 +96,7 @@ public function testPaginateInvalidQuery(): void
$this->expectExceptionMessage('No repository set for query.');

$controller = new Controller();
$controller->Posts = null;
$controller->paginate = [
'className' => Paginator::class,
];
Expand Down
60 changes: 30 additions & 30 deletions tests/TestCase/Model/Behavior/LampagerBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,8 @@ function (Table $posts) {
->forward()
->seekable()
->limit(3)
->orderAsc($posts->query()->expr('modified'))
->orderAsc($posts->query()->expr('id'));
->orderAsc($posts->selectQuery()->expr('modified'))
->orderAsc($posts->selectQuery()->expr('id'));
},
new PaginationResult(
[
Expand Down Expand Up @@ -698,8 +698,8 @@ function (Table $posts) {
->forward()
->seekable()
->limit(3)
->orderAsc($posts->query()->expr('modified'))
->orderAsc($posts->query()->expr('id'))
->orderAsc($posts->selectQuery()->expr('modified'))
->orderAsc($posts->selectQuery()->expr('id'))
->cursor([
'id' => 3,
'modified' => new FrozenTime('2017-01-01 10:00:00'),
Expand Down Expand Up @@ -743,8 +743,8 @@ function (Table $posts) {
->seekable()
->exclusive()
->limit(3)
->orderAsc($posts->query()->expr('modified'))
->orderAsc($posts->query()->expr('id'))
->orderAsc($posts->selectQuery()->expr('modified'))
->orderAsc($posts->selectQuery()->expr('id'))
->cursor([
'id' => 3,
'modified' => new FrozenTime('2017-01-01 10:00:00'),
Expand Down Expand Up @@ -784,8 +784,8 @@ function (Table $posts) {
->backward()
->seekable()
->limit(3)
->orderAsc($posts->query()->expr('modified'))
->orderAsc($posts->query()->expr('id'));
->orderAsc($posts->selectQuery()->expr('modified'))
->orderAsc($posts->selectQuery()->expr('id'));
},
new PaginationResult(
[
Expand Down Expand Up @@ -822,8 +822,8 @@ function (Table $posts) {
->seekable()
->exclusive()
->limit(3)
->orderAsc($posts->query()->expr('modified'))
->orderAsc($posts->query()->expr('id'));
->orderAsc($posts->selectQuery()->expr('modified'))
->orderAsc($posts->selectQuery()->expr('id'));
},
new PaginationResult(
[
Expand Down Expand Up @@ -859,8 +859,8 @@ function (Table $posts) {
->backward()
->seekable()
->limit(3)
->orderAsc($posts->query()->expr('modified'))
->orderAsc($posts->query()->expr('id'))
->orderAsc($posts->selectQuery()->expr('modified'))
->orderAsc($posts->selectQuery()->expr('id'))
->cursor([
'id' => 3,
'modified' => new FrozenTime('2017-01-01 10:00:00'),
Expand Down Expand Up @@ -897,8 +897,8 @@ function (Table $posts) {
->seekable()
->exclusive()
->limit(3)
->orderAsc($posts->query()->expr('modified'))
->orderAsc($posts->query()->expr('id'))
->orderAsc($posts->selectQuery()->expr('modified'))
->orderAsc($posts->selectQuery()->expr('id'))
->cursor([
'id' => 3,
'modified' => new FrozenTime('2017-01-01 10:00:00'),
Expand Down Expand Up @@ -930,8 +930,8 @@ function (Table $posts) {
->forward()
->seekable()
->limit(3)
->orderDesc($posts->query()->expr('modified'))
->orderDesc($posts->query()->expr('id'));
->orderDesc($posts->selectQuery()->expr('modified'))
->orderDesc($posts->selectQuery()->expr('id'));
},
new PaginationResult(
[
Expand Down Expand Up @@ -968,8 +968,8 @@ function (Table $posts) {
->seekable()
->exclusive()
->limit(3)
->orderDesc($posts->query()->expr('modified'))
->orderDesc($posts->query()->expr('id'));
->orderDesc($posts->selectQuery()->expr('modified'))
->orderDesc($posts->selectQuery()->expr('id'));
},
new PaginationResult(
[
Expand Down Expand Up @@ -1005,8 +1005,8 @@ function (Table $posts) {
->forward()
->seekable()
->limit(3)
->orderDesc($posts->query()->expr('modified'))
->orderDesc($posts->query()->expr('id'))
->orderDesc($posts->selectQuery()->expr('modified'))
->orderDesc($posts->selectQuery()->expr('id'))
->cursor([
'id' => 3,
'modified' => new FrozenTime('2017-01-01 10:00:00'),
Expand Down Expand Up @@ -1043,8 +1043,8 @@ function (Table $posts) {
->seekable()
->exclusive()
->limit(3)
->orderDesc($posts->query()->expr('modified'))
->orderDesc($posts->query()->expr('id'))
->orderDesc($posts->selectQuery()->expr('modified'))
->orderDesc($posts->selectQuery()->expr('id'))
->cursor([
'id' => 3,
'modified' => new FrozenTime('2017-01-01 10:00:00'),
Expand Down Expand Up @@ -1076,8 +1076,8 @@ function (Table $posts) {
->backward()
->seekable()
->limit(3)
->orderDesc($posts->query()->expr('modified'))
->orderDesc($posts->query()->expr('id'));
->orderDesc($posts->selectQuery()->expr('modified'))
->orderDesc($posts->selectQuery()->expr('id'));
},
new PaginationResult(
[
Expand Down Expand Up @@ -1114,8 +1114,8 @@ function (Table $posts) {
->seekable()
->exclusive()
->limit(3)
->orderDesc($posts->query()->expr('modified'))
->orderDesc($posts->query()->expr('id'));
->orderDesc($posts->selectQuery()->expr('modified'))
->orderDesc($posts->selectQuery()->expr('id'));
},
new PaginationResult(
[
Expand Down Expand Up @@ -1151,8 +1151,8 @@ function (Table $posts) {
->backward()
->seekable()
->limit(3)
->orderDesc($posts->query()->expr('modified'))
->orderDesc($posts->query()->expr('id'))
->orderDesc($posts->selectQuery()->expr('modified'))
->orderDesc($posts->selectQuery()->expr('id'))
->cursor([
'id' => 3,
'modified' => new FrozenTime('2017-01-01 10:00:00'),
Expand Down Expand Up @@ -1196,8 +1196,8 @@ function (Table $posts) {
->seekable()
->exclusive()
->limit(3)
->orderDesc($posts->query()->expr('modified'))
->orderDesc($posts->query()->expr('id'))
->orderDesc($posts->selectQuery()->expr('modified'))
->orderDesc($posts->selectQuery()->expr('id'))
->cursor([
'id' => 3,
'modified' => new FrozenTime('2017-01-01 10:00:00'),
Expand Down
12 changes: 6 additions & 6 deletions tests/TestCase/ORM/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ public function testOrderQueryExpression(): void
);

$actual = $posts->lampager()
->order([$posts->query()->expr('modified')])
->order([$posts->query()->expr('id')])
->order([$posts->selectQuery()->expr('modified')])
->order([$posts->selectQuery()->expr('id')])
->limit(1)
->all();

Expand Down Expand Up @@ -155,7 +155,7 @@ public function testLimitQueryExpression(): void
$actual = $posts->lampager()
->orderAsc('modified')
->orderAsc('id')
->limit($posts->query()->expr('1'))
->limit($posts->selectQuery()->expr('1'))
->all();

$this->assertJsonEquals($expected, $actual);
Expand All @@ -172,7 +172,7 @@ public function testLimitIllegalQueryExpression(): void
$posts->lampager()
->orderAsc('modified')
->orderAsc('id')
->limit($posts->query()->expr('1 + 1'))
->limit($posts->selectQuery()->expr('1 + 1'))
->all();
}

Expand Down Expand Up @@ -236,14 +236,14 @@ public function testUnion(): void
$posts->lampager()
->orderAsc('modified')
->orderAsc('id')
->union($posts->query()->select())
->union($posts->selectQuery()->select())
->all();
}

public function testCall(): void
{
$this->expectException(\ErrorException::class);
$this->expectExceptionMessage('You must call `all()` first');
$this->expectExceptionMessage('Instead call `$query->all()->take(...)` instead.');

/** @var LampagerBehavior&Table $posts */
$posts = TableRegistry::getTableLocator()->get('Posts');
Expand Down

0 comments on commit 5ae4f0b

Please sign in to comment.