Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust to CS fixer v3.2 rules #900

Merged
merged 5 commits into from
Oct 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 63 additions & 35 deletions .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ jobs:
type: 'CodingStyle'
- php: 'latest'
type: 'StaticAnalysis'
env:
LOG_COVERAGE: ""
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Configure PHP
run: |
if [ -n "$LOG_COVERAGE" ]; then echo "xdebug.mode=coverage" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; else rm /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini; fi
rm /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
php --version

- name: Setup cache 1/2
Expand All @@ -48,18 +46,15 @@ jobs:

- name: Install PHP dependencies
run: |
if [ "${{ matrix.type }}" != "Phpunit" ] && [ "${{ matrix.type }}" != "StaticAnalysis" ]; then composer remove --no-interaction --no-update phpunit/phpunit johnkary/phpunit-speedtrap phpunit/dbunit phpunit/phpcov --dev ; fi
if [ "${{ matrix.type }}" != "CodingStyle" ]; then composer remove --no-interaction --no-update friendsofphp/php-cs-fixer --dev && composer --no-interaction --no-update require jdorn/sql-formatter ; fi
if [ "${{ matrix.type }}" != "StaticAnalysis" ]; then composer remove --no-interaction --no-update phpstan/phpstan --dev ; fi
if [ "${{ matrix.type }}" != "Phpunit" ] && [ "${{ matrix.type }}" != "StaticAnalysis" ]; then composer remove --no-interaction --no-update phpunit/phpunit johnkary/phpunit-speedtrap phpunit/phpcov --dev; fi
if [ "${{ matrix.type }}" != "CodingStyle" ]; then composer remove --no-interaction --no-update friendsofphp/php-cs-fixer --dev && composer --no-interaction --no-update require jdorn/sql-formatter; fi
if [ "${{ matrix.type }}" != "StaticAnalysis" ]; then composer remove --no-interaction --no-update phpstan/phpstan --dev; fi
composer update --ansi --prefer-dist --no-interaction --no-progress --optimize-autoloader

- name: Init
run: |
mkdir -p build/logs

- name: "Run tests: SQLite (only for Phpunit)"
if: matrix.type == 'Phpunit'
run: "vendor/bin/phpunit \"$(if [ -n \"$LOG_COVERAGE\" ]; then echo '--coverage-text'; else echo '--no-coverage'; fi)\" -v"
if: startsWith(matrix.type, 'Phpunit')
run: |
vendor/bin/phpunit --exclude-group none --no-coverage -v

- name: "Run tests: SQLite Hintable (only for Phpunit)"
if: matrix.type == 'Phpunit'
Expand All @@ -69,12 +64,13 @@ jobs:

- name: Check Coding Style (only for CodingStyle)
if: matrix.type == 'CodingStyle'
run: vendor/bin/php-cs-fixer fix --dry-run --using-cache=no --diff --verbose
run: |
vendor/bin/php-cs-fixer fix --dry-run --using-cache=no --diff --verbose

- name: Run Static Analysis (only for StaticAnalysis)
if: matrix.type == 'StaticAnalysis'
run: |
echo "memory_limit = 1G" > /usr/local/etc/php/conf.d/custom-memory-limit.ini
echo "memory_limit = 2G" > /usr/local/etc/php/conf.d/custom-memory-limit.ini
vendor/bin/phpstan analyse

- name: Run Static Analysis with DBAL 2.x (only for StaticAnalysis)
Expand Down Expand Up @@ -102,16 +98,16 @@ jobs:
services:
mysql:
image: mysql:8
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5 -e MYSQL_ROOT_PASSWORD=atk4_pass_root -e MYSQL_USER=atk4_test -e MYSQL_PASSWORD=atk4_pass -e MYSQL_DATABASE=atk4_test__data --entrypoint sh mysql:8 -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password"
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5 -e MYSQL_ROOT_PASSWORD=atk4_pass_root -e MYSQL_USER=atk4_test -e MYSQL_PASSWORD=atk4_pass -e MYSQL_DATABASE=atk4_test --entrypoint sh mysql:8 -c "exec docker-entrypoint.sh mysqld --default-authentication-plugin=mysql_native_password"
mariadb:
image: mariadb
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5 -e MYSQL_ROOT_PASSWORD=atk4_pass_root -e MYSQL_USER=atk4_test -e MYSQL_PASSWORD=atk4_pass -e MYSQL_DATABASE=atk4_test__data
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5 -e MYSQL_ROOT_PASSWORD=atk4_pass_root -e MYSQL_USER=atk4_test -e MYSQL_PASSWORD=atk4_pass -e MYSQL_DATABASE=atk4_test
postgres:
image: postgres:12-alpine
env:
POSTGRES_USER: atk4_test
POSTGRES_PASSWORD: atk4_pass
POSTGRES_DB: atk4_test__data
POSTGRES_DB: atk4_test
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
mssql:
image: mcr.microsoft.com/mssql/server
Expand Down Expand Up @@ -146,53 +142,85 @@ jobs:

- name: Install PHP dependencies
run: |
if [ "${{ matrix.type }}" != "Phpunit" ] && [ "${{ matrix.type }}" != "Phpunit Lowest" ] && [ "${{ matrix.type }}" != "Phpunit Burn" ]; then composer remove --no-interaction --no-update phpunit/phpunit johnkary/phpunit-speedtrap phpunit/dbunit phpunit/phpcov --dev ; fi
if [ "${{ matrix.type }}" != "CodingStyle" ]; then composer remove --no-interaction --no-update friendsofphp/php-cs-fixer --dev && composer --no-update --ansi --prefer-dist --no-interaction --no-progress require jdorn/sql-formatter ; fi
if [ "${{ matrix.type }}" != "StaticAnalysis" ]; then composer remove --no-interaction --no-update phpstan/phpstan --dev ; fi
if [ "${{ matrix.type }}" != "Phpunit" ] && [ "${{ matrix.type }}" != "Phpunit Lowest" ] && [ "${{ matrix.type }}" != "Phpunit Burn" ]; then composer remove --no-interaction --no-update phpunit/phpunit johnkary/phpunit-speedtrap phpunit/phpcov --dev; fi
if [ "${{ matrix.type }}" != "CodingStyle" ]; then composer remove --no-interaction --no-update friendsofphp/php-cs-fixer --dev && composer --no-update --ansi --prefer-dist --no-interaction --no-progress require jdorn/sql-formatter; fi
if [ "${{ matrix.type }}" != "StaticAnalysis" ]; then composer remove --no-interaction --no-update phpstan/phpstan --dev; fi
composer update --ansi --prefer-dist --no-interaction --no-progress --optimize-autoloader
if [ "${{ matrix.type }}" == "Phpunit Lowest" ]; then composer update --ansi --prefer-dist --prefer-lowest --prefer-stable --no-interaction --no-progress --optimize-autoloader ; fi
if [ "${{ matrix.type }}" == "Phpunit Burn" ]; then sed -i 's/ *public function runBare(): void/public function runBare(): void { gc_collect_cycles(); gc_collect_cycles(); $mem0 = memory_get_usage(); for ($i = 0; $i < '"$(if [ \"$GITHUB_EVENT_NAME\" == \"schedule\" ]; then echo 50; else echo 5; fi)"'; ++$i) { $this->_runBare(); gc_collect_cycles(); gc_collect_cycles(); if ($i === 0) { $mem1 = memory_get_usage(); } } $mem2 = memory_get_usage(); if ($mem2 - 3072 * 1024 > $mem0 || $mem2 > $mem1) { $this->onNotSuccessfulTest(new AssertionFailedError("Memory leak detected! (" . round($mem0 \/ (1024 * 1024), 3) . " MB + " . round(($mem1 - $mem0) \/ (1024 * 1024), 3) . " MB + " . round(($mem2 - $mem1) \/ 1024, 3) . " KB, " . $i . " iterations)")); } } private function _runBare(): void/' vendor/phpunit/phpunit/src/Framework/TestCase.php && cat vendor/phpunit/phpunit/src/Framework/TestCase.php | grep '_runBare(' ; fi
if [ "${{ matrix.type }}" == "Phpunit Lowest" ]; then composer update --ansi --prefer-dist --prefer-lowest --prefer-stable --no-interaction --no-progress --optimize-autoloader; fi
if [ "${{ matrix.type }}" == "Phpunit Burn" ]; then sed -i 's~ *public function runBare(): void~public function runBare(): void { gc_collect_cycles(); gc_collect_cycles(); $memDiffs = array_fill(0, '"$(if [ \"$GITHUB_EVENT_NAME\" == \"schedule\" ]; then echo 64; else echo 16; fi)"', 0); for ($i = -1; $i < count($memDiffs); ++$i) { $this->_runBare(); gc_collect_cycles(); gc_collect_cycles(); $mem = memory_get_usage(); if ($i !== -1) { $memDiffs[$i] = $mem - $memPrev; } $memPrev = $mem; rsort($memDiffs); if (array_sum($memDiffs) >= 4096 * 1024 || $memDiffs[2] > 0) { $this->onNotSuccessfulTest(new AssertionFailedError( "Memory leak detected! (" . implode(" + ", array_map(fn ($v) => number_format($v / 1024, 3, ".", " "), array_filter($memDiffs))) . " KB, " . ($i + 2) . " iterations)" )); } } } private function _runBare(): void~' vendor/phpunit/phpunit/src/Framework/TestCase.php && cat vendor/phpunit/phpunit/src/Framework/TestCase.php | grep '_runBare('; fi

- name: Init
run: |
mkdir -p build/logs
php -r '(new PDO("mysql:host=mysql", "root", "atk4_pass_root"))->exec("ALTER USER '"'"'atk4_test'"'"'@'"'"'%'"'"' WITH MAX_USER_CONNECTIONS 5");'
php -r '(new PDO("mysql:host=mariadb", "root", "atk4_pass_root"))->exec("ALTER USER '"'"'atk4_test'"'"'@'"'"'%'"'"' WITH MAX_USER_CONNECTIONS 5");'
php -r '(new PDO("pgsql:host=postgres;dbname=atk4_test__data", "atk4_test", "atk4_pass"))->exec("ALTER ROLE atk4_test CONNECTION LIMIT 1");'
php -r '(new PDO("pgsql:host=postgres;dbname=atk4_test", "atk4_test", "atk4_pass"))->exec("ALTER ROLE atk4_test CONNECTION LIMIT 1");'
if [ -n "$LOG_COVERAGE" ]; then mkdir coverage; fi

- name: "Run tests: SQLite (only for Phpunit)"
if: startsWith(matrix.type, 'Phpunit')
run: "vendor/bin/phpunit \"$(if [ -n \"$LOG_COVERAGE\" ]; then echo '--coverage-text'; else echo '--no-coverage'; fi)\" -v"
run: |
php -d opcache.enable_cli=1 vendor/bin/phpunit --exclude-group none $(if [ -n "$LOG_COVERAGE" ]; then echo --coverage-text; else echo --no-coverage; fi) -v
if [ -n "$LOG_COVERAGE" ]; then mv coverage/phpunit.cov coverage/phpunit-sqlite.cov; fi

- name: "Run tests: MySQL (only for Phpunit)"
if: startsWith(matrix.type, 'Phpunit')
run: "vendor/bin/phpunit --configuration phpunit-mysql.xml.dist \"$(if [ -n \"$LOG_COVERAGE\" ]; then echo '--coverage-text'; else echo '--no-coverage'; fi)\" -v"
env:
DB_DSN: "mysql:host=mysql;dbname=atk4_test"
DB_USER: atk4_test
DB_PASSWD: atk4_pass
run: |
php -d opcache.enable_cli=1 vendor/bin/phpunit --exclude-group none $(if [ -n "$LOG_COVERAGE" ]; then echo --coverage-text; else echo --no-coverage; fi) -v
if [ -n "$LOG_COVERAGE" ]; then mv coverage/phpunit.cov coverage/phpunit-mysql.cov; fi

- name: "Run tests: MariaDB (only for Phpunit)"
if: startsWith(matrix.type, 'Phpunit')
run: "vendor/bin/phpunit --configuration phpunit-mariadb.xml.dist \"$(if [ -n \"$LOG_COVERAGE\" ]; then echo '--coverage-text'; else echo '--no-coverage'; fi)\" -v"
env:
DB_DSN: "mysql:host=mariadb;dbname=atk4_test"
DB_USER: atk4_test
DB_PASSWD: atk4_pass
run: |
php -d opcache.enable_cli=1 vendor/bin/phpunit --exclude-group none $(if [ -n "$LOG_COVERAGE" ]; then echo --coverage-text; else echo --no-coverage; fi) -v
if [ -n "$LOG_COVERAGE" ]; then mv coverage/phpunit.cov coverage/phpunit-mariadb.cov; fi

- name: "Run tests: PostgreSQL (only for Phpunit)"
if: startsWith(matrix.type, 'Phpunit')
run: "vendor/bin/phpunit --configuration phpunit-pgsql.xml.dist \"$(if [ -n \"$LOG_COVERAGE\" ]; then echo '--coverage-text'; else echo '--no-coverage'; fi)\" -v"
env:
DB_DSN: "pgsql:host=postgres;dbname=atk4_test"
DB_USER: atk4_test
DB_PASSWD: atk4_pass
run: |
php -d opcache.enable_cli=1 vendor/bin/phpunit --exclude-group none $(if [ -n "$LOG_COVERAGE" ]; then echo --coverage-text; else echo --no-coverage; fi) -v
if [ -n "$LOG_COVERAGE" ]; then mv coverage/phpunit.cov coverage/phpunit-postgres.cov; fi

- name: "Run tests: MSSQL (only for Phpunit)"
if: startsWith(matrix.type, 'Phpunit')
run: "vendor/bin/phpunit --configuration phpunit-mssql.xml.dist \"$(if [ -n \"$LOG_COVERAGE\" ]; then echo '--coverage-text'; else echo '--no-coverage'; fi)\" -v"
env:
DB_DSN: "sqlsrv:Server=mssql;Database=master"
DB_USER: sa
DB_PASSWD: atk4_pass
run: |
php -d opcache.enable_cli=1 vendor/bin/phpunit --exclude-group none $(if [ -n "$LOG_COVERAGE" ]; then echo --coverage-text; else echo --no-coverage; fi) -v
if [ -n "$LOG_COVERAGE" ]; then mv coverage/phpunit.cov coverage/phpunit-mssql.cov; fi

- name: "Run tests: Oracle (only for Phpunit)"
if: startsWith(matrix.type, 'Phpunit')
run: "vendor/bin/phpunit --configuration phpunit-oracle.xml.dist \"$(if [ -n \"$LOG_COVERAGE\" ]; then echo '--coverage-text'; else echo '--no-coverage'; fi)\" -v"
env:
DB_DSN: "oci:dbname=oracle/xe;charset=UTF8"
DB_USER: system
DB_PASSWD: oracle
run: |
php -d opcache.enable_cli=1 vendor/bin/phpunit --exclude-group none $(if [ -n "$LOG_COVERAGE" ]; then echo --coverage-text; else echo --no-coverage; fi) -v
if [ -n "$LOG_COVERAGE" ]; then mv coverage/phpunit.cov coverage/phpunit-oracle.cov; fi

- name: Upload coverage logs 1/2 (only for "latest" Phpunit)
- name: Upload coverage logs 1/2 (only for latest Phpunit)
if: env.LOG_COVERAGE
run: |
echo "memory_limit = 1G" > /usr/local/etc/php/conf.d/custom-memory-limit.ini
vendor/bin/phpcov merge build/logs/ --clover build/logs/cc.xml
ls -l coverage | wc -l
php -d memory_limit=2G vendor/bin/phpcov merge coverage/ --clover coverage/merged.xml

- name: Upload coverage logs 2/2 (only for "latest" Phpunit)
- name: Upload coverage logs 2/2 (only for latest Phpunit)
if: env.LOG_COVERAGE
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: build/logs/cc.xml
file: coverage/merged.xml
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
docs/build
/build
/docs/build
/coverage
/vendor
/composer.lock
.idea
nbproject
.vscode
.DS_Store

local
Expand All @@ -14,4 +15,3 @@ cache
*.cache.*

/phpunit.xml
/phpunit-*.xml
24 changes: 0 additions & 24 deletions phpunit-mariadb.xml.dist

This file was deleted.

24 changes: 0 additions & 24 deletions phpunit-mssql.xml.dist

This file was deleted.

24 changes: 0 additions & 24 deletions phpunit-mysql.xml.dist

This file was deleted.

24 changes: 0 additions & 24 deletions phpunit-oracle.xml.dist

This file was deleted.

24 changes: 0 additions & 24 deletions phpunit-pgsql.xml.dist

This file was deleted.

3 changes: 1 addition & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<var name="DB_DSN" value="sqlite::memory:" />
<var name="DB_USER" value="" />
<var name="DB_PASSWD" value="" />
<var name="DB_DBNAME" value="" />
</php>
<testsuites>
<testsuite name="tests">
Expand All @@ -18,7 +17,7 @@
<directory suffix=".php">src</directory>
</include>
<report>
<php outputFile="build/logs/clover.cov" />
<php outputFile="coverage/phpunit.cov" />
</report>
</coverage>
</phpunit>
2 changes: 1 addition & 1 deletion src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ public function saveAndUnload(array $data = [])
*/
public function withPersistence(Persistence $persistence, $id = null, string $class = null)
{
$class = $class ?? static::class;
$class ??= static::class;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is new syntax, right? Never noticed it before.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shorthand by php, needed for default cs fixer config


/** @var self $model */
$model = new $class($persistence, ['table' => $this->table]);
Expand Down
4 changes: 2 additions & 2 deletions src/Persistence/Sql/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public static function normalizeDsn($dsn, $user = null, $pass = null)
$dsn = $parts['scheme'] . ':host=' . $parts['host']
. (isset($parts['port']) ? ';port=' . $parts['port'] : '')
. ';dbname=' . substr($parts['path'], 1);
$user = $user ?? ($parts['user'] ?? null);
$pass = $pass ?? ($parts['pass'] ?? null);
$user ??= $parts['user'] ?? null;
$pass ??= $parts['pass'] ?? null;
}

// If it's still array, then simply use it
Expand Down
Loading