Skip to content

Commit

Permalink
Rework testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromegamez committed Feb 18, 2020
1 parent f0d783f commit a906f9b
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 112 deletions.
188 changes: 76 additions & 112 deletions .github/workflows/tests.yml
Expand Up @@ -5,39 +5,47 @@ on:

jobs:
# Overview:
# - unit-tests
# - static-code-analysis
# - coding-standards
# - tests (unit tests, static code analysis, coding standards)
# - integration-tests (with code coverage, needs the above)
unit-tests:
name: Unit Tests (PHP ${{matrix.php}}, ${{matrix.os}})
runs-on: ${{matrix.os}}-latest
tests:
name: PHP ${{matrix.php}}
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"

strategy:
matrix:
php: ["7.0", "7.1", "7.2", "7.3", "7.4"]
os: [ubuntu, windows]
exclude:
- os: windows
php: 7.1
- os: windows
php: 7.2
- os: windows
php: 7.3
- os: windows
php: 7.4

env:
extensions: ctype, dom, grpc, json, mbstring, openssl, xml, zip, zlib
key: cache-v2 # can be any string, change to clear the extension cache.

steps:
- name: Checkout code
uses: actions/checkout@v1
uses: actions/checkout@v2

- name: Setup cache environment
id: cache-env
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.extensions }}
key: ${{ env.key }}

- name: Cache extensions
uses: actions/cache@v1
with:
path: ${{ steps.cache-env.outputs.dir }}
key: ${{ steps.cache-env.outputs.key }}
restore-keys: ${{ steps.cache-env.outputs.key }}

- name: Setup PHP
uses: shivammathur/setup-php@v1
uses: shivammathur/setup-php@v2
with:
php-version: ${{matrix.php}}
extensions: ctype, dom, json, mbstring, openssl, xml, zip, zlib
coverage: none
php-version: ${{ matrix.php }}
extensions: ${{ env.extensions }}
tools: composer, pecl
coverage: xdebug

- name: Get Composer Cache Directory
id: composer-cache
Expand All @@ -46,12 +54,9 @@ jobs:
- name: Cache dependencies
uses: actions/cache@v1
with:
path: ${{steps.composer-cache.outputs.dir}}
key: ${{matrix.php}}-${{runner.os}}-unit-tests-composer-${{hashFiles('**/composer.json')}}
restore-keys: ${{matrix.php}}-${{runner.os}}-unit-tests-composer-

- name: Setup Problem Matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies (stable)
if: "matrix.php != '7.0'"
Expand All @@ -61,95 +66,57 @@ jobs:
if: "matrix.php == '7.0'"
run: composer update --prefer-lowest --prefer-dist --no-interaction --no-suggest --no-progress

- name: Run PHPUnit
run: vendor/bin/phpunit --testsuite=unit

static-code-analysis:
name: Static Code Analysis
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"

steps:
- name: Checkout code
uses: actions/checkout@v1

- name: Setup PHP
uses: shivammathur/setup-php@v1
with:
php-version: 7.4
extensions: ctype, dom, json, mbstring, openssl, xml, zip, zlib, grpc
tools: composer, pecl
coverage: none

- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ${{steps.composer-cache.outputs.dir}}
key: ${{matrix.php}}-${{runner.os}}-static-code-analysis-composer-${{hashFiles('**/composer.json')}}
restore-keys: ${{matrix.php}}-${{runner.os}}-static-code-analysis-composer-

- name: Install dependencies
run: |
composer install --prefer-dist --no-interaction --no-suggest --no-progress
composer require google/cloud-firestore:^1.8
- name: Setup Problem Matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Run PHPStan
if: "matrix.php == '7.4'"
run: vendor/bin/phpstan analyse src tests -c phpstan.neon --level=max --no-progress

coding-standards:
name: Coding Standards
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"

steps:
- name: Checkout code
uses: actions/checkout@v1

- name: Setup PHP
uses: shivammathur/setup-php@v1
with:
php-version: 7.4
extensions: ctype, dom, json, mbstring, openssl, xml, zip, zlib
coverage: none

- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ${{steps.composer-cache.outputs.dir}}
key: ${{matrix.php}}-${{runner.os}}-coding-standards-composer-${{hashFiles('**/composer.json')}}
restore-keys: ${{matrix.php}}-${{runner.os}}-coding-standards-composer-

- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-suggest --no-progress

- name: Run PHP CS Fixer
if: "matrix.php == '7.4'"
run: vendor/bin/php-cs-fixer fix --config=.php_cs.dist -v --dry-run --stop-on-violation --using-cache=no

- name: Run PHPUnit
run: vendor/bin/phpunit --testsuite=unit

integration-tests:
name: Integration Tests with Code Coverage
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
needs: [unit-tests, coding-standards, static-code-analysis]
needs: [tests]

env:
php-version: '7.4'
extensions: ctype, dom, grpc, json, mbstring, openssl, xml, zip, zlib
key: cache-integration-v2 # can be any string, change to clear the extension cache.

steps:
- name: Checkout code
uses: actions/checkout@v1
uses: actions/checkout@v2
with:
fetch-depth: 0 # A truncated git history might mess with sonarcloud's blame data

- name: Setup cache environment
id: cache-env
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ env.php-version }}
extensions: ${{ env.extensions }}
key: ${{ env.key }}

- name: Cache extensions
uses: actions/cache@v1
with:
path: ${{ steps.cache-env.outputs.dir }}
key: ${{ steps.cache-env.outputs.key }}
restore-keys: ${{ steps.cache-env.outputs.key }}

- name: Setup PHP
uses: shivammathur/setup-php@v1
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
extensions: ctype, dom, json, mbstring, openssl, xml, zip, zlib, grpc
php-version: ${{ env.php-version }}
extensions: ${{ env.extensions }}
tools: composer, pecl
coverage: xdebug

Expand All @@ -160,32 +127,29 @@ jobs:
- name: Cache dependencies
uses: actions/cache@v1
with:
path: ${{steps.composer-cache.outputs.dir}}
key: ${{matrix.php}}-${{runner.os}}-integration-tests-composer-${{hashFiles('**/composer.json')}}
restore-keys: ${{matrix.php}}-${{runner.os}}-integration-tests-composer-
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --prefer-dist --no-interaction --no-suggest --no-progress

- name: Setup Problem Matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Install dependencies
run: |
composer install --prefer-dist --no-interaction --no-suggest --no-progress
composer require google/cloud-firestore:^1.8
- name: Run Integration Tests with Code Coverage
env:
FIREBASE_CREDENTIALS: ${{secrets.FIREBASE_CREDENTIALS}}
TEST_REGISTRATION_TOKENS: ${{secrets.TEST_REGISTRATION_TOKENS}}
run: vendor/bin/phpunit --coverage-clover=coverage.xml --log-junit=test-report.xml

# The current sonarcloud github action doesn't process the coverage report correctly
# - name: Upload reports to sonarcloud
# uses: sonarsource/sonarcloud-github-action@master
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# The current sonarcloud github action doesn't process the coverage report correctly
# - name: Upload reports to sonarcloud
# uses: sonarsource/sonarcloud-github-action@master
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

# CodeCov is used for reports on pull requests (to be seen how this works)
- name: Upload coverage to CodeCov
uses: codecov/codecov-action@v1
with:
Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -10,9 +10,12 @@ Interact with [Google Firebase](https://firebase.google.com) from your PHP appli
[![Discord](https://img.shields.io/discord/523866370778333184.svg?color=7289da&logo=discord)](https://discord.gg/nbgVfty)

[![Tests](https://github.com/kreait/firebase-php/workflows/Tests/badge.svg?branch=master)](https://github.com/kreait/firebase-php/actions)
[![codecov](https://codecov.io/gh/kreait/firebase-php/branch/master/graph/badge.svg)](https://codecov.io/gh/kreait/firebase-php)
<!--
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=kreait_firebase-php&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=kreait_firebase-php)
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=kreait_firebase-php&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=kreait_firebase-php)
[![Code Coverage](https://sonarcloud.io/api/project_badges/measure?project=kreait_firebase-php&metric=coverage)](https://sonarcloud.io/dashboard?id=kreait_firebase-php)
-->

## Resources

Expand Down
1 change: 1 addition & 0 deletions composer.json
Expand Up @@ -36,6 +36,7 @@
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"google/cloud-firestore": "^1.11",
"jangregor/phpstan-prophecy": "^0.1.2|^0.2|^0.3|^0.4.2",
"phpstan/phpstan-phpunit": "^0.9.4|^0.11.2",
"phpunit/phpunit": "^6.5.14|^7.5.17",
Expand Down

0 comments on commit a906f9b

Please sign in to comment.