Skip to content

Commit 34075ca

Browse files
authored
Merge pull request #194 from kevindecapite/issue-193
Prepare for CakePHP 5.x
2 parents 0d8856e + a67d5be commit 34075ca

File tree

53 files changed

+689
-697
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+689
-697
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ on:
1010

1111
jobs:
1212
testsuite:
13-
runs-on: ubuntu-22.04
13+
runs-on: ubuntu-24.04
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
php-version: [ '7.4', '8.0', '8.1' ]
17+
php-version: [ '8.1', '8.2', '8.3', '8.4' ]
1818
db-type: [ mysql ]
1919
prefer-lowest: ['']
2020
include:
21-
- php-version: '7.4'
21+
- php-version: '8.1'
2222
db-type: 'mysql'
2323
prefer-lowest: 'prefer-lowest'
2424

@@ -49,7 +49,7 @@ jobs:
4949
run: echo "::set-output name=date::$(date +'%Y-%m')"
5050

5151
- name: Cache composer dependencies
52-
uses: actions/cache@v3
52+
uses: actions/cache@v4
5353
with:
5454
path: ${{ steps.composer-cache.outputs.dir }}
5555
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}
@@ -62,35 +62,22 @@ jobs:
6262
composer update
6363
fi
6464
65-
- name: Configure PHPUnit matcher
66-
if: matrix.php-version == '7.4' && matrix.db-type == 'mysql'
67-
uses: mheap/phpunit-matcher-action@v1
68-
6965
- name: Run PHPUnit
7066
run: |
71-
if [[ ${{ matrix.db-type }} == 'mysql' && ${{ matrix.php-version }} != '7.2' ]]; then export DB_URL='mysql://root:[email protected]/cakephp?init[]=SET sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"'; fi
72-
if [[ ${{ matrix.db-type }} == 'mysql' && ${{ matrix.php-version }} == '7.2' ]]; then export DB_URL='mysql://root:[email protected]/cakephp?encoding=utf8'; fi
73-
if [[ ${{ matrix.db-type }} == 'mysql' && ${{ matrix.php-version }} == '7.4' ]]; then
74-
vendor/bin/phpunit --coverage-clover=coverage.xml --verbose
75-
else
76-
vendor/bin/phpunit
77-
fi
78-
79-
- name: Code Coverage Report
80-
if: success() && matrix.php-version == '7.4' && matrix.db-type == 'mysql'
81-
uses: codecov/codecov-action@v3
67+
export DB_URL='mysql://root:[email protected]/cakephp?init[]=SET sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"'
68+
vendor/bin/phpunit --display-incomplete --display-skipped --display-warnings --display-deprecations
8269
8370
coding-standard:
8471
name: Coding Standard
85-
runs-on: ubuntu-22.04
72+
runs-on: ubuntu-24.04
8673

8774
steps:
8875
- uses: actions/checkout@v3
8976

9077
- name: Setup PHP
9178
uses: shivammathur/setup-php@v2
9279
with:
93-
php-version: '7.4'
80+
php-version: '8.1'
9481
extensions: mbstring, intl, apcu
9582
coverage: none
9683

@@ -103,7 +90,7 @@ jobs:
10390
run: echo "::set-output name=date::$(date +'%Y-%m')"
10491

10592
- name: Cache composer dependencies
106-
uses: actions/cache@v3
93+
uses: actions/cache@v4
10794
with:
10895
path: ${{ steps.composer-cache.outputs.dir }}
10996
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}
@@ -116,15 +103,15 @@ jobs:
116103

117104
static-analysis:
118105
name: Static Analysis
119-
runs-on: ubuntu-22.04
106+
runs-on: ubuntu-24.04
120107

121108
steps:
122109
- uses: actions/checkout@v3
123110

124111
- name: Setup PHP
125112
uses: shivammathur/setup-php@v2
126113
with:
127-
php-version: '7.4'
114+
php-version: '8.1'
128115
extensions: mbstring, intl, apcu
129116
coverage: none
130117
tools: cs2pr
@@ -138,16 +125,13 @@ jobs:
138125
run: echo "::set-output name=date::$(date +'%Y-%m')"
139126

140127
- name: Cache composer dependencies
141-
uses: actions/cache@v1
128+
uses: actions/cache@v4
142129
with:
143130
path: ${{ steps.composer-cache.outputs.dir }}
144131
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}
145132

146133
- name: composer install
147134
run: composer stan-setup
148135

149-
- name: Run psalm
150-
run: vendor/bin/psalm.phar --output-format=github
151-
152136
- name: Run phpstan
153137
run: vendor/bin/phpstan.phar analyse --error-format=checkstyle ./src | cs2pr

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ vendor/
55
composer.lock
66
tmp
77
.phpunit.result.cache
8+
.phpunit.cache

