Skip to content

Fix RulesetTest#833

Merged
GaryJones merged 1 commit intodevelopfrom
feature/fix-ruleset-test
May 20, 2025
Merged

Fix RulesetTest#833
GaryJones merged 1 commit intodevelopfrom
feature/fix-ruleset-test

Conversation

@jrfnl
Copy link
Collaborator

@jrfnl jrfnl commented May 19, 2025

As of PHPCS 3.13.0, PHPCS will show deprecation notices for various features which will be removed in PHPCS 4.0.0.

However, in PHPCS 3.x, PHPCS sends all output to STDOUT (this will change in PHPCS 4.x), so if the output of an exec command which expects a json report is captured, this will now also include the deprecation notices in the output, which means the json_decode() command will fail as the captured output is not valid JSON.

This, in turn, is currently causing the Ruleset test runs to fail in CI for the VIPCS repo. The issue is locally reproducable.

This commit fixes this by:

  • Changing the --report=json in the command being run to --report-json=[filename] and storing the JSON output to a file. This way the report file will only contain report output and will not include the deprecation notices (those will still go to STDOUT).
  • Next, we read the report file to process the JSON report;
  • And then delete the report file (and prevent it from being committed via the .gitignore file, just in case the file delete would fail at some point).

This solution is PHPCS cross-version compatible as the --report-json=[filename] CLI flag has been around for quite a while.

This solution should also improve the stability of the script for potential future changes in PHPCS.

As of PHPCS 3.13.0, PHPCS will show deprecation notices for various features which will be removed in PHPCS 4.0.0.

However, in PHPCS 3.x, PHPCS sends all output to `STDOUT` (this will change in PHPCS 4.x), so if the output of an `exec` command which expects a `json` report is captured, this will now also include the deprecation notices in the output, which means the `json_decode()` command will fail as the captured output is not valid JSON.

This, in turn, is currently causing the Ruleset test runs to fail in CI for the VIPCS repo. The issue is locally reproducable.

This commit fixes this by:
* Changing the `--report=json` in the command being run to `--report-json=[filename]` and storing the JSON output to a file.
    This way the report file will _only_ contain report output and will not include the deprecation notices (those will still go to `STDOUT`).
* Next, we read the report file to process the JSON report;
* And then delete the report file (and prevent it from being committed via the `.gitignore` file, just in case the file delete would fail at some point).

This solution is PHPCS cross-version compatible as the `--report-json=[filename]` CLI flag has been around for quite a while.

This solution should also improve the stability of the script for potential future changes in PHPCS.
@jrfnl jrfnl added this to the 3.x Next milestone May 19, 2025
@jrfnl jrfnl requested a review from a team as a code owner May 19, 2025 17:06
@GaryJones GaryJones merged commit 828b752 into develop May 20, 2025
42 checks passed
@GaryJones GaryJones deleted the feature/fix-ruleset-test branch May 20, 2025 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants