From 24f81aba71560b907121e62a261624ee9a4c2666 Mon Sep 17 00:00:00 2001 From: Robert van Lienden Date: Mon, 30 Dec 2024 22:39:38 +0100 Subject: [PATCH 1/3] Add codestyle coverage. --- .gitignore | 3 ++- Taskfile | 6 +++++- development/Dockerfile | 7 +++++++ development/tooling/phpunit.xml | 30 ++++++++++++++++++++++------- tests/unit/AgreementServiceTest.php | 2 ++ 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 32ba368..2c8083e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ -.phpunit.result.cache +.phpunit.*cache +coverage vendor composer.lock \ No newline at end of file diff --git a/Taskfile b/Taskfile index e7d0b8f..fb79918 100755 --- a/Taskfile +++ b/Taskfile @@ -58,7 +58,11 @@ function task:phpstan { ## Run PHPStan } function task:tests { ## Run unit tests - dockercompose-exec vendor/bin/phpunit -c development/tooling/phpunit.xml --testdox tests + dockercompose-exec vendor/bin/phpunit -c development/tooling/phpunit.xml --testdox +} + +function task:tests-with-coverage { ## Run unit tests with codestyle reports + dockercompose-exec vendor/bin/phpunit -c development/tooling/phpunit.xml --testdox --coverage-html coverage } # ========================================================= diff --git a/development/Dockerfile b/development/Dockerfile index 3f73b26..45a699d 100644 --- a/development/Dockerfile +++ b/development/Dockerfile @@ -11,6 +11,13 @@ RUN apk add --no-cache \ WORKDIR /www +RUN apk add linux-headers --no-cache $PHPIZE_DEPS --virtual .build-deps; \ + pecl install xdebug; \ + docker-php-ext-enable xdebug; \ + apk del .build-deps; + +RUN echo "xdebug.mode=coverage" >> /usr/local/etc/php/conf.d/xdebug.ini; + RUN set -eux; \ COMPOSER_MEMORY_LIMIT=2G composer install --prefer-dist --no-scripts --no-progress; \ composer clear-cache diff --git a/development/tooling/phpunit.xml b/development/tooling/phpunit.xml index d46baa3..1dffa42 100644 --- a/development/tooling/phpunit.xml +++ b/development/tooling/phpunit.xml @@ -1,9 +1,25 @@ - + + + + ./../../tests + + + + + + ./../../src + + diff --git a/tests/unit/AgreementServiceTest.php b/tests/unit/AgreementServiceTest.php index a909066..b7aa0e9 100644 --- a/tests/unit/AgreementServiceTest.php +++ b/tests/unit/AgreementServiceTest.php @@ -2,10 +2,12 @@ namespace RobertvanLienden\UserAgreements\Tests\Service; +use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\TestCase; use RobertvanLienden\UserAgreements\Service\AgreementService; use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface; +#[CoversClass(AgreementService::class)] class AgreementServiceTest extends TestCase { private AgreementService $agreementService; From 60fb05a792927df3451186e04de1d68c1d7ffe8b Mon Sep 17 00:00:00 2001 From: Robert van Lienden Date: Mon, 30 Dec 2024 22:49:26 +0100 Subject: [PATCH 2/3] Try to get code coverage in workflow --- .github/workflows/workflow.yaml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index 4df1b8a..37cdc0e 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -31,6 +31,12 @@ jobs: run: | docker run --rm php-ci vendor/bin/phpstan --configuration=./development/tooling/phpstan.neon - - name: Run unit tests + - name: Run unit tests with coverage run: | - docker run --rm php-ci vendor/bin/phpunit -c development/tooling/phpunit.xml --testdox tests \ No newline at end of file + docker run --rm php-ci vendor/bin/phpunit -c development/tooling/phpunit.xml --testdox tests --coverage-clover coverage.xml + + - name: Upload coverage reports to Codecov + uses: codecov/codecov-action@v5 + with: + token: ${{ secrets.CODECOV_TOKEN }} + slug: robertvanlienden/useragreementsbundle \ No newline at end of file From 171b36fddb29df9f96d46c16f73ef46bfa1cf5ac Mon Sep 17 00:00:00 2001 From: Robert van Lienden Date: Mon, 30 Dec 2024 22:53:36 +0100 Subject: [PATCH 3/3] Another try to upload coverage --- .github/workflows/workflow.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index 37cdc0e..c464ca8 100644 --- a/.github/workflows/workflow.yaml +++ b/.github/workflows/workflow.yaml @@ -33,7 +33,7 @@ jobs: - name: Run unit tests with coverage run: | - docker run --rm php-ci vendor/bin/phpunit -c development/tooling/phpunit.xml --testdox tests --coverage-clover coverage.xml + docker run --rm -v $GITHUB_WORKSPACE:/workspace php-ci vendor/bin/phpunit -c development/tooling/phpunit.xml --testdox tests --coverage-clover=/workspace/coverage.xml - name: Upload coverage reports to Codecov uses: codecov/codecov-action@v5