composer.json

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,17 @@
2929
}
3030
],
3131
"require": {
32-
"php": ">=7.4.0",
33-
"cakephp/cakephp": "^4.4.1",
34-
"friendsofcake/crud": "^6.0",
35-
"laravel-json-api/neomerx-json-api": "^5.0"
32+
"php": ">=8.1.0",
33+
"cakephp/cakephp": "^5.0.0",
34+
"friendsofcake/crud": "^7.2.0",
35+
"laravel-json-api/neomerx-json-api": "^5.0.2"
3636
},
3737
"require-dev": {
38-
"phpunit/phpunit": "~8.5 || ^9.3",
39-
"friendsofcake/cakephp-test-utilities": "^2.0.1",
40-
"friendsofcake/search": "^6.2.2",
41-
"cakephp/cakephp-codesniffer": "^4.0",
42-
"dms/phpunit-arraysubset-asserts": "^0.4.0"
38+
"phpunit/phpunit": "^10.5.5 || ^11.1.3 || ^12.0.9",
39+
"friendsofcake/cakephp-test-utilities": "^3.0.0",
40+
"friendsofcake/search": "^7.0.0",
41+
"cakephp/cakephp-codesniffer": "^5.1",
42+
"dms/phpunit-arraysubset-asserts": "^0.5.0"
4343
},
4444
"autoload": {
4545
"psr-4": {
@@ -65,13 +65,8 @@
6565
"scripts": {
6666
"cs-check": "phpcs -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
6767
"cs-fix": "phpcbf --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/",
68-
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:~1.8.0 psalm/phar:~4.26.0 && mv composer.backup composer.json",
68+
"stan-setup": "cp composer.json composer.backup && composer require --dev phpstan/phpstan:~2.1.17 && mv composer.backup composer.json",
6969
"phpstan": "phpstan analyse --memory-limit=3G src/",
70-
"psalm": "psalm.phar --show-info=false",
71-
"stan": [
72-
"@phpstan",
73-
"@psalm"
74-
],
7570
"test": "phpunit"
7671
},
7772
"config": {

phpstan-baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,3 @@ parameters:
99
message: "#^Access to an undefined property Cake\\\\Controller\\\\Controller\\:\\:\\$Crud\\.$#"
1010
count: 1
1111
path: src/Listener/PaginationListener.php
12-
13-
-
14-
message: "#^Call to an undefined method Cake\\\\Datasource\\\\EntityInterface\\:\\:visibleProperties\\(\\)\\.$#"
15-
count: 1
16-
path: src/Schema/JsonApi/DynamicEntitySchema.php

phpstan.neon

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ parameters:
55
level: 6
66
paths:
77
- src
8-
checkMissingIterableValueType: false
9-
checkGenericClassInNonGenericObjectType: false
108
universalObjectCratesClasses:
119
- Crud\Event\Subject
1210
bootstrapFiles:
1311
- vendor/cakephp/cakephp/src/Core/Exception/CakeException.php
12+
ignoreErrors:
13+
- identifier: missingType.iterableValue
14+
- identifier: missingType.generics

phpunit.xml.dist

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,24 @@
1+
<?xml version="1.0"?>
12
<phpunit
2-
colors="true"
3-
processIsolation="false"
4-
stopOnFailure="false"
5-
bootstrap="./tests/bootstrap.php">
6-
7-
<testsuites>
8-
<testsuite name="Crud">
9-
<directory>./tests/</directory>
10-
</testsuite>
11-
</testsuites>
12-
13-
<listeners>
14-
<listener class="\Cake\TestSuite\Fixture\FixtureInjector">
15-
<arguments>
16-
<object class="\Cake\TestSuite\Fixture\FixtureManager" />
17-
</arguments>
18-
</listener>
19-
</listeners>
20-
21-
<filter>
22-
<whitelist>
23-
<directory suffix=".php">./src/</directory>
24-
<directory suffix=".ctp">./src/</directory>
25-
</whitelist>
26-
</filter>
27-
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
colors="true"
5+
processIsolation="false"
6+
stopOnFailure="false"
7+
bootstrap="./tests/bootstrap.php"
8+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
9+
cacheDirectory=".phpunit.cache"
10+
>
11+
<extensions>
12+
<bootstrap class="Cake\TestSuite\Fixture\Extension\PHPUnitExtension"/>
13+
</extensions>
14+
<testsuites>
15+
<testsuite name="Crud">
16+
<directory>./tests/</directory>
17+
</testsuite>
18+
</testsuites>
19+
<source>
20+
<include>
21+
<directory suffix=".php">./src/</directory>
22+
</include>
23+
</source>
2824
</phpunit>

psalm.xml

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

src/Action/RelationshipsAction.php

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
use Crud\Traits\SerializeTrait;
2222
use Crud\Traits\ViewTrait;
2323
use Crud\Traits\ViewVarTrait;
24+
use function Cake\Core\pluginSplit;
25+
use function Cake\I18n\__;
2426

2527
/**
2628
* Class RelationshipViewAction
@@ -47,7 +49,7 @@ class RelationshipsAction extends BaseAction
4749
*
4850
* @var array
4951
*/
50-
protected $_defaultConfig = [
52+
protected array $_defaultConfig = [
5153
'enabled' => true,
5254
'scope' => 'entity',
5355
'findMethod' => 'all',
@@ -150,7 +152,7 @@ public function checkAllowed(): void
150152
protected function _findRelations(Subject $subject): EntityInterface
151153
{
152154
$relationName = $this->_request()->getParam('type');
153-
$table = $this->_table();
155+
$table = $this->_controller()->fetchTable();
154156
$association = $table->getAssociation($relationName);
155157
$targetTable = $association->getTarget();
156158

@@ -188,7 +190,7 @@ protected function _findRelations(Subject $subject): EntityInterface
188190
->where(
189191
[
190192
$table->aliasField($primaryKey) => $foreignKeyParam,
191-
]
193+
],
192194
)
193195
->contain([
194196
$relationName => [
@@ -202,7 +204,7 @@ protected function _findRelations(Subject $subject): EntityInterface
202204
'association' => $association,
203205
'repository' => $table,
204206
'query' => $primaryQuery,
205-
]
207+
],
206208
);
207209
$this->_trigger('beforeFind', $subject);
208210
$entity = $subject->query->first();
@@ -239,7 +241,7 @@ protected function _get(): void
239241
*
240242
* @return void
241243
*/
242-
protected function _delete()
244+
protected function _delete(): void
243245
{
244246
$subject = $this->_subject();
245247
$request = $this->_request();
@@ -272,7 +274,7 @@ protected function _delete()
272274
$idsToDelete = (array)Hash::extract($data, '{n}.id');
273275
$foreignRecords = $entity->$property;
274276
$entity->$property = [];
275-
foreach ($foreignRecords as $key => $foreignRecord) {
277+
foreach ($foreignRecords as $foreignRecord) {
276278
if (!in_array($foreignRecord->id, $idsToDelete, false)) {
277279
$entity->{$property}[] = $foreignRecord;
278280
}
@@ -284,7 +286,7 @@ protected function _delete()
284286
$association->setSaveStrategy('replace');
285287
}
286288
$saveMethod = $this->saveMethod();
287-
if ($this->_table()->$saveMethod($entity, $this->saveOptions())) {
289+
if ($this->_controller()->fetchTable()->$saveMethod($entity, $this->saveOptions())) {
288290
$this->_success($subject);
289291

290292
return;
@@ -298,7 +300,7 @@ protected function _delete()
298300
*
299301
* @return void
300302
*/
301-
protected function _post()
303+
protected function _post(): void
302304
{
303305
$subject = $this->_subject();
304306
$request = $this->_request();
@@ -333,7 +335,7 @@ protected function _post()
333335
$this->_trigger('beforeSave', $subject);
334336

335337
$saveMethod = $this->saveMethod();
336-
if ($this->_table()->$saveMethod($entity, $this->saveOptions())) {
338+
if ($this->_controller()->fetchTable()->$saveMethod($entity, $this->saveOptions())) {
337339
$this->_success($subject);
338340

339341
return;
@@ -347,7 +349,7 @@ protected function _post()
347349
*
348350
* @return void
349351
*/
350-
protected function _patch()
352+
protected function _patch(): void
351353
{
352354
$subject = $this->_subject();
353355
$request = $this->_request();
@@ -363,7 +365,6 @@ protected function _patch()
363365

364366
if (in_array($association->type(), [Association::MANY_TO_ONE, Association::ONE_TO_ONE], true)) {
365367
//Set the relationship to the corresponding entity
366-
/** @psalm-suppress TypeDoesNotContainNull */
367368
if (array_key_exists('id', $data)) {
368369
$entity->{$property} = $foreignTable->get($data['id']);
369370
} elseif ($data === null) {
@@ -382,7 +383,7 @@ protected function _patch()
382383
$association->setSaveStrategy('replace');
383384
}
384385
$saveMethod = $this->saveMethod();
385-
if ($this->_table()->$saveMethod($entity, $this->saveOptions())) {
386+
if ($this->_controller()->fetchTable()->$saveMethod($entity, $this->saveOptions())) {
386387
$this->_success($subject);
387388

388389
return;
@@ -442,21 +443,21 @@ protected function getForeignRecords(array $data, Association $association): arr
442443
->where(
443444
[
444445
$association->aliasField($associationPrimaryKey) . ' in' => $idsToAdd,
445-
]
446+
],
446447
)
447448
->all();
448449

449450
if (count($idsToAdd) !== count($foreignRecords)) {
450451
$foundIds = $foreignRecords->extract(
451452
static function ($record) {
452453
return $record->id;
453-
}
454+
},
454455
)
455456
->toArray();
456457
$missingIds = array_diff($idsToAdd, $foundIds);
457458

458459
throw new RecordNotFoundException(
459-
__('Not all requested records could be found. Missing IDs are {0}', implode(', ', $missingIds))
460+
__('Not all requested records could be found. Missing IDs are {0}', implode(', ', $missingIds)),
460461
);
461462
}
462463

0 commit comments

Comments
 (0)