Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Normalize Unit Testing workflow across repos #53

Merged
merged 21 commits into from
Apr 28, 2020
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
77 changes: 55 additions & 22 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,92 @@ name: Unit Testing

on:
pull_request:
branches: '*'
branches: '**'
push:
branches:
- master
- develop
branches: '**'
schedule:
- cron: '0 */6 * * *'

jobs:
unit-test:
name: Unit Testing
name: Unit
runs-on: ubuntu-latest
container:
image: atk4/image:${{ matrix.php }} # https://github.com/atk4/image
strategy:
fail-fast: false
matrix:
php: ['7.2', '7.3', 'latest']
type: ['Phpunit']
include:
- php: 'latest'
type: 'CodingStyle'
env:
LOG_COVERAGE: "${{ fromJSON('{true: \"1\", false: \"\"}')[matrix.php == 'latest' && matrix.type == 'Phpunit' && (github.event_name == 'pull_request' || (github.event_name == 'push' && (github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/master')))] }}"
services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: password
DB_DATABASE: dsql_test
MYSQL_ROOT_PASSWORD: atk4_pass
MYSQL_USER: atk4_test
MYSQL_PASSWORD: atk4_pass
MYSQL_DATABASE: atk4_test__schema
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=5
steps:
- uses: actions/checkout@v2
- run: php --version
- name: Get Composer Cache Directory
- name: Checkout
uses: actions/checkout@v2

- name: Configure PHP
run: |
if [ -z "$LOG_COVERAGE" ]; then rm /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini ; fi
php --version

- name: Setup cache 1/2
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v1

- name: Setup cache 2/2
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('composer.json') }}
key: ${{ runner.os }}-composer-${{ matrix.php }}-${{ matrix.type }}-${{ hashFiles('composer.json') }}
restore-keys: |
${{ runner.os }}-composer-

- run: composer install --no-progress --no-suggest --prefer-dist --optimize-autoloader
- name: Install PHP dependencies
run: |
if [ "${{ matrix.type }}" != "Phpunit" ]; then composer remove --no-interaction --no-update phpunit/phpunit phpunit/phpcov --dev ; fi
if [ "${{ matrix.type }}" != "CodingStyle" ]; then composer remove --no-interaction --no-update friendsofphp/php-cs-fixer --dev ; fi
composer install --no-suggest --ansi --prefer-dist --no-interaction --no-progress --optimize-autoloader

- name: Run Tests
- name: Init
run: |
mkdir -p build/logs
mysql -uroot -ppassword -h mysql -e 'CREATE DATABASE dsql_test;'
- name: SQLite Testing
run: vendor/bin/phpunit --configuration phpunit.xml --coverage-text --exclude-group dns

- name: MySQL Testing
run: vendor/bin/phpunit --configuration phpunit-mysql-workflow.xml --exclude-group dns
- 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"

- name: "Run tests: MySQL (only for Phpunit)"
if: 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"

- name: Lint / check syntax (only for CodingStyle)
if: matrix.type == 'CodingStyle'
run: find . \( -type d \( -path './vendor/*' \) \) -prune -o ! -type d -name '*.php' -print0 | xargs -0 -n1 php -l

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

- name: Merge coverage logs
run: vendor/bin/phpcov merge build/logs/ --clover build/logs/cc.xml;
- name: Upload coverage logs 1/2 (only for "latest" Phpunit)
if: env.LOG_COVERAGE
run: vendor/bin/phpcov merge build/logs/ --clover build/logs/cc.xml

- uses: codecov/codecov-action@v1
- 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
15 changes: 13 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
/composer.lock
docs/build
/build
/vendor
/composer.lock
.idea
nbproject
.DS_Store
/.idea/

local
*.local
*.local.*
cache
*.cache
*.cache.*

/phpunit.xml
/phpunit-mysql.xml
51 changes: 0 additions & 51 deletions .old.travis.yml

This file was deleted.

57 changes: 57 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in([__DIR__])
->exclude([
'cache',
'build',
'vendor',
]);

return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@PhpCsFixer' => true,
'@PhpCsFixer:risky' =>true,
'@PHP71Migration:risky' => true,

// required by PSR-12
'concat_space' => [
'spacing' => 'one',
],

