Skip to content

Increase test coverage of the CS Fixer commands - #41

Merged
hugo-goncalves-kununu merged 2 commits into
mainfrom
increase-test-coverage
Sep 14, 2026
Merged

hugo-goncalves-kununu merged 2 commits into
mainfrom
increase-test-coverage

Conversation

@hugo-goncalves-kununu

@hugo-goncalves-kununu hugo-goncalves-kununu commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

Description

The objective of this PR is to get the SonarCloud quality gate back to green.

It was failing on both coverage conditions: 94.7% overall against a 95% threshold, and 86.3% on new code against 90%. Everything else on the gate already passed (0 bugs, 0 vulnerabilities, A ratings across the board, 0% duplication on new code, 100% hotspots reviewed).

The two PHP-CS-Fixer commands accounted for 36 of the 48 uncovered lines, so that is where the tests go.

Details

  • tests/PHPCSFixer/Command/CommandTestCase.php

    • Disables exception catching on Composer's Application.
    • Without it, Application::getComposer() calls exit(1) rather than throwing when it cannot build a Composer instance, which ends the whole test run instead of letting the command under test handle the failure. This was the blocker for testing the vendor-dir fallback at all.
  • tests/PHPCSFixer/Command/CsFixerCommandTest.php

    • Adds testCsFixerCommandReturnsFailureWhenBinaryIsMissing, which runs the command from a directory with no composer.json.
    • That single test exercises both previously untested paths: the catch (Throwable) plus __DIR__ fallback in getVendorDir(), and the "binary not found or not executable" guard it then trips.
    • Adds working-directory and temp-directory bookkeeping to tearDown() so the chdir cannot leak into other tests.
  • tests/PHPCSFixer/Command/CsFixerGitHookCommandTest.php

    • Adds testScopeMarkerIsRemovedWhenTheProjectConfigGoesAway. This is the one real behavioural gap rather than just a line count: testScopeMarkerIsWrittenOnlyForAProjectRootedConfig walked packaged to project-owned but never back, so nothing checked that dropping a project's php-cs-fixer.php clears .git/kununu/filter-by-config. Left stale, the hook keeps narrowing staged files through a config that is no longer there.
    • Adds testFailsWhenSymlinkDirectoryCannotBeCreated and testFailsWhenSymlinkCannotBeCreated, covering the two failure paths in ensureSymlinkRelative(). Both follow the chmod pattern the file already uses.
    • Collapses the vendor tree setup, duplicated verbatim across four tests, into a createVendorTree() helper.
  • .github/workflows/continuous-integration.yml

    • Bumps SonarSource/sonarqube-scan-action from v8.1.0 to v8.2.1.

The SonarCloud quality gate was failing on coverage: 94.7% overall against a 95%
threshold, and 86.3% on new code against 90%. The two PHP-CS-Fixer commands held
36 of the 48 uncovered lines.

Add four tests:

- CsFixerCommand: running outside a Composer project, which exercises both the
  vendor-dir fallback and the missing-binary guard.
- CsFixerGitHookCommand: the scope marker being removed once a project drops its
  own config, plus the two symlink failure paths.

CommandTestCase now disables exception catching on Composer's Application.
Without that, Application::getComposer() calls exit(1) rather than throwing when
it cannot build a Composer instance, ending the whole test run instead of
letting the command handle the failure.

Also collapse the vendor tree setup, duplicated verbatim across four tests, into
a single helper.

Coverage: CsFixerCommand 81.8% to 96.1%, CsFixerGitHookCommand 83.7% to 94.1%,
overall 94.1% to 97.2%.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@hugo-goncalves-kununu
hugo-goncalves-kununu marked this pull request as ready for review September 14, 2026 09:43
@hugo-goncalves-kununu
hugo-goncalves-kununu requested a review from a team as a code owner September 14, 2026 09:43
@hugo-goncalves-kununu
hugo-goncalves-kununu merged commit 419f757 into main Sep 14, 2026
5 checks passed
@hugo-goncalves-kununu
hugo-goncalves-kununu deleted the increase-test-coverage branch September 14, 2026 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant