Increase test coverage of the CS Fixer commands - #41
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.phpApplication.Application::getComposer()callsexit(1)rather than throwing when it cannot build aComposerinstance, 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.phptestCsFixerCommandReturnsFailureWhenBinaryIsMissing, which runs the command from a directory with nocomposer.json.catch (Throwable)plus__DIR__fallback ingetVendorDir(), and the "binary not found or not executable" guard it then trips.tearDown()so the chdir cannot leak into other tests.tests/PHPCSFixer/Command/CsFixerGitHookCommandTest.phptestScopeMarkerIsRemovedWhenTheProjectConfigGoesAway. This is the one real behavioural gap rather than just a line count:testScopeMarkerIsWrittenOnlyForAProjectRootedConfigwalked packaged to project-owned but never back, so nothing checked that dropping a project'sphp-cs-fixer.phpclears.git/kununu/filter-by-config. Left stale, the hook keeps narrowing staged files through a config that is no longer there.testFailsWhenSymlinkDirectoryCannotBeCreatedandtestFailsWhenSymlinkCannotBeCreated, covering the two failure paths inensureSymlinkRelative(). Both follow the chmod pattern the file already uses.createVendorTree()helper..github/workflows/continuous-integration.ymlSonarSource/sonarqube-scan-actionfrom v8.1.0 to v8.2.1.