Skip to content

Commit

Permalink
Merge pull request #358 from ergebnis/feature/coverage
Browse files Browse the repository at this point in the history
Enhancement: Collect code coverage from running unit tests only
  • Loading branch information
localheinz authored Nov 5, 2023
2 parents 0ac2346 + 2e4e38c commit 5c72ddf
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 15 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/integrate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
- name: "Collect code coverage with Xdebug and phpunit/phpunit"
env:
XDEBUG_MODE: "coverage"
run: "vendor/bin/phpunit --colors=always --configuration=test/phpunit.xml --coverage-clover=.build/phpunit/logs/clover.xml"
run: "vendor/bin/phpunit --colors=always --configuration=test/Unit/phpunit.xml --coverage-clover=.build/phpunit/logs/clover.xml"

- name: "Send code coverage report to codecov.io"
uses: "codecov/codecov-action@v3.1.4"
Expand Down Expand Up @@ -490,7 +490,7 @@ jobs:
dependencies: "${{ matrix.dependencies }}"

- name: "Run unit tests with phpunit/phpunit"
run: "vendor/bin/phpunit --colors=always --configuration=test/phpunit.xml --testsuite=unit"
run: "vendor/bin/phpunit --colors=always --configuration=test/Unit/phpunit.xml"

- name: "Run end-to-end tests with phpunit/phpunit"
run: "vendor/bin/phpunit --colors=always --configuration=test/phpunit.xml --testsuite=end-to-end"
run: "vendor/bin/phpunit --colors=always --configuration=test/EndToEnd/phpunit.xml"
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ it: refactoring coding-standards security-analysis static-code-analysis tests ##
.PHONY: code-coverage
code-coverage: vendor ## Collects coverage from running unit tests with phpunit/phpunit
mkdir -p .build/phpunit/
vendor/bin/phpunit --configuration=test/phpunit.xml --coverage-text
vendor/bin/phpunit --configuration=test/Unit/phpunit.xml --coverage-text

.PHONY: coding-standards
coding-standards: vendor ## Lints YAML files with yamllint, normalizes composer.json with ergebnis/composer-normalize, and fixes code style issues with friendsofphp/php-cs-fixer
Expand Down Expand Up @@ -59,8 +59,8 @@ static-code-analysis-baseline: vendor ## Generates a baseline for static code an
.PHONY: tests
tests: vendor ## Runs unit and end-to-end tests with phpunit/phpunit
mkdir -p .build/phpunit
vendor/bin/phpunit --configuration=test/phpunit.xml --testsuite=unit
vendor/bin/phpunit --configuration=test/phpunit.xml --testsuite=end-to-end
vendor/bin/phpunit --configuration=test/Unit/phpunit.xml
vendor/bin/phpunit --configuration=test/EndToEnd/phpunit.xml

vendor: composer.json composer.lock
composer validate --strict
Expand Down
15 changes: 6 additions & 9 deletions test/phpunit.xml → test/EndToEnd/phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../vendor/phpunit/phpunit/phpunit.xsd"
xsi:noNamespaceSchemaLocation="../../vendor/phpunit/phpunit/phpunit.xsd"
beStrictAboutChangesToGlobalState="true"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutTodoAnnotatedTests="true"
bootstrap="../vendor/autoload.php"
cacheDirectory="../.build/phpunit/"
bootstrap="../../vendor/autoload.php"
cacheDirectory="../../.build/phpunit/end-to-end/"
cacheResult="true"
colors="true"
columns="max"
Expand All @@ -28,15 +28,12 @@
<coverage includeUncoveredFiles="true"/>
<source>
<include>
<directory suffix=".php">../src/</directory>
<directory suffix=".php">../../src/</directory>
</include>
</source>
<testsuites>
<testsuite name="end-to-end">
<directory suffix=".phpt">EndToEnd/</directory>
</testsuite>
<testsuite name="unit">
<directory>Unit/</directory>
<testsuite name="End-to-end Tests">
<directory>.</directory>
</testsuite>
</testsuites>
</phpunit>
39 changes: 39 additions & 0 deletions test/Unit/phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../vendor/phpunit/phpunit/phpunit.xsd"
beStrictAboutChangesToGlobalState="true"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutTodoAnnotatedTests="true"
bootstrap="../../vendor/autoload.php"
cacheDirectory="../../.build/phpunit/unit/"
cacheResult="true"
colors="true"
columns="max"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
executionOrder="random"
requireCoverageMetadata="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
>
<coverage includeUncoveredFiles="true"/>
<source>
<include>
<directory suffix=".php">../../src/</directory>
</include>
</source>
<testsuites>
<testsuite name="Unit Tests">
<directory>.</directory>
</testsuite>
</testsuites>
</phpunit>

0 comments on commit 5c72ddf

Please sign in to comment.