Skip to content

Commit

Permalink
PHP 8 / PHPUnit 9 (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
yoanm committed Apr 1, 2023
1 parent 03bff17 commit 670787a
Show file tree
Hide file tree
Showing 17 changed files with 436 additions and 205 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
@@ -0,0 +1,16 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4

[Makefile]
indent_style = tab
indent_size = 8

[{*.yml,*.yaml}]
indent_style = space
indent_size = 2
3 changes: 3 additions & 0 deletions .github/.editorconfig
@@ -0,0 +1,3 @@
[*.yml]
indent_style = space
indent_size = 2
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
@@ -0,0 +1 @@
* @yoanm
7 changes: 7 additions & 0 deletions .github/dependabot.yml
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: composer
directory: "/"
schedule:
interval: monthly
open-pull-requests-limit: 10
240 changes: 240 additions & 0 deletions .github/workflows/CI.yml
@@ -0,0 +1,240 @@
name: 'CI'
on: # Build any PRs and main branch changes
workflow_dispatch: # Allows to run the workflow manually from the Actions tab
pull_request:
types:
- opened
- edited
- synchronize
push:
branches: [ master ]
schedule:
- cron: '0 0 1 */6 *' # Every 6 months

concurrency:
group: "${{ github.workflow }}-${{ github.head_ref || github.ref }}"
cancel-in-progress: true

env:
TEST_OUTPUT_STYLE: pretty
CODACY_CACHE_PATH: ~/.cache/codacy
CODACY_BIN: ~/.cache/codacy/codacy.sh

jobs:
tests:
name: UTs & FTs - PHPUnit ${{ matrix.phpunit-version }}
runs-on: ubuntu-latest
env:
COVERAGE_TYPE: none
strategy:
fail-fast: true
max-parallel: 4
matrix:
include:
# Bare minimum => Lowest versions allowed by composer config
- phpunit-version: '9.0'
php-version: '8.0'
composer-flag: --prefer-lowest
# Up to date versions => Latest versions allowed by composer config
- phpunit-version: '9.0'
php-version: '8.2'
# Late phpunit migration => Lowest phpunit version with latest minor php version allowed by composer config
- phpunit-version: '9.0'
php-version: '8.2'
composer-flag: --prefer-lowest
# Late php migration => Latest phpunit version with lowest minor php version allowed by composer config
- phpunit-version: '9.0'
php-version: '8.0'
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Enable coverage
if: ${{ matrix.php-version == '8.2' }}
run: |
echo "COVERAGE_OUTPUT_STYLE=clover" >> $GITHUB_ENV
echo "COVERAGE_TYPE=xdebug" >> $GITHUB_ENV
- name: Setup PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: '${{ matrix.php-version }}'
tools: composer
coverage: xdebug # Coverage driver is mandatory to be able to use/cover StrictCoverageListener
env:
# Always use latest available patch for the version
update: true

- name: Setup cache
id: cache
uses: actions/cache@v3
with:
path: |
~/.composer
./vendor
${{ env.CODACY_CACHE_PATH }}
build/behat-code-coverage-cache
# Clear the cache if composer json (as composer.lock is in the repo) has been updated
key: tests-${{ matrix.php-version }}-${{ matrix.phpunit-version }}-${{ matrix.composer-flag }}-${{ hashFiles('composer.json') }}

- name: Download codacy binary
if: steps.cache.outputs.cache-hit != 'true'
run: |
mkdir -p ${{ env.CODACY_CACHE_PATH }} \
&& curl -LN https://coverage.codacy.com/get.sh -o ${{ env.CODACY_BIN }} \
&& chmod +x ${{ env.CODACY_BIN }} \
&& ${{ env.CODACY_BIN }} download
- name: Build
run: |
composer require -W ${{ env.COMPOSER_OPTIONS }} ${{ matrix.composer-flag }} \
phpunit/phpunit:^${{ matrix.phpunit-version }} \
&& composer update ${{ matrix.composer-flag }} \
&& make build
- name: Tests
run: make test-unit && make test-functional

# Upload to codacy first as codecov action always remove coverage files despite move_coverage_to_trash at false
# And only if it's not a PR from a fork => Can't work as codacy secret is not accessible in that context
- name: Upload coverages to Codacy
if: ${{ github.event.pull_request.head.repo.full_name == 'yoanm/PhpUnitExtended' && env.COVERAGE_TYPE == 'xdebug' }}
run: ${{ env.CODACY_BIN }} report -r build/coverage-phpunit/unit.clover -r build/coverage-behat/clover.xml -r build/coverage-phpunit/functional.clover -t ${{ secrets.CODACY_PROJECT_TOKEN }} --partial

# See the reports at https://codecov.io/gh/yoanm/PhpUnitExtended
- name: Upload unit tests coverage to codecov
if: ${{ env.COVERAGE_TYPE == 'xdebug' }}
uses: codecov/codecov-action@v3
with:
file: "build/coverage-phpunit/unit.clover"
name: "unit-tests-${{ matrix.php-version }}-${{ matrix.phpunit-version }}"
flags: "unit-tests,php-${{ matrix.php-version }},sf-${{ matrix.phpunit-version }}"
fail_ci_if_error: true
move_coverage_to_trash: false
verbose: ${{ runner.debug == '1' }}

- name: Upload functional tests coverage to codecov
if: ${{ env.COVERAGE_TYPE == 'xdebug' }}
uses: codecov/codecov-action@v3
with:
files: "build/coverage-behat/clover.xml,build/coverage-phpunit/functional.clover"
name: "functional-tests-${{ matrix.php-version }}-${{ matrix.phpunit-version }}"
flags: "functional-tests,php-${{ matrix.php-version }},sf-${{ matrix.phpunit-version }}"
fail_ci_if_error: true
move_coverage_to_trash: false
verbose: ${{ runner.debug == '1' }}

static-checks:
name: Static checks
runs-on: ubuntu-latest
needs: [ tests ]
steps:
- uses: actions/checkout@v3

- name: Setup PHP 8.2
uses: shivammathur/setup-php@v2
with:
php-version: 8.2 # Latest supported
tools: composer
coverage: none
env:
# Always use latest available patch for the version
update: true

- name: Setup cache
id: cache
uses: actions/cache@v3
with:
path: |
~/.composer
# Clear the cache if composer json (as composer.lock is in the repo) has been updated
key: tests-${{ env.PHP_VERSION }}-${{ hashFiles('composer.json') }}

- name: Build
run: make build

- name: ComposerRequireChecker
uses: docker://webfactory/composer-require-checker:3.2.0

- name: Dependencies check
if: ${{ github.event_name == 'pull_request' }}
uses: actions/dependency-review-action@v1

finalize-codacy-coverage-report:
runs-on: ubuntu-latest
name: Finalize Codacy coverage report
if: ${{ github.event.pull_request.head.repo.full_name == 'yoanm/PhpUnitExtended' }}
needs: [ tests ]
steps:
- name: Setup cache
id: cache
uses: actions/cache@v3
with:
path: |
${{ env.CODACY_CACHE_PATH }}
key: codacy-final

- name: Download codacy binary
if: steps.cache.outputs.cache-hit != 'true'
run: |
mkdir -p ${{ env.CODACY_CACHE_PATH }} \
&& curl -LN https://coverage.codacy.com/get.sh -o ${{ env.CODACY_BIN }} \
&& chmod +x ${{ env.CODACY_BIN }} \
&& ${{ env.CODACY_BIN }} download
- name: Finalize reporting
run: ${{ env.CODACY_BIN }} final -t ${{ secrets.CODACY_PROJECT_TOKEN }}

nightly-tests:
name: Nightly - PHPUnit ${{ matrix.phpunit-version }}
runs-on: ubuntu-latest
env:
COMPOSER_OPTIONS: '--optimize-autoloader --ignore-platform-req=php+'
continue-on-error: true
needs: [ static-checks, tests ]
strategy:
fail-fast: false
max-parallel: 4
matrix:
php-version:
- '8.3' # Current php dev version
phpunit-version:
#- '9.0' # Lowest supported
- '9.0' # Latest supported
include:
- phpunit-version: '10' # Next PHPunit major version to manage with latest supported PHP version
php-version: '8.2'

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Setup PHP ${{ matrix.php-version }}
uses: shivammathur/setup-php@v2
with:
php-version: '${{ matrix.php-version }}'
tools: composer
coverage: none
env:
# Always use latest available patch for the version
update: true

- name: Setup cache
id: cache
uses: actions/cache@v3
with:
path: |
~/.composer
./vendor
# Clear the cache if composer json (as composer.lock is in the repo) has been updated
key: tests-${{ matrix.php-version }}-${{ matrix.phpunit-version }}-${{ hashFiles('composer.json') }}

- name: Build
run: |
composer require -W ${{ env.COMPOSER_OPTIONS }} \
phpunit/phpunit:^${{ matrix.phpunit-version }} \
&& composer update \
&& make build
- name: Test
run: make test-unit && make test-functional
39 changes: 22 additions & 17 deletions .scrutinizer.yml
Expand Up @@ -11,22 +11,27 @@ build_failure_conditions:
build:
dependencies:
override:
- make build
- command: make build
title: Build deps
idle_timeout: 240
tests:
stop_on_failure: true
override:
- php-scrutinizer-run
-
command: make codestyle
analysis:
file: 'build/reports/cs-data'
format: 'php-cs-checkstyle'
-
command: make coverage
idle_timeout: 1200
coverage:
file: 'build/coverage/clover.xml'
format: 'php-clover'
- command: make codestyle
title: Code style
- command: make scrutinizer-phpunit
idle_timeout: 1200
coverage:
file: 'build/coverage-phpunit/scrutinizer.xml'
format: 'php-clover'
- command: make scrutinizer-behat
idle_timeout: 1200
coverage:
file: 'build/coverage-behat/clover.xml'
format: 'php-clover'
- command: php-scrutinizer-run --enable-security-analysis
title: Scrutinizer checks

cache:
directories:
- ~/.composer
Expand All @@ -36,13 +41,13 @@ build:
variables:
CI: 'true'
TEST_OUTPUT_STYLE: 'pretty'
COMPOSER_OPTIONS: '--optimize-autoloader'
COVERAGE_OUTPUT_STYLE: 'clover'
COVERAGE_CLOVER_FILE_PATH: 'build/coverage/clover.xml'
PHPCS_REPORT_STYLE: 'checkstyle'
PHPCS_REPORT_FILE: 'build/reports/cs-data'
COMPOSER_OPTIONS: '--optimize-autoloader'
php:
version: "7.1"
version: "8.2"
ini:
memory_limit: "-1"
timezone: UTC
postgresql: false
redis: false
Expand Down
26 changes: 0 additions & 26 deletions .travis.yml

This file was deleted.

0 comments on commit 670787a

Please sign in to comment.