Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruleset::explain(): refactor method to remove use of output buffers + add test #118

Merged
merged 1 commit into from
Dec 4, 2023

Commits on Dec 4, 2023

  1. Ruleset::explain(): refactor method to remove use of output buffers +…

    … add test
    
    As pointed out in 3876 / 84, the `Ruleset::explain()` method was using output buffers incorrectly - it contained three `ob_start()` calls and only one `ob_end*()` call, which meant that at the end, there would be at least one unclosed output buffer.
    
    The (incorrect) use of the output buffers also meant that any test calling this method would be marked as risky with a "Test code or tested code did not (only) close its own output buffers" notice.
    
    In my opinion, the use of output buffers is unnecessary for the "explain" command, so I've refactored the code to remove the use of output buffering completely.
    
    The actual function output remains the same, with only a tiny difference - where previously, the separator marker line for a standard of which only 1 sniff was used would be 1 dash too long, the separator marker line will now match the length of the title line for the standard (tiny bug fix).
    
    This change now allows for the method to be tested, so a test has been added as well.
    
    The test uses the PSR1 standard as:
    1. That standard is not expected to change anymore, which should make this test quite stable.
    2. That standard has "sub-standards" with both 1 as well as "more than 1" sniffs, meaning the output of the subtitles can be tested.
    
    While it may seem redundant to have a test for this code as this is not code which changes often, the deprecation notice fixed in 3876 / 84 would have been caught by this test, while now it was only by the luck of the draw of me running `phpcs -e` while on PHP 8.3 (early) that we found that deprecation.
    jrfnl committed Dec 4, 2023
    Configuration menu
    Copy the full SHA
    4dc78b2 View commit details
    Browse the repository at this point in the history