Skip to content

Commit

Permalink
Mutations testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mabar committed Oct 29, 2020
1 parent 24454b5 commit fb6ccc0
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 0 deletions.
113 changes: 113 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,116 @@ jobs:
run: |
composer global require php-coveralls/php-coveralls
php-coveralls -v --config build/.coveralls.yml
tests-mutations:
name: "Test for mutants"
runs-on: "${{ matrix.operating-system }}"

strategy:
matrix:
php-version: [ "7.4" ]
operating-system: [ "ubuntu-latest" ]

if: "github.event_name == 'push'"

steps:
- name: "Check if other steps should be executed"
uses: "actions/github-script@v3"
id: "should-run"
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
result-encoding: "string"
script: |
result = await github.repos.get({
owner: context.repo.owner,
repo: context.repo.repo,
})
ref = 'refs/heads/' + result.data.default_branch;
return ref === context.ref ? 'yes' : 'no';
- name: "Checkout"
if: "${{ steps.should-run.outputs.result == 'yes' }}"
uses: "actions/checkout@v2"

- name: "Create PHP extensions cache key"
uses: "actions/github-script@v3"
id: "php-extensions-cache-key"
with:
script: "return '${{ env.php-extensions }}'.replace(' ', '').replace(',', '+');"
result-encoding: "string"

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

- name: "Cache PHP extensions"
if: "${{ steps.should-run.outputs.result == 'yes' }}"
uses: "actions/cache@v2"
with:
path: "${{ steps.php-extensions-cache.outputs.dir }}"
key: "${{ steps.php-extensions-cache.outputs.key }}"
restore-keys: "${{ steps.php-extensions-cache.outputs.key }}"

- name: "Install PHP"
if: "${{ steps.should-run.outputs.result == 'yes' }}"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
extensions: "${{ env.php-extensions }}"
tools: "${{ env.php-tools }}"

- name: "Setup problem matchers for PHP"
if: "${{ steps.should-run.outputs.result == 'yes' }}"
run: 'echo "::add-matcher::${{ runner.tool_cache }}/php.json"'

- name: "Get Composer cache directory"
if: "${{ steps.should-run.outputs.result == 'yes' }}"
id: "php-composer-cache"
run: 'echo "::set-output name=dir::$(composer config cache-files-dir)"'

- name: "Cache PHP dependencies"
if: "${{ steps.should-run.outputs.result == 'yes' }}"
uses: "actions/cache@v2"
with:
path: "${{ steps.php-composer-cache.outputs.dir }}"
key: "${{ runner.os }}-composer-${{ hashFiles('**/composer.json', '**/composer.lock') }}"
restore-keys: "${{ runner.os }}-composer-"

- name: "Install PHP dependencies"
if: "${{ steps.should-run.outputs.result == 'yes' }}"
run: "composer update --no-interaction --no-progress --prefer-dist --prefer-stable"

- name: "Cache PHPUnit data"
uses: "actions/cache@v2"
with:
path: "var/build-tools/PHPUnit"
key: "${{ runner.os }}-phpunit"
restore-keys: "${{ runner.os }}-phpunit"

- name: "Setup problem matchers for PHPUnit"
if: "${{ steps.should-run.outputs.result == 'yes' }}"
run: 'echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"'

- name: "Cache Infection data"
uses: "actions/cache@v2"
with:
path: "var/build-tools/Infection"
key: "${{ runner.os }}-infection"
restore-keys: "${{ runner.os }}-infection"

- name: "Mutation tests"
if: "${{ steps.should-run.outputs.result == 'yes' }}"
env:
STRYKER_DASHBOARD_API_KEY: "${{ secrets.STRYKER_DASHBOARD_API_KEY }}"
run: "make mutations"

- name: "Upload logs"
uses: "actions/upload-artifact@v2"
with:
name: "Logs"
path: "var/logs"
if-no-files-found: "ignore"
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,12 @@ coverage-clover: ## Generate code coverage in XML format

coverage-html: ## Generate code coverage in HTML format
php -d pcov.enabled=1 -d pcov.directory=./src vendor/bin/phpunit -c build/phpunit.xml --coverage-html var/coverage/coverage-html $(ARGS)

mutations: ## Check code for mutants
php -d pcov.enabled=1 -d pcov.directory=./src vendor/bin/phpunit -c build/phpunit.xml --coverage-xml=var/coverage/coverage-xml --log-junit=var/coverage/junit.xml
vendor/bin/infection \
--configuration=build/infection.json \
--threads=$(nproc) \
--coverage=../var/coverage \
--skip-initial-tests \
$(ARGS)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<p align=center>
<a href="https://github.com/orisai/auth/actions?query=workflow%3Aci"><img src="https://github.com/orisai/auth/workflows/ci/badge.svg"></a>
<a href="https://coveralls.io/r/orisai/auth"><img src="https://badgen.net/coveralls/c/github/orisai/auth/v1.x?cache=300"></a>
<a href="https://dashboard.stryker-mutator.io/reports/github.com/orisai/auth/v1.x"><img src="https://badge.stryker-mutator.io/github.com/orisai/auth/v1.x"></a>
<a href="https://packagist.org/packages/orisai/auth"><img src="https://badgen.net/packagist/dt/orisai/auth?cache=3600"></a>
<a href="https://packagist.org/packages/orisai/auth"><img src="https://badgen.net/packagist/v/orisai/auth?cache=3600"></a>
<a href="https://choosealicense.com/licenses/mpl-2.0/"><img src="https://badgen.net/badge/license/MPL-2.0/blue?cache=3600"></a>
Expand Down
17 changes: 17 additions & 0 deletions build/infection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"source": {
"directories": [
"src"
]
},
"logs": {
"text": "var/logs/infection.log",
"badge": {
"branch": "v1.x"
}
},
"tmpDir": "../var/build-tools/Infection",
"mutators": {
"@default": true
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"require-dev": {
"ext-sodium": "*",
"infection/infection": "^0.19.0",
"orisai/coding-standard": "^1.0.0",
"pepakriz/phpstan-exception-rules": "^0.10.0",
"phpstan/extension-installer": "^1.0.0",
Expand Down

0 comments on commit fb6ccc0

Please sign in to comment.