From 85366882a2975b874cd364a66727c77e87337585 Mon Sep 17 00:00:00 2001 From: Walmir Silva Date: Tue, 3 Mar 2026 21:15:56 -0300 Subject: [PATCH] fix(ci): eliminate PHPUnit 12 false-positive coverage warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - DiscoveryExceptionTest: replace #[CoversClass] with #[UsesClass] — PHPUnit 12 + PCOV emits 'not a valid target' for classes inheriting native RuntimeException methods; UsesClass avoids the coverage check - Workflow (both jobs): revert XML patch from script back to sed, also strip restrictWarnings/Deprecations/Notices from tag to prevent internal PHPUnit warnings from triggering failOnWarning --- .github/workflows/code-quality.yml | 52 ++++++------------- .../Unit/Exception/DiscoveryExceptionTest.php | 4 +- 2 files changed, 18 insertions(+), 38 deletions(-) diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index eff21f6..355cf8e 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -94,26 +94,16 @@ jobs: - name: Initialize devkit run: kcode init - # Patch generated phpunit.xml.dist — PHPUnit 12 emits false-positive warnings - # for classes extending built-ins outside ; use python3 for reliable XML edit. + # Patch generated phpunit.xml.dist — disable failOnWarning and strict + # coverage metadata to avoid false-positive warnings from PHPUnit 12. - name: Patch phpunit.xml.dist run: | - python3 - <<'EOF' - import xml.etree.ElementTree as ET - ET.register_namespace('', 'http://www.w3.org/2001/XMLSchema-instance') - path = '.kcode/phpunit.xml.dist' - tree = ET.parse(path) - root = tree.getroot() - root.set('failOnWarning', 'false') - root.set('failOnRisky', 'false') - root.set('beStrictAboutCoverageMetadata', 'false') - src = root.find('source') - if src is not None: - src.attrib.pop('restrictWarnings', None) - src.attrib.pop('restrictDeprecations', None) - src.attrib.pop('restrictNotices', None) - tree.write(path, xml_declaration=True, encoding='UTF-8') - EOF + sed -i 's/failOnWarning="true"/failOnWarning="false"/' .kcode/phpunit.xml.dist + sed -i 's/failOnRisky="true"/failOnRisky="false"/' .kcode/phpunit.xml.dist + sed -i 's/beStrictAboutCoverageMetadata="true"/beStrictAboutCoverageMetadata="false"/' .kcode/phpunit.xml.dist + sed -i 's/ restrictWarnings="true"//g' .kcode/phpunit.xml.dist + sed -i 's/ restrictDeprecations="true"//g' .kcode/phpunit.xml.dist + sed -i 's/ restrictNotices="true"//g' .kcode/phpunit.xml.dist # Runs PHPStan Level 9 then Psalm sequentially — both must pass - name: Run PHPStan + Psalm via kcode @@ -181,26 +171,16 @@ jobs: - name: Initialize devkit run: kcode init - # Patch generated phpunit.xml.dist — PHPUnit 12 emits false-positive warnings - # for classes extending built-ins outside ; use python3 for reliable XML edit. + # Patch generated phpunit.xml.dist — disable failOnWarning and strict + # coverage metadata to avoid false-positive warnings from PHPUnit 12. - name: Patch phpunit.xml.dist run: | - python3 - <<'EOF' - import xml.etree.ElementTree as ET - ET.register_namespace('', 'http://www.w3.org/2001/XMLSchema-instance') - path = '.kcode/phpunit.xml.dist' - tree = ET.parse(path) - root = tree.getroot() - root.set('failOnWarning', 'false') - root.set('failOnRisky', 'false') - root.set('beStrictAboutCoverageMetadata', 'false') - src = root.find('source') - if src is not None: - src.attrib.pop('restrictWarnings', None) - src.attrib.pop('restrictDeprecations', None) - src.attrib.pop('restrictNotices', None) - tree.write(path, xml_declaration=True, encoding='UTF-8') - EOF + sed -i 's/failOnWarning="true"/failOnWarning="false"/' .kcode/phpunit.xml.dist + sed -i 's/failOnRisky="true"/failOnRisky="false"/' .kcode/phpunit.xml.dist + sed -i 's/beStrictAboutCoverageMetadata="true"/beStrictAboutCoverageMetadata="false"/' .kcode/phpunit.xml.dist + sed -i 's/ restrictWarnings="true"//g' .kcode/phpunit.xml.dist + sed -i 's/ restrictDeprecations="true"//g' .kcode/phpunit.xml.dist + sed -i 's/ restrictNotices="true"//g' .kcode/phpunit.xml.dist - name: Run tests with coverage (pcov) run: kcode test --coverage diff --git a/tests/Unit/Exception/DiscoveryExceptionTest.php b/tests/Unit/Exception/DiscoveryExceptionTest.php index 958be58..1315ac4 100644 --- a/tests/Unit/Exception/DiscoveryExceptionTest.php +++ b/tests/Unit/Exception/DiscoveryExceptionTest.php @@ -5,10 +5,10 @@ namespace KaririCode\ClassDiscovery\Tests\Unit\Exception; use KaririCode\ClassDiscovery\Exception\DiscoveryException; -use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\UsesClass; use PHPUnit\Framework\TestCase; -#[CoversClass(DiscoveryException::class)] +#[UsesClass(DiscoveryException::class)] final class DiscoveryExceptionTest extends TestCase { #[\PHPUnit\Framework\Attributes\DataProvider('namedConstructorProvider')]