From f4e027e9bd9ad3c03f1d78d5f4d3befb1f910f41 Mon Sep 17 00:00:00 2001 From: Ishan Vyas Date: Wed, 12 Jul 2023 10:55:03 +0530 Subject: [PATCH] Bump CakePHP version to 4.2 --- .github/workflows/ci.yml | 125 ++++++++++++++++++ .travis.yml | 27 ---- composer.json | 11 +- phpunit.xml.dist | 3 +- .../Component/ApiPaginationComponent.php | 5 +- tests/Fixture/ArticlesFixture.php | 7 - tests/Schema/articles.sql | 5 + ...entOnNonConventionalControllerNameTest.php | 5 +- .../TestApp/Controller/ArticlesController.php | 1 - .../Controller/ArticlesIndexController.php | 1 - 10 files changed, 145 insertions(+), 45 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml create mode 100644 tests/Schema/articles.sql diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e0a2d31 --- /dev/null +++ b/.github/workflows/ci.yml @@ -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:root@127.0.0.1/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 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index b4c3966..0000000 --- a/.travis.yml +++ /dev/null @@ -1,27 +0,0 @@ -language: php - -env: - global: - - PHPCS=0 - - RUN_TESTS=1 - -php: - - 7.3 - -sudo: false - -matrix: - include: - - php: 7.2 - env: PHPCS=1 RUN_TESTS=0 - -before_script: - - travis_retry composer self-update - - travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source - -script: - - sh -c "if [ '$RUN_TESTS' = '1' ]; then vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover; fi" - - sh -c "if [ '$PHPCS' = '1' ]; then vendor/bin/phpcs -p ./src ./tests; fi" - -after_script: - - if [[ $TRAVIS_PHP_VERSION != 'hhvm' && $TRAVIS_PHP_VERSION != '7.0' ]]; then php vendor/bin/ocular code-coverage:upload --format=php-clover coverage.clover; fi diff --git a/composer.json b/composer.json index 5de9c1f..f492cf4 100644 --- a/composer.json +++ b/composer.json @@ -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": { @@ -45,5 +45,10 @@ "branch-alias": { "dev-master": "1.0-dev" } + }, + "config": { + "allow-plugins": { + "dealerdirect/phpcodesniffer-composer-installer": true + } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 1136eba..5ce9bef 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -16,8 +16,7 @@ + class="\Cake\TestSuite\Fixture\FixtureInjector"> diff --git a/src/Controller/Component/ApiPaginationComponent.php b/src/Controller/Component/ApiPaginationComponent.php index 34057a8..bdf4168 100644 --- a/src/Controller/Component/ApiPaginationComponent.php +++ b/src/Controller/Component/ApiPaginationComponent.php @@ -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'])) { diff --git a/tests/Fixture/ArticlesFixture.php b/tests/Fixture/ArticlesFixture.php index d241bc2..dca49ce 100644 --- a/tests/Fixture/ArticlesFixture.php +++ b/tests/Fixture/ArticlesFixture.php @@ -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.'], diff --git a/tests/Schema/articles.sql b/tests/Schema/articles.sql new file mode 100644 index 0000000..0d3baf8 --- /dev/null +++ b/tests/Schema/articles.sql @@ -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 +); diff --git a/tests/TestCase/Controller/Component/ApiPaginationComponentOnNonConventionalControllerNameTest.php b/tests/TestCase/Controller/Component/ApiPaginationComponentOnNonConventionalControllerNameTest.php index 39a6c67..d158cfc 100644 --- a/tests/TestCase/Controller/Component/ApiPaginationComponentOnNonConventionalControllerNameTest.php +++ b/tests/TestCase/Controller/Component/ApiPaginationComponentOnNonConventionalControllerNameTest.php @@ -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'], []], ]; } diff --git a/tests/test_app/TestApp/Controller/ArticlesController.php b/tests/test_app/TestApp/Controller/ArticlesController.php index 428e94c..bc2f5cd 100644 --- a/tests/test_app/TestApp/Controller/ArticlesController.php +++ b/tests/test_app/TestApp/Controller/ArticlesController.php @@ -10,6 +10,5 @@ class ArticlesController extends Controller public function initialize(): void { parent::initialize(); - $this->loadComponent('Paginator'); } } diff --git a/tests/test_app/TestApp/Controller/ArticlesIndexController.php b/tests/test_app/TestApp/Controller/ArticlesIndexController.php index a999113..45822d9 100644 --- a/tests/test_app/TestApp/Controller/ArticlesIndexController.php +++ b/tests/test_app/TestApp/Controller/ArticlesIndexController.php @@ -10,6 +10,5 @@ class ArticlesIndexController extends Controller public function initialize(): void { parent::initialize(); - $this->loadComponent('Paginator'); } }