diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 02aae24..d5d2d74 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,11 +18,31 @@ jobs: with: php-version: '8.4' extensions: mbstring - coverage: none + coverage: pcov tools: composer:v2 - name: Validate composer.json run: composer validate --no-check-publish --no-check-lock - name: Install dependencies run: composer update --prefer-dist --no-progress --no-interaction - - name: Run tests - run: vendor/bin/phpunit --no-coverage + - name: PHPStan + run: vendor/bin/phpstan analyse --no-progress --memory-limit=1G + - name: Run tests with coverage + run: | + mkdir -p build + vendor/bin/phpunit --coverage-clover=build/coverage.xml + - name: Enforce coverage threshold + env: + COVERAGE_MIN: '75' + run: | + php -r ' + $xml = simplexml_load_file("build/coverage.xml"); + $metrics = $xml->project->metrics; + $total = (int) $metrics["statements"]; + $covered = (int) $metrics["coveredstatements"]; + $pct = $total > 0 ? 100 * $covered / $total : 0.0; + printf("Coverage: %.2f%% (minimum %.2f%%)\n", $pct, (float) getenv("COVERAGE_MIN")); + if ($pct < (float) getenv("COVERAGE_MIN")) { + fwrite(STDERR, "Coverage below threshold\n"); + exit(1); + } + ' diff --git a/composer.json b/composer.json index b4361af..f50e49d 100755 --- a/composer.json +++ b/composer.json @@ -1,25 +1,29 @@ { - "name": "fastd/container", - "description": "FastD Container", - "type": "library", - "keywords": ["FastD", "container"], - "license": "MIT", - "authors": [ - { - "name": "janhuang", - "email": "384099566@qq.com" + "name": "fastd/container", + "description": "FastD Container", + "type": "library", + "keywords": [ + "FastD", + "container" + ], + "license": "MIT", + "authors": [ + { + "name": "janhuang", + "email": "384099566@qq.com" + } + ], + "require": { + "php": ">=8.4", + "psr/container": "^2.0" + }, + "require-dev": { + "phpunit/phpunit": "^10.0", + "phpstan/phpstan": "^1.12.24" + }, + "autoload": { + "psr-4": { + "FastD\\Container\\": "src" + } } - ], - "require": { - "php": ">=8.4", - "psr/container": "^2.0" - }, - "require-dev": { - "phpunit/phpunit": "^10.0" - }, - "autoload": { - "psr-4": { - "FastD\\Container\\": "src" - } - } } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..91e6453 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,4 @@ +parameters: + level: 5 + paths: + - src diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 31ffb94..4aa465f 100755 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,10 @@ - + + + + src + + tests