Skip to content

Commit f4e027e

Browse files
committed
Bump CakePHP version to 4.2
1 parent f5c2cae commit f4e027e

File tree

10 files changed

+145
-45
lines changed

10 files changed

+145
-45
lines changed

Diff for: .github/workflows/ci.yml

+125
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
schedule:
9+
- cron: "0 0 * * 0" # Runs at 00:00 UTC on Sun.
10+
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
#########################
16+
# Run PHPUnit testsuite #
17+
#########################
18+
testsuite:
19+
20+
runs-on: ubuntu-latest
21+
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
php-versions: ['7.4', '8.0', '8.1', '8.2']
26+
db-type: [mysql]
27+
prefer-lowest: ['', 'prefer-lowest']
28+
29+
steps:
30+
- uses: actions/checkout@v3
31+
32+
- name: Setup MySQL 8
33+
if: matrix.db-type == 'mysql'
34+
run: docker run --rm --name=mysqld -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=cakephp -p 3306:3306 -d mysql:8 --default-authentication-plugin=mysql_native_password --disable-log-bin
35+
36+
- name: Validate composer.json and composer.lock
37+
run: composer validate --strict
38+
39+
- name: Get composer cache directory
40+
id: composer-cache
41+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
42+
43+
- name: Get date part for cache key
44+
id: key-date
45+
run: echo "date=$(date +'%Y-%m')" >> $GITHUB_OUTPUT
46+
47+
- name: Cache composer dependencies
48+
uses: actions/cache@v3
49+
with:
50+
path: ${{ steps.composer-cache.outputs.dir }}
51+
key: test-${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
52+
53+
- name: Setup PHP
54+
uses: shivammathur/setup-php@v2
55+
with:
56+
php-version: ${{ matrix.php-versions }}
57+
extensions: mbstring, intl
58+
59+
- name: Install composer dependencies
60+
run: |
61+
if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
62+
composer update --prefer-lowest --prefer-stable
63+
elif ${{ matrix.php-version == '8.2' }}; then
64+
composer update --ignore-platform-req=php
65+
else
66+
composer update
67+
fi
68+
69+
- name: Wait for MySQL
70+
if: matrix.db-type == 'mysql'
71+
run: while ! `mysqladmin ping -h 127.0.0.1 --silent`; do printf 'Waiting for MySQL...\n'; sleep 2; done;
72+
73+
- name: Run PHPUnit testsuite
74+
run: |
75+
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then
76+
export DB_URL='mysql://root:[email protected]/cakephp';
77+
mysql -h 127.0.0.1 -u root -proot cakephp < ./tests/Schema/articles.sql
78+
fi
79+
vendor/bin/phpunit --stderr;
80+
81+
##############
82+
# Code style #
83+
##############
84+
cs:
85+
86+
runs-on: ubuntu-latest
87+
88+
strategy:
89+
matrix:
90+
php-versions: ['7.4']
91+
92+
steps:
93+
- name: Checkout
94+
uses: actions/checkout@v3
95+
96+
- name: Validate composer.json and composer.lock
97+
run: composer validate --strict
98+
99+
- name: Get composer cache directory
100+
id: composer-cache
101+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
102+
103+
- name: Get date part for cache key
104+
id: key-date
105+
run: echo "date=$(date +'%Y-%m')" >> $GITHUB_OUTPUT
106+
107+
- name: Cache composer dependencies
108+
uses: actions/cache@v3
109+
with:
110+
path: ${{ steps.composer-cache.outputs.dir }}
111+
key: cs-${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
112+
restore-keys: |
113+
cs-${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
114+
115+
- name: Setup PHP
116+
uses: shivammathur/setup-php@v2
117+
with:
118+
php-version: ${{ matrix.php-versions }}
119+
extensions: mbstring, intl
120+
121+
- name: Install composer dependencies
122+
run: composer update --no-interaction
123+
124+
- name: Run CS check
125+
run: composer cs-check

Diff for: .travis.yml

-27
This file was deleted.

Diff for: composer.json

+8-3
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
],
1818
"require": {
1919
"php": ">=7.2",
20-
"cakephp/cakephp": "^4.0"
20+
"cakephp/cakephp": "^4.2"
2121
},
2222
"require-dev": {
23-
"phpunit/phpunit" : "^8.5",
23+
"phpunit/phpunit" : "^8.5.23",
2424
"scrutinizer/ocular": "1.7",
25-
"cakephp/cakephp-codesniffer": "~4.0.0"
25+
"cakephp/cakephp-codesniffer": "^4.7"
2626
},
2727
"autoload": {
2828
"psr-4": {
@@ -45,5 +45,10 @@
4545
"branch-alias": {
4646
"dev-master": "1.0-dev"
4747
}
48+
},
49+
"config": {
50+
"allow-plugins": {
51+
"dealerdirect/phpcodesniffer-composer-installer": true
52+
}
4853
}
4954
}

Diff for: phpunit.xml.dist

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
</testsuites>
1717
<listeners>
1818
<listener
19-
class="\Cake\TestSuite\Fixture\FixtureInjector"
20-
file="./vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php">
19+
class="\Cake\TestSuite\Fixture\FixtureInjector">
2120
<arguments>
2221
<object class="\Cake\TestSuite\Fixture\FixtureManager" />
2322
</arguments>

Diff for: src/Controller/Component/ApiPaginationComponent.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ public function beforeRender(Event $event)
4646

4747
$subject = $event->getSubject();
4848
$modelName = ucfirst($this->getConfig('model', $subject->getName()));
49-
$this->pagingInfo = $this->getController()->getRequest()->getAttribute('paging')[$modelName];
49+
if (isset($this->getController()->getRequest()->getAttribute('paging')[$modelName])) {
50+
$this->pagingInfo = $this->getController()->getRequest()->getAttribute('paging')[$modelName];
51+
}
52+
5053
$config = $this->getConfig();
5154

5255
if (!empty($config['aliases'])) {

Diff for: tests/Fixture/ArticlesFixture.php

-7
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@ class ArticlesFixture extends TestFixture
77
{
88
public $table = 'bryancrowe_articles';
99

10-
public $fields = [
11-
'id' => ['type' => 'integer'],
12-
'title' => ['type' => 'string', 'null' => false],
13-
'body' => 'text',
14-
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]],
15-
];
16-
1710
public $records = [
1811
['title' => 'Post #1', 'body' => 'This is the article body.'],
1912
['title' => 'Post #2', 'body' => 'This is the article body.'],

Diff for: tests/Schema/articles.sql

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CREATE TABLE `bryancrowe_articles` (
2+
`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
3+
`title` varchar(255) NOT NULL,
4+
`body` text NOT NULL
5+
);

Diff for: tests/TestCase/Controller/Component/ApiPaginationComponentOnNonConventionalControllerNameTest.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,10 @@ public function testVariousModelValueOnNonConventionalController(array $config,
7474
public function dataForTestVariousModelValueOnNonConventionalController(): array
7575
{
7676
return [
77-
78-
[[], null],
77+
[[], []],
7978
[['model' => 'Articles'], $this->getDefaultPagination()],
8079
[['model' => 'articles'], $this->getDefaultPagination()],
81-
[['model' => 'NonExistingModel'], null],
80+
[['model' => 'NonExistingModel'], []],
8281
];
8382
}
8483

Diff for: tests/test_app/TestApp/Controller/ArticlesController.php

-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ class ArticlesController extends Controller
1010
public function initialize(): void
1111
{
1212
parent::initialize();
13-
$this->loadComponent('Paginator');
1413
}
1514
}

Diff for: tests/test_app/TestApp/Controller/ArticlesIndexController.php

-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ class ArticlesIndexController extends Controller
1010
public function initialize(): void
1111
{
1212
parent::initialize();
13-
$this->loadComponent('Paginator');
1413
}
1514
}

0 commit comments

Comments
 (0)