Skip to content

Commit

Permalink
Update requirement to cakephp/cakephp@^5.1 (#51)
Browse files Browse the repository at this point in the history
* Fix incompatibility with SQLite in CakePHP 5.1

* Update requirement to cakephp/cakephp@^5.1
  • Loading branch information
chitoku-k authored Jan 8, 2025
1 parent a9f8873 commit bd7a1f1
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 63 deletions.
4 changes: 2 additions & 2 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: ^8.1
- CakePHP: ^5.0
- CakePHP: ^5.1
- [lampager/lampager][]: ^0.4

### Note
Expand Down Expand Up @@ -170,7 +170,7 @@ See also: [lampager/lampager][].
| Lampager\\Cake\\`Paginator` | Class | Lampager\\`Paginator` | Paginator implementation for CakePHP |
| Lampager\\Cake\\`ArrayProcessor` | Class | Lampager\\`ArrayProcessor` | Processor implementation for CakePHP |
| Lampager\\Cake\\`PaginationResult` | Class | Lampager\\`PaginationResult`<br>Cake\\Datasource\\Paging\\`PaginatedInterface` | PaginationResult implementation for CakePHP |
| Lampager\\Cake\\Database\\`SqliteCompiler` | Class | Cake\\Database\\`SqliteCompiler` | Query compiler implementation for SQLite |
| Lampager\\Cake\\Database\\`SqliteCompiler` | Class | Cake\\Database\\`QueryCompiler` | Query compiler implementation for SQLite |
| Lampager\\Cake\\Database\\Driver\\`Sqlite` | Class | Cake\\Database\\Driver\\`Sqlite` | Driver implementation which delegates to Lampager\\Cake\\Database\\`SqliteCompiler` |

## API
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
},
"require": {
"php": "^8.1",
"cakephp/cakephp": "^5.0",
"cakephp/cakephp": "^5.1",
"lampager/lampager": "^0.4"
},
"require-dev": {
"phpunit/phpunit": "^10.1",
"phpunit/phpunit": "^10.1 || ^11.0",
"nilportugues/sql-query-formatter": "^1.2"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/Database/SqliteCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
namespace Lampager\Cake\Database;

use Cake\Database\Query;
use Cake\Database\SqliteCompiler as BaseSqliteCompiler;
use Cake\Database\QueryCompiler;
use Cake\Database\ValueBinder;

class SqliteCompiler extends BaseSqliteCompiler
class SqliteCompiler extends QueryCompiler
{
/**
* {@inheritdoc}
Expand Down
31 changes: 11 additions & 20 deletions tests/TestCase/Datasource/PaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Lampager\Cake\PaginationResult;
use Lampager\Cake\Test\TestCase\TestCase;
use Lampager\Exceptions\InvalidArgumentException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;

class PaginatorTest extends TestCase
Expand All @@ -26,10 +27,8 @@ class PaginatorTest extends TestCase
'plugin.Lampager\\Cake.Posts',
];

/**
* @dataProvider valueProvider
* @dataProvider queryExpressionProvider
*/
#[DataProvider('valueProvider')]
#[DataProvider('queryExpressionProvider')]
public function testPaginateTable(callable $factory, PaginationResult $expected): void
{
$controller = new class(new ServerRequest()) extends Controller {
Expand All @@ -48,10 +47,8 @@ public function testPaginateTable(callable $factory, PaginationResult $expected)
$this->assertJsonEquals($expected, $controller->paginate('Posts', $options));
}

/**
* @dataProvider valueProvider
* @dataProvider queryExpressionProvider
*/
#[DataProvider('valueProvider')]
#[DataProvider('queryExpressionProvider')]
public function testPaginateTableFinder(callable $factory, PaginationResult $expected): void
{
$controller = new class(new ServerRequest()) extends Controller {
Expand All @@ -74,10 +71,8 @@ public function testPaginateTableFinder(callable $factory, PaginationResult $exp
$this->assertJsonEquals($expected, $controller->paginate('Posts', $options));
}

/**
* @dataProvider valueProvider
* @dataProvider queryExpressionProvider
*/
#[DataProvider('valueProvider')]
#[DataProvider('queryExpressionProvider')]
public function testPaginateCakeQuery(callable $factory, PaginationResult $expected): void
{
$controller = new class(new ServerRequest()) extends Controller {
Expand All @@ -96,10 +91,8 @@ public function testPaginateCakeQuery(callable $factory, PaginationResult $expec
$this->assertJsonEquals($expected, $controller->paginate($posts->find('all'), $options));
}

/**
* @dataProvider valueProvider
* @dataProvider queryExpressionProvider
*/
#[DataProvider('valueProvider')]
#[DataProvider('queryExpressionProvider')]
public function testPaginateExtraSettings(callable $factory): void
{
$controller = new class(new ServerRequest()) extends Controller {
Expand All @@ -122,10 +115,8 @@ public function testPaginateExtraSettings(callable $factory): void
});
}

/**
* @dataProvider valueProvider
* @dataProvider queryExpressionProvider
*/
#[DataProvider('valueProvider')]
#[DataProvider('queryExpressionProvider')]
public function testPaginateLampagerCakeQuery(callable $factory): void
{
$this->expectException(InvalidArgumentException::class);
Expand Down
3 changes: 2 additions & 1 deletion tests/TestCase/Model/ArrayProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Lampager\Cake\PaginationResult;
use Lampager\Cake\Paginator;
use Lampager\Cake\Test\TestCase\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;

class ArrayProcessorTest extends TestCase
Expand All @@ -21,8 +22,8 @@ class ArrayProcessorTest extends TestCase
* @param mixed[] $options
* @param ?mixed[] $cursor
* @param Entity[] $rows
* @dataProvider processProvider
*/
#[DataProvider('processProvider')]
public function testProcess(array $options, ?array $cursor, array $rows, PaginationResult $expected): void
{
/** @var MockObject&Table $repository */
Expand Down
7 changes: 3 additions & 4 deletions tests/TestCase/Model/Behavior/LampagerBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@
use Lampager\Cake\ORM\Query;
use Lampager\Cake\Test\TestCase\TestCase;
use Lampager\PaginationResult;
use PHPUnit\Framework\Attributes\DataProvider;

class LampagerBehaviorTest extends TestCase
{
public array $fixtures = [
'plugin.Lampager\\Cake.Posts',
];

/**
* @dataProvider valueProvider
* @dataProvider queryExpressionProvider
*/
#[DataProvider('valueProvider')]
#[DataProvider('queryExpressionProvider')]
public function testLampager(callable $factory, PaginationResult $expected): void
{
/** @var LampagerBehavior&Table $posts */
Expand Down
15 changes: 5 additions & 10 deletions tests/TestCase/ORM/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Lampager\Exceptions\Query\BadKeywordException;
use Lampager\Exceptions\Query\InsufficientConstraintsException;
use Lampager\Exceptions\Query\LimitParameterException;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;

class QueryTest extends TestCase
Expand Down Expand Up @@ -46,10 +47,8 @@ public function tearDown(): void
parent::tearDown();
}

/**
* @dataProvider orderProvider
*/
public function testorderBy(callable $factory, PaginationResult $expected): void
#[DataProvider('orderProvider')]
public function testOrderBy(callable $factory, PaginationResult $expected): void
{
/** @var LampagerBehavior&Table $posts */
$posts = TableRegistry::getTableLocator()->get('Posts');
Expand All @@ -60,9 +59,7 @@ public function testorderBy(callable $factory, PaginationResult $expected): void
$this->assertJsonEquals($expected, $query->paginate());
}

/**
* @dataProvider orderProvider
*/
#[DataProvider('orderProvider')]
public function testOrderClear(callable $factory): void
{
$this->expectException(LampagerException::class);
Expand Down Expand Up @@ -309,9 +306,7 @@ public function testDebugInfoIncomplete(): void
$this->assertArrayHasKey('extraOptions', $actual);
}

/**
* @dataProvider countProvider
*/
#[DataProvider('countProvider')]
public function testCount(callable $factory, int $expected): void
{
/** @var LampagerBehavior&Table $posts */
Expand Down
45 changes: 23 additions & 22 deletions tests/TestCase/PaginationResultTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Generator;
use IteratorAggregate;
use Lampager\Cake\PaginationResult;
use PHPUnit\Framework\Attributes\DataProvider;
use Traversable;

class PaginationResultTest extends TestCase
Expand Down Expand Up @@ -37,9 +38,9 @@ public function tearDown(): void
* @param Entity[] $entities
* @param Entity[]|Traversable<Entity> $records
* @param mixed[] $meta
* @dataProvider arrayProvider
* @dataProvider iteratorAggregateProvider
*/
#[DataProvider('arrayProvider')]
#[DataProvider('iteratorAggregateProvider')]
public function testCurrentPage(array $entities, $records, array $meta): void
{
$actual = new PaginationResult($records, $meta);
Expand All @@ -50,9 +51,9 @@ public function testCurrentPage(array $entities, $records, array $meta): void
* @param Entity[] $entities
* @param Entity[]|Traversable<Entity> $records
* @param mixed[] $meta
* @dataProvider arrayProvider
* @dataProvider iteratorAggregateProvider
*/
#[DataProvider('arrayProvider')]
#[DataProvider('iteratorAggregateProvider')]
public function testPerPage(array $entities, $records, array $meta): void
{
$actual = new PaginationResult($records, $meta);
Expand All @@ -63,9 +64,9 @@ public function testPerPage(array $entities, $records, array $meta): void
* @param Entity[] $entities
* @param Entity[]|Traversable<Entity> $records
* @param mixed[] $meta
* @dataProvider arrayProvider
* @dataProvider iteratorAggregateProvider
*/
#[DataProvider('arrayProvider')]
#[DataProvider('iteratorAggregateProvider')]
public function testTotalCount(array $entities, $records, array $meta): void
{
$actual = new PaginationResult($records, $meta);
Expand All @@ -76,9 +77,9 @@ public function testTotalCount(array $entities, $records, array $meta): void
* @param Entity[] $entities
* @param Entity[]|Traversable<Entity> $records
* @param mixed[] $meta
* @dataProvider arrayProvider
* @dataProvider iteratorAggregateProvider
*/
#[DataProvider('arrayProvider')]
#[DataProvider('iteratorAggregateProvider')]
public function testPageCount(array $entities, $records, array $meta): void
{
$actual = new PaginationResult($records, $meta);
Expand All @@ -89,9 +90,9 @@ public function testPageCount(array $entities, $records, array $meta): void
* @param Entity[] $entities
* @param Entity[]|Traversable<Entity> $records
* @param mixed[] $meta
* @dataProvider arrayProvider
* @dataProvider iteratorAggregateProvider
*/
#[DataProvider('arrayProvider')]
#[DataProvider('iteratorAggregateProvider')]
public function testHasPrevPage(array $entities, $records, array $meta): void
{
$actual = new PaginationResult($records, $meta);
Expand All @@ -102,9 +103,9 @@ public function testHasPrevPage(array $entities, $records, array $meta): void
* @param Entity[] $entities
* @param Entity[]|Traversable<Entity> $records
* @param mixed[] $meta
* @dataProvider arrayProvider
* @dataProvider iteratorAggregateProvider
*/
#[DataProvider('arrayProvider')]
#[DataProvider('iteratorAggregateProvider')]
public function testHasNextPage(array $entities, $records, array $meta): void
{
$actual = new PaginationResult($records, $meta);
Expand All @@ -115,9 +116,9 @@ public function testHasNextPage(array $entities, $records, array $meta): void
* @param Entity[] $entities
* @param Entity[]|Traversable<Entity> $records
* @param mixed[] $meta
* @dataProvider arrayProvider
* @dataProvider iteratorAggregateProvider
*/
#[DataProvider('arrayProvider')]
#[DataProvider('iteratorAggregateProvider')]
public function testItems(array $entities, $records, array $meta): void
{
$paginationResult = new PaginationResult($records, $meta);
Expand All @@ -130,9 +131,9 @@ public function testItems(array $entities, $records, array $meta): void
* @param Entity[] $entities
* @param Entity[]|Traversable<Entity> $records
* @param mixed[] $meta
* @dataProvider arrayProvider
* @dataProvider iteratorAggregateProvider
*/
#[DataProvider('arrayProvider')]
#[DataProvider('iteratorAggregateProvider')]
public function testPagingParam(array $entities, $records, array $meta): void
{
$actual = new PaginationResult($records, $meta);
Expand All @@ -149,9 +150,9 @@ public function testPagingParam(array $entities, $records, array $meta): void
* @param Entity[] $entities
* @param Entity[]|Traversable<Entity> $records
* @param mixed[] $meta
* @dataProvider arrayProvider
* @dataProvider iteratorAggregateProvider
*/
#[DataProvider('arrayProvider')]
#[DataProvider('iteratorAggregateProvider')]
public function testJsonSerialize(array $entities, $records, array $meta, string $expected): void
{
$actual = json_encode(new PaginationResult($records, $meta));
Expand All @@ -162,9 +163,9 @@ public function testJsonSerialize(array $entities, $records, array $meta, string
* @param Entity[] $entities
* @param Entity[]|Traversable<Entity> $records
* @param mixed[] $meta
* @dataProvider arrayProvider
* @dataProvider iteratorAggregateProvider
*/
#[DataProvider('arrayProvider')]
#[DataProvider('iteratorAggregateProvider')]
public function testDebugInfo(array $entities, $records, array $meta): void
{
$actual = (new PaginationResult($records, $meta))->__debugInfo();
Expand All @@ -183,9 +184,9 @@ public function testDebugInfo(array $entities, $records, array $meta): void
* @param Entity[] $entities
* @param Entity[]|Traversable<Entity> $records
* @param mixed[] $meta
* @dataProvider arrayProvider
* @dataProvider iteratorAggregateProvider
*/
#[DataProvider('arrayProvider')]
#[DataProvider('iteratorAggregateProvider')]
public function testPublicProperties(array $entities, $records, array $meta): void
{
$paginationResult = new PaginationResult($records, $meta);
Expand Down

0 comments on commit bd7a1f1

Please sign in to comment.