Skip to content

Commit

Permalink
Merge pull request #12 from ishanvyas22/cakephp44-upgrade
Browse files Browse the repository at this point in the history
Bump CakePHP version to 4.2
  • Loading branch information
bcrowe authored Jul 12, 2023
2 parents f5c2cae + f4e027e commit c6fd911
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 45 deletions.
125 changes: 125 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: CI

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
schedule:
- cron: "0 0 * * 0" # Runs at 00:00 UTC on Sun.

permissions:
contents: read

jobs:
#########################
# Run PHPUnit testsuite #
#########################
testsuite:

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php-versions: ['7.4', '8.0', '8.1', '8.2']
db-type: [mysql]
prefer-lowest: ['', 'prefer-lowest']

steps:
- uses: actions/checkout@v3

- name: Setup MySQL 8
if: matrix.db-type == 'mysql'
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

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Get date part for cache key
id: key-date
run: echo "date=$(date +'%Y-%m')" >> $GITHUB_OUTPUT

- name: Cache composer dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: test-${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl

- name: Install composer dependencies
run: |
if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
composer update --prefer-lowest --prefer-stable
elif ${{ matrix.php-version == '8.2' }}; then
composer update --ignore-platform-req=php
else
composer update
fi
- name: Wait for MySQL
if: matrix.db-type == 'mysql'
run: while ! `mysqladmin ping -h 127.0.0.1 --silent`; do printf 'Waiting for MySQL...\n'; sleep 2; done;

- name: Run PHPUnit testsuite
run: |
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then
export DB_URL='mysql://root:[email protected]/cakephp';
mysql -h 127.0.0.1 -u root -proot cakephp < ./tests/Schema/articles.sql
fi
vendor/bin/phpunit --stderr;
##############
# Code style #
##############
cs:

runs-on: ubuntu-latest

strategy:
matrix:
php-versions: ['7.4']

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Get date part for cache key
id: key-date
run: echo "date=$(date +'%Y-%m')" >> $GITHUB_OUTPUT

- name: Cache composer dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: cs-${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
restore-keys: |
cs-${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, intl

- name: Install composer dependencies
run: composer update --no-interaction

- name: Run CS check
run: composer cs-check
27 changes: 0 additions & 27 deletions .travis.yml

This file was deleted.

11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
],
"require": {
"php": ">=7.2",
"cakephp/cakephp": "^4.0"
"cakephp/cakephp": "^4.2"
},
"require-dev": {
"phpunit/phpunit" : "^8.5",
"phpunit/phpunit" : "^8.5.23",
"scrutinizer/ocular": "1.7",
"cakephp/cakephp-codesniffer": "~4.0.0"
"cakephp/cakephp-codesniffer": "^4.7"
},
"autoload": {
"psr-4": {
Expand All @@ -45,5 +45,10 @@
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
3 changes: 1 addition & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
</testsuites>
<listeners>
<listener
class="\Cake\TestSuite\Fixture\FixtureInjector"
file="./vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureInjector.php">
class="\Cake\TestSuite\Fixture\FixtureInjector">
<arguments>
<object class="\Cake\TestSuite\Fixture\FixtureManager" />
</arguments>
Expand Down
5 changes: 4 additions & 1 deletion src/Controller/Component/ApiPaginationComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ public function beforeRender(Event $event)

$subject = $event->getSubject();
$modelName = ucfirst($this->getConfig('model', $subject->getName()));
$this->pagingInfo = $this->getController()->getRequest()->getAttribute('paging')[$modelName];
if (isset($this->getController()->getRequest()->getAttribute('paging')[$modelName])) {
$this->pagingInfo = $this->getController()->getRequest()->getAttribute('paging')[$modelName];
}

$config = $this->getConfig();

if (!empty($config['aliases'])) {
Expand Down
7 changes: 0 additions & 7 deletions tests/Fixture/ArticlesFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ class ArticlesFixture extends TestFixture
{
public $table = 'bryancrowe_articles';

public $fields = [
'id' => ['type' => 'integer'],
'title' => ['type' => 'string', 'null' => false],
'body' => 'text',
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]],
];

public $records = [
['title' => 'Post #1', 'body' => 'This is the article body.'],
['title' => 'Post #2', 'body' => 'This is the article body.'],
Expand Down
5 changes: 5 additions & 0 deletions tests/Schema/articles.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CREATE TABLE `bryancrowe_articles` (
`id` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
`title` varchar(255) NOT NULL,
`body` text NOT NULL
);
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,10 @@ public function testVariousModelValueOnNonConventionalController(array $config,
public function dataForTestVariousModelValueOnNonConventionalController(): array
{
return [

[[], null],
[[], []],
[['model' => 'Articles'], $this->getDefaultPagination()],
[['model' => 'articles'], $this->getDefaultPagination()],
[['model' => 'NonExistingModel'], null],
[['model' => 'NonExistingModel'], []],
];
}

Expand Down
1 change: 0 additions & 1 deletion tests/test_app/TestApp/Controller/ArticlesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ class ArticlesController extends Controller
public function initialize(): void
{
parent::initialize();
$this->loadComponent('Paginator');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ class ArticlesIndexController extends Controller
public function initialize(): void
{
parent::initialize();
$this->loadComponent('Paginator');
}
}

0 comments on commit c6fd911

Please sign in to comment.