Skip to content

Cake 5 support #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ jobs:
run: vendor/bin/phpstan analyse

- name: Run tests
run: vendor/bin/phpunit --coverage-clover=coverage.xml
run: vendor/bin/phpunit
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
/vendor
/composer.lock
/nbproject
/phpunit.xml
/coverage.xml
.phpunit.*
test.sqlite
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"type": "cakephp-plugin",
"license": "MIT",
"require": {
"cakephp/orm": "~4.0"
"cakephp/orm": "~5.0"
},
"require-dev": {
"cakephp/cakephp": "~4.0",
"cakephp/cakephp-codesniffer": "^4.0",
"phpunit/phpunit": "^9.5",
"cakephp/cakephp": "~5.0",
"cakephp/cakephp-codesniffer": "^5.0",
"phpunit/phpunit": "^10.0",
"phpstan/phpstan": "^2.0"
},
"autoload": {
Expand Down
12 changes: 7 additions & 5 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
parameters:
level: 4
# reportUnmatchedIgnoredErrors: false
# treatPhpDocTypesAsCertain: false
level: 8
paths:
- src/
- tests/
- src/
ignoreErrors:
-
identifier: missingType.generics
-
identifier: missingType.iterableValue
17 changes: 17 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit
colors="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="./tests/bootstrap.php"
>
<testsuites>
<testsuite name="Chunk Plugin Test Suite">
<directory>./tests/TestCase/</directory>
</testsuite>
</testsuites>
<extensions>
<bootstrap class="Cake\TestSuite\Fixture\Extension\PHPUnitExtension"/>
</extensions>
</phpunit>
34 changes: 0 additions & 34 deletions phpunit.xml.dist

This file was deleted.

6 changes: 3 additions & 3 deletions src/Model/Behavior/ChunkBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@
namespace Robotusers\Chunk\Model\Behavior;

use Cake\ORM\Behavior;
use Cake\ORM\Query;
use Cake\ORM\Query\SelectQuery;
use Robotusers\Chunk\ORM\ResultSet;

class ChunkBehavior extends Behavior
{
/**
* Returns chunked result set.
*
* @param \Cake\ORM\Query $query Query instance.
* @param \Cake\ORM\Query\SelectQuery $query Query instance.
* @param array $config Config.
* @return \Robotusers\Chunk\ORM\ResultSet
*/
public function chunk(Query $query, array $config = [])
public function chunk(SelectQuery $query, array $config = []): ResultSet
{
return new ResultSet($query, $config);
}
Expand Down
55 changes: 28 additions & 27 deletions src/ORM/ResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
use Cake\Collection\CollectionTrait;
use Cake\Core\InstanceConfigTrait;
use Cake\Datasource\ResultSetInterface;
use Cake\ORM\Query;
use Cake\ORM\Query\SelectQuery;
use ReturnTypeWillChange;
use RuntimeException;

class ResultSet implements ResultSetInterface
Expand All @@ -42,70 +43,70 @@ class ResultSet implements ResultSetInterface
*
* @var mixed
*/
protected $current;
protected mixed $current;

/**
* Query instance.
*
* @var \Cake\ORM\Query
* @var \Cake\ORM\Query\SelectQuery
*/
protected $query;
protected SelectQuery $query;

/**
* Current chunk size.
*
* @var int
*/
protected $chunkSize = 0;
protected int $chunkSize = 0;

/**
* Current chunk index.
*
* @var int
*/
protected $chunkIndex = 0;
protected int $chunkIndex = 0;

/**
* Current chunk content.
*
* @var array
* @var array<int, mixed>
*/
protected $chunk;
protected array $chunk;

/**
* Current element index.
*
* @var int
*/
protected $index = 0;
protected int $index = 0;

/**
* Current page.
*
* @var int
*/
protected $page = 0;
protected int $page = 0;

/**
* Original query offset.
*
* @var int
* @var ?int
*/
protected $offset;
protected ?int $offset;

/**
* Original query limit.
*
* @var int
* @var ?int
*/
protected $limit;
protected ?int $limit;

/**
* Total count.
*
* @var int
*/
protected $count;
protected int $count;

/**
* Default config.
Expand All @@ -114,18 +115,18 @@ class ResultSet implements ResultSetInterface
*
* @var array
*/
protected $_defaultConfig = [
protected array $_defaultConfig = [
'size' => 1000,
];

/**
* Constructor.
*
* @param \Cake\ORM\Query $query Query object.
* @param \Cake\ORM\Query\SelectQuery $query Query object.
* @param array $config Configuration.
* @throws \RuntimeException When query is not supported.
*/
public function __construct(Query $query, array $config = [])
public function __construct(SelectQuery $query, array $config = [])
{
$type = $query->type();
if ($type !== 'select') {
Expand All @@ -144,17 +145,17 @@ public function __construct(Query $query, array $config = [])
/**
* @inheritDoc
*/
#[\ReturnTypeWillChange]
public function current()
#[ReturnTypeWillChange]
public function current(): mixed
{
return $this->current;
}

/**
* @inheritDoc
*/
#[\ReturnTypeWillChange]
public function key()
#[ReturnTypeWillChange]
public function key(): mixed
{
return $this->index;
}
Expand Down Expand Up @@ -215,7 +216,7 @@ public function valid(): bool
*
* @return void
*/
protected function fetchChunk()
protected function fetchChunk(): void
{
$size = $this->getConfig('size');

Expand Down Expand Up @@ -251,12 +252,12 @@ public function count(): int
*
* Serialization is not supported (yet). *
*/
public function serialize()
public function serialize(): never
{
throw new RuntimeException('You cannot serialize this result set.');
}

public function __serialize(): array
public function __serialize(): never
{
throw new RuntimeException('You cannot serialize this result set.');
}
Expand All @@ -266,12 +267,12 @@ public function __serialize(): array
*
* Serialization is not supported (yet). *
*/
public function unserialize($serialized)
public function unserialize(string $serialized): never
{
throw new RuntimeException('You cannot unserialize this result set.');
}

public function __unserialize(array $data): void
public function __unserialize(array $data): never
{
throw new RuntimeException('You cannot unserialize this result set.');
}
Expand Down
5 changes: 2 additions & 3 deletions tests/TestCase/Model/Behavior/ChunkBehaviorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
*/
namespace Robotusers\Chunk\Test\TestCase\Model\Behavior;

use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use Robotusers\Chunk\Model\Behavior\ChunkBehavior;
use Robotusers\Chunk\ORM\ResultSet;
Expand All @@ -38,13 +37,13 @@
*/
class ChunkBehaviorTest extends TestCase
{
public $fixtures = [
public array $fixtures = [
'core.Authors',
];

public function testChunk()
{
$table = TableRegistry::get('Authors');
$table = $this->getTableLocator()->get('Authors');
$query = $table->find();

$behavior = new ChunkBehavior($table);
Expand Down
Loading
Loading