diff --git a/.github/workflows/workflow.yaml b/.github/workflows/workflow.yaml index 4df1b8a..c464ca8 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 -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 + with: + token: ${{ secrets.CODECOV_TOKEN }} + slug: robertvanlienden/useragreementsbundle \ No newline at end of file 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;