Skip to content

Commit 4569de1

Browse files
Merge pull request #4 from robotusers/0.3
Cake 5 support
2 parents e85924d + 207df3a commit 4569de1

File tree

12 files changed

+103
-101
lines changed

12 files changed

+103
-101
lines changed

.github/workflows/php.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ jobs:
3939
run: vendor/bin/phpstan analyse
4040

4141
- name: Run tests
42-
run: vendor/bin/phpunit --coverage-clover=coverage.xml
42+
run: vendor/bin/phpunit

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
/vendor
44
/composer.lock
55
/nbproject
6-
/phpunit.xml
76
/coverage.xml
87
.phpunit.*
8+
test.sqlite

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
"type": "cakephp-plugin",
66
"license": "MIT",
77
"require": {
8-
"cakephp/orm": "~4.0"
8+
"cakephp/orm": "~5.0"
99
},
1010
"require-dev": {
11-
"cakephp/cakephp": "~4.0",
12-
"cakephp/cakephp-codesniffer": "^4.0",
13-
"phpunit/phpunit": "^9.5",
11+
"cakephp/cakephp": "~5.0",
12+
"cakephp/cakephp-codesniffer": "^5.0",
13+
"phpunit/phpunit": "^10.0",
1414
"phpstan/phpstan": "^2.0"
1515
},
1616
"autoload": {

phpstan.neon

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
parameters:
2-
level: 4
3-
# reportUnmatchedIgnoredErrors: false
4-
# treatPhpDocTypesAsCertain: false
2+
level: 8
53
paths:
6-
- src/
7-
- tests/
4+
- src/
5+
ignoreErrors:
6+
-
7+
identifier: missingType.generics
8+
-
9+
identifier: missingType.iterableValue

phpunit.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit
4+
colors="true"
5+
processIsolation="false"
6+
stopOnFailure="false"
7+
bootstrap="./tests/bootstrap.php"
8+
>
9+
<testsuites>
10+
<testsuite name="Chunk Plugin Test Suite">
11+
<directory>./tests/TestCase/</directory>
12+
</testsuite>
13+
</testsuites>
14+
<extensions>
15+
<bootstrap class="Cake\TestSuite\Fixture\Extension\PHPUnitExtension"/>
16+
</extensions>
17+
</phpunit>

phpunit.xml.dist

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/Model/Behavior/ChunkBehavior.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@
2727
namespace Robotusers\Chunk\Model\Behavior;
2828

2929
use Cake\ORM\Behavior;
30-
use Cake\ORM\Query;
30+
use Cake\ORM\Query\SelectQuery;
3131
use Robotusers\Chunk\ORM\ResultSet;
3232

3333
class ChunkBehavior extends Behavior
3434
{
3535
/**
3636
* Returns chunked result set.
3737
*
38-
* @param \Cake\ORM\Query $query Query instance.
38+
* @param \Cake\ORM\Query\SelectQuery $query Query instance.
3939
* @param array $config Config.
4040
* @return \Robotusers\Chunk\ORM\ResultSet
4141
*/
42-
public function chunk(Query $query, array $config = [])
42+
public function chunk(SelectQuery $query, array $config = []): ResultSet
4343
{
4444
return new ResultSet($query, $config);
4545
}

src/ORM/ResultSet.php

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
use Cake\Collection\CollectionTrait;
3030
use Cake\Core\InstanceConfigTrait;
3131
use Cake\Datasource\ResultSetInterface;
32-
use Cake\ORM\Query;
32+
use Cake\ORM\Query\SelectQuery;
33+
use ReturnTypeWillChange;
3334
use RuntimeException;
3435

3536
class ResultSet implements ResultSetInterface
@@ -42,70 +43,70 @@ class ResultSet implements ResultSetInterface
4243
*
4344
* @var mixed
4445
*/
45-
protected $current;
46+
protected mixed $current;
4647

4748
/**
4849
* Query instance.
4950
*
50-
* @var \Cake\ORM\Query
51+
* @var \Cake\ORM\Query\SelectQuery
5152
*/
52-
protected $query;
53+
protected SelectQuery $query;
5354

5455
/**
5556
* Current chunk size.
5657
*
5758
* @var int
5859
*/
59-
protected $chunkSize = 0;
60+
protected int $chunkSize = 0;
6061

6162
/**
6263
* Current chunk index.
6364
*
6465
* @var int
6566
*/
66-
protected $chunkIndex = 0;
67+
protected int $chunkIndex = 0;
6768

6869
/**
6970
* Current chunk content.
7071
*
71-
* @var array
72+
* @var array<int, mixed>
7273
*/
73-
protected $chunk;
74+
protected array $chunk;
7475

7576
/**
7677
* Current element index.
7778
*
7879
* @var int
7980
*/
80-
protected $index = 0;
81+
protected int $index = 0;
8182

8283
/**
8384
* Current page.
8485
*
8586
* @var int
8687
*/
87-
protected $page = 0;
88+
protected int $page = 0;
8889

8990
/**
9091
* Original query offset.
9192
*
92-
* @var int
93+
* @var ?int
9394
*/
94-
protected $offset;
95+
protected ?int $offset;
9596

9697
/**
9798
* Original query limit.
9899
*
99-
* @var int
100+
* @var ?int
100101
*/
101-
protected $limit;
102+
protected ?int $limit;
102103

103104
/**
104105
* Total count.
105106
*
106107
* @var int
107108
*/
108-
protected $count;
109+
protected int $count;
109110

110111
/**
111112
* Default config.
@@ -114,18 +115,18 @@ class ResultSet implements ResultSetInterface
114115
*
115116
* @var array
116117
*/
117-
protected $_defaultConfig = [
118+
protected array $_defaultConfig = [
118119
'size' => 1000,
119120
];
120121

121122
/**
122123
* Constructor.
123124
*
124-
* @param \Cake\ORM\Query $query Query object.
125+
* @param \Cake\ORM\Query\SelectQuery $query Query object.
125126
* @param array $config Configuration.
126127
* @throws \RuntimeException When query is not supported.
127128
*/
128-
public function __construct(Query $query, array $config = [])
129+
public function __construct(SelectQuery $query, array $config = [])
129130
{
130131
$type = $query->type();
131132
if ($type !== 'select') {
@@ -144,17 +145,17 @@ public function __construct(Query $query, array $config = [])
144145
/**
145146
* @inheritDoc
146147
*/
147-
#[\ReturnTypeWillChange]
148-
public function current()
148+
#[ReturnTypeWillChange]
149+
public function current(): mixed
149150
{
150151
return $this->current;
151152
}
152153

153154
/**
154155
* @inheritDoc
155156
*/
156-
#[\ReturnTypeWillChange]
157-
public function key()
157+
#[ReturnTypeWillChange]
158+
public function key(): mixed
158159
{
159160
return $this->index;
160161
}
@@ -215,7 +216,7 @@ public function valid(): bool
215216
*
216217
* @return void
217218
*/
218-
protected function fetchChunk()
219+
protected function fetchChunk(): void
219220
{
220221
$size = $this->getConfig('size');
221222

@@ -251,12 +252,12 @@ public function count(): int
251252
*
252253
* Serialization is not supported (yet). *
253254
*/
254-
public function serialize()
255+
public function serialize(): never
255256
{
256257
throw new RuntimeException('You cannot serialize this result set.');
257258
}
258259

259-
public function __serialize(): array
260+
public function __serialize(): never
260261
{
261262
throw new RuntimeException('You cannot serialize this result set.');
262263
}
@@ -266,12 +267,12 @@ public function __serialize(): array
266267
*
267268
* Serialization is not supported (yet). *
268269
*/
269-
public function unserialize($serialized)
270+
public function unserialize(string $serialized): never
270271
{
271272
throw new RuntimeException('You cannot unserialize this result set.');
272273
}
273274

274-
public function __unserialize(array $data): void
275+
public function __unserialize(array $data): never
275276
{
276277
throw new RuntimeException('You cannot unserialize this result set.');
277278
}

tests/TestCase/Model/Behavior/ChunkBehaviorTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
*/
2727
namespace Robotusers\Chunk\Test\TestCase\Model\Behavior;
2828

29-
use Cake\ORM\TableRegistry;
3029
use Cake\TestSuite\TestCase;
3130
use Robotusers\Chunk\Model\Behavior\ChunkBehavior;
3231
use Robotusers\Chunk\ORM\ResultSet;
@@ -38,13 +37,13 @@
3837
*/
3938
class ChunkBehaviorTest extends TestCase
4039
{
41-
public $fixtures = [
40+
public array $fixtures = [
4241
'core.Authors',
4342
];
4443

4544
public function testChunk()
4645
{
47-
$table = TableRegistry::get('Authors');
46+
$table = $this->getTableLocator()->get('Authors');
4847
$query = $table->find();
4948

5049
$behavior = new ChunkBehavior($table);

0 commit comments

Comments
 (0)