From fb36598d838ffb50cd0680522b73d105d084e7af Mon Sep 17 00:00:00 2001 From: ADmad Date: Wed, 17 Nov 2021 13:36:04 +0530 Subject: [PATCH] Switch to Github Actions for CI --- .gitattributes | 3 +- .github/workflows/ci.yml | 101 ++++++++++++++++++++++++ .travis.yml | 65 --------------- README.md | 2 +- psalm-baseline.xml | 12 --- psalm.xml | 1 - src/Model/Behavior/SequenceBehavior.php | 4 +- tests/bootstrap.php | 5 ++ 8 files changed, 111 insertions(+), 82 deletions(-) create mode 100644 .github/workflows/ci.yml delete mode 100644 .travis.yml delete mode 100644 psalm-baseline.xml diff --git a/.gitattributes b/.gitattributes index 345e7b5..ae1b776 100644 --- a/.gitattributes +++ b/.gitattributes @@ -2,8 +2,7 @@ .editorconfig export-ignore .gitattributes export-ignore .gitignore export-ignore +.github export-ignore phpunit.xml.dist export-ignore -.travis.yml export-ignore tests export-ignore psalm.xml export-ignore -psalm-baseline.xml export-ignore diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7f6e6fa --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,101 @@ +name: CI + +on: + push: + branches: + - master + pull_request: + branches: + - '*' + +jobs: + testsuite: + runs-on: ubuntu-18.04 + strategy: + fail-fast: false + matrix: + php-version: ['7.4', '8.0', '8.1'] + db-type: [mysql, pgsql] + prefer-lowest: [''] + include: + - php-version: '7.2' + db-type: 'sqlite' + prefer-lowest: 'prefer-lowest' + + services: + postgres: + image: postgres + ports: + - 5432:5432 + env: + POSTGRES_PASSWORD: postgres + + steps: + - uses: actions/checkout@v2 + + - name: Setup Service + if: matrix.db-type == 'mysql' + run: | + sudo service mysql start + mysql -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE cakephp;' + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + extensions: mbstring, intl, pdo_${{ matrix.db-type }} + coverage: pcov + + - name: Composer install + run: | + composer --version + if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then + composer update --prefer-lowest --prefer-stable + else + composer install + fi + + - name: Run PHPUnit + run: | + if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then export DB_URL='sqlite:///:memory:'; fi + if [[ ${{ matrix.db-type }} == 'mysql' ]]; then export DB_URL='mysql://root:root@127.0.0.1/cakephp?init[]=SET sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"'; fi + if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:postgres@127.0.0.1/postgres'; fi + + if [[ ${{ matrix.php-version }} == '7.4' && ${{ matrix.db-type }} == 'mysql' ]]; then + vendor/bin/phpunit --coverage-clover=coverage.xml + else + vendor/bin/phpunit + fi + + - name: Code Coverage Report + if: success() && matrix.php-version == '7.4' && matrix.db-type == 'mysql' + uses: codecov/codecov-action@v2 + + cs-stan: + name: Coding Standard & Static Analysis + runs-on: ubuntu-18.04 + + steps: + - uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '7.4' + extensions: mbstring, intl + coverage: none + tools: psalm:4.4, phpstan:1.0 + + - name: Composer Install + run: composer require cakephp/cakephp-codesniffer:^4.2 + + - name: Run phpcs + run: vendor/bin/phpcs --standard=CakePHP src/ tests/ + + - name: Run psalm + if: success() || failure() + run: psalm --output-format=github + + - name: Run phpstan + if: success() || failure() + run: phpstan analyse src diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 096b9a8..0000000 --- a/.travis.yml +++ /dev/null @@ -1,65 +0,0 @@ -language: php - -php: - - 7.2 - - 7.4 - -services: - - mysql - - postgresql - -env: - matrix: - - DB=mysql db_dsn='mysql://root@127.0.0.1/cakephp_test' - - DB=pgsql db_dsn='postgres://postgres@127.0.0.1/cakephp_test' - - DB=sqlite db_dsn='sqlite:///:memory:' - - global: - - DEFAULT=1 - -matrix: - fast_finish: true - - include: - - php: 7.2 - env: PHPCS=1 DEFAULT=0 - - - php: 7.2 - env: STATIC_ANALYSIS=1 DEFAULT=0 - - - php: 7.2 - env: PREFER_LOWEST=1 - -before_script: - - phpenv config-rm xdebug.ini - - - if [[ $PREFER_LOWEST != 1 ]]; then composer update --no-interaction; fi - - if [[ $PREFER_LOWEST == 1 ]]; then composer update --no-interaction --prefer-lowest --prefer-stable; fi - - - if [[ $DB = 'mysql' ]]; then mysql -e 'CREATE DATABASE cakephp_test;'; fi - - if [[ $DB = 'pgsql' ]]; then psql -c 'CREATE DATABASE cakephp_test;' -U postgres; fi - - - if [[ $PHPCS = 1 ]]; then composer require cakephp/cakephp-codesniffer:^4.0; fi - -script: - - | - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.2 ]]; then - mkdir -p build/logs - vendor/bin/phpunit --coverage-clover=build/logs/clover.xml - fi - - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION != 7.2 ]]; then vendor/bin/phpunit; fi - - - if [[ $PHPCS = 1 ]]; then vendor/bin/phpcs -p --standard=vendor/cakephp/cakephp-codesniffer/CakePHP ./src ./tests; fi - - - if [[ $STATIC_ANALYSIS = 1 ]]; then composer require --dev psalm/phar:^3.7 && vendor/bin/psalm.phar src; fi - -after_success: - - | - if [[ $DEFAULT = 1 && $TRAVIS_PHP_VERSION = 7.2 ]]; then - wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar - chmod +x php-coveralls.phar - ./php-coveralls.phar - fi - -notifications: - email: false diff --git a/README.md b/README.md index 425feae..efdb9a7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Sequence plugin to maintain ordered list of records -[![Build Status](https://img.shields.io/travis/ADmad/cakephp-sequence/master.svg?style=flat-square)](https://travis-ci.org/ADmad/cakephp-sequence) +[![Build Status](https://img.shields.io/github/workflow/status/ADmad/cakephp-sequence/CI/master?style=flat-square)](https://github.com/ADmad/cakephp-sequence/actions/workflows/ci.yml) [![Coverage](https://img.shields.io/codecov/c/github/ADmad/cakephp-sequence.svg?style=flat-square)](https://codecov.io/github/ADmad/cakephp-sequence) [![Total Downloads](https://img.shields.io/packagist/dt/admad/cakephp-sequence.svg?style=flat-square)](https://packagist.org/packages/admad/cakephp-sequence) [![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE.txt) diff --git a/psalm-baseline.xml b/psalm-baseline.xml deleted file mode 100644 index f0838bd..0000000 --- a/psalm-baseline.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - $previousEntity - $this->_table->getPrimaryKey() - - - set - - - diff --git a/psalm.xml b/psalm.xml index b6d0e95..163cdb8 100644 --- a/psalm.xml +++ b/psalm.xml @@ -4,7 +4,6 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd" - errorBaseline="psalm-baseline.xml" > diff --git a/src/Model/Behavior/SequenceBehavior.php b/src/Model/Behavior/SequenceBehavior.php index fdf6d35..8e723f3 100644 --- a/src/Model/Behavior/SequenceBehavior.php +++ b/src/Model/Behavior/SequenceBehavior.php @@ -337,11 +337,12 @@ function ($connection) use ($table, $entity, $config, $scope, $direction) { $newOrder = $entity->get($orderField) + 1; } + /** @var \Cake\Datasource\EntityInterface|null $previousEntity */ $previousEntity = $table->find() ->where(array_merge($scope, [$orderField => $newOrder])) ->first(); - if (!empty($previousEntity)) { + if ($previousEntity !== null) { $previousEntity->set($orderField, $oldOrder); if (!$table->save($previousEntity, ['atomic' => false, 'checkRules' => false])) { return false; @@ -445,6 +446,7 @@ protected function _getOldValues(EntityInterface $entity): array } if (count($fields) != count($values)) { + /** @psalm-suppress PossiblyInvalidArgument */ $primaryKey = $entity->get($this->_table->getPrimaryKey()); $entity = $this->_table->get($primaryKey, ['fields' => $fields]); $values = $entity->extract($fields); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 76c2ba1..77078cc 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -5,6 +5,7 @@ * Test suite bootstrap for Sequence */ +use Cake\Core\Configure; use Cake\Datasource\ConnectionManager; /* @@ -36,3 +37,7 @@ require dirname(__DIR__) . '/vendor/cakephp/cakephp/tests/bootstrap.php'; ConnectionManager::get('test')->getDriver()->enableAutoQuoting(true); + +Configure::write('Error.ignoredDeprecationPaths', [ + 'src/TestSuite/Fixture/FixtureInjector.php', +]);