Skip to content

Commit

Permalink
Switch to Github Actions for CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Nov 17, 2021
1 parent da79b22 commit 8bf4d8f
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 84 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
Expand Up @@ -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
103 changes: 103 additions & 0 deletions .github/workflows/ci.yml
@@ -0,0 +1,103 @@
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']
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@v1
with:
fetch-depth: 1

- 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
65 changes: 0 additions & 65 deletions .travis.yml

This file was deleted.

12 changes: 0 additions & 12 deletions psalm-baseline.xml

This file was deleted.

1 change: 0 additions & 1 deletion psalm.xml
Expand Up @@ -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"
>
<projectFiles>
<directory name="src" />
Expand Down
10 changes: 6 additions & 4 deletions src/Model/Behavior/SequenceBehavior.php
Expand Up @@ -337,18 +337,19 @@ 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) {
// Nothing to do if trying to move down entity already at last position
return true;
} elseif ($direction === '+') {
$previousEntity->set($orderField, $oldOrder);
if (!$table->save($previousEntity, ['atomic' => false, 'checkRules' => false])) {
return false;
}
// Nothing to do if trying to move down entity already at last position
} elseif ($direction === '+') {
return true;
}

$entity->set($orderField, $newOrder);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8bf4d8f

Please sign in to comment.