// disable some too strict rules
'phpdoc_types_order' => [
'null_adjustment' => 'always_last',
'sort_algorithm' => 'none',
],
'single_line_throw' => false,
'yoda_style' => [
'equal' => false,
'identical' => false,
],
'native_function_invocation' => false,
'non_printable_character' => [
'use_escape_sequences_in_strings' => true,
],
'declare_strict_types' => false,
'void_return' => false,
'combine_consecutive_issets' => false,
'combine_consecutive_unsets' => false,
'multiline_whitespace_before_semicolons' => false,
'no_superfluous_elseif' => false,
'ordered_class_elements' => false,
'php_unit_internal_class' => false,
'php_unit_test_case_static_method_calls' => [
'call_type' => 'this',
],
'php_unit_test_class_requires_covers' => false,
'phpdoc_add_missing_param_annotation' => false,
'return_assignment' => false,
'comment_to_phpdoc' => false,
'nullable_type_declaration_for_default_null_value' => [
'use_nullable_type_declaration' => false,
],
])
->setFinder($finder)
->setCacheFile(__DIR__ . '/.php_cs.cache');
17 changes: 17 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ignore:
- demos
- docs
- tests
- tools
coverage:
precision: 2
round: down
range: "40...100" # lower coverage expectations
status:
project:
default:
threshold: 1% # lower coverage diff threshold, but maybe is not working
target: 100
target: 40
patch: yes
changes: no
23 changes: 14 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
"minimum-stability": "dev",
"prefer-stable": true,
"authors": [
{
"name": "Romans Malinovskis",
"email": "romans@agiletoolkit.org",
"homepage": "https://nearly.guru/"
}
{"name": "Romans Malinovskis", "email": "romans@agiletoolkit.org", "homepage": "https://nearly.guru/" },
{"name": "Imants Horsts", "homepage": "https://darkside.lv/"},
{"name": "Francesco Danti", "homepage": "https://oracoltech.com/"},
{"name": "Michael Voříšek", "homepage": "https://mvorisek.cz/"},
{"name": "Georgi Hristov", "homepage": "https://xsystems.io/"}
],
"config": {
"sort-packages": true
},
"require": {
"php": ">=7.2.0",
"atk4/data": "dev-develop"
Expand All @@ -32,13 +35,15 @@
},
"require-dev": {
"atk4/ui": "dev-develop",
"phpunit/phpunit": "*",
"phpunit/phpcov": "*"
"friendsofphp/php-cs-fixer": "^2.16",
"phpunit/phpcov": "*",
"phpunit/phpunit": "*"
},
"require-dev-release": {
"atk4/ui": "^2.0",
"phpunit/phpunit": "*",
"phpunit/phpcov": "*"
"friendsofphp/php-cs-fixer": "^2.16",
"phpunit/phpcov": "*",
"phpunit/phpunit": "*"
},
"suggest": {
"atk4/ui": "dev-develop",
Expand Down
2 changes: 1 addition & 1 deletion demos/modelmigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function init(): void
// ok, now we surely have DB!

$user->save([
'name' => 'John' . rand(1, 100),
'name' => 'John' . random_int(1, 100),
]);
} catch (\atk4\core\Exception $e) {
echo $e->getColorfulText();
Expand Down
21 changes: 0 additions & 21 deletions phpunit-mysql.xml

This file was deleted.

8 changes: 4 additions & 4 deletions phpunit-mysql-workflow.xml → phpunit-mysql.xml.dist
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<phpunit colors="true" bootstrap="vendor/autoload.php" printerClass="atk4\core\AtkPhpunit\ResultPrinter">
<php>
<var name="DB_DSN" value="mysql:dbname=dsql_test;host=mysql" />
<var name="DB_USER" value="root" />
<var name="DB_PASSWD" value="password" />
<var name="DB_DBNAME" value="dsql_test" />
<var name="DB_DSN" value="mysql:dbname=atk4_test__schema;host=mysql" />
<var name="DB_USER" value="atk4_test" />
<var name="DB_PASSWD" value="atk4_pass" />
<var name="DB_DBNAME" value="atk4_test__schema" />
</php>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
Expand Down
8 changes: 3 additions & 5 deletions phpunit.xml → phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<phpunit colors="true" bootstrap="vendor/autoload.php" printerClass="atk4\core\AtkPhpunit\ResultPrinter">
<php>
<!-- By default will use sqlite:memory
<var name="DB_DSN" value="mysql:dbname=dsql_test;host=localhost" />
<var name="DB_USER" value="travis" />
<var name="DB_DSN" value="sqlite::memory:" />
<var name="DB_USER" value="" />
<var name="DB_PASSWD" value="" />
<var name="DB_DBNAME" value="dsql_test" />
-->
<var name="DB_DBNAME" value="" />
</php>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
Expand Down
Loading