Skip to content

Conversation

rodrigoprimo
Copy link
Contributor

Description

This PR restores the FileList tests that were removed in #1213 and fixes the issue that was breaking the ability to run sniff tests for external standards using the PHPCS native test framework.

This problem was happening because self::initializeConfigAndRuleset() was called in a data provider method in AddFileTest.php. This means that the Config instance created inside initializeConfigAndRuleset() using ConfigDouble was created before AllSniffs::suite() had a chance to get the installed standards from the CodeSniffer.conf configuration file. When AllSniffs::suite() runs, ConfigDouble already overrode the configData and configDataFile properties, and
CodeSniffer.conf is never read, and the tests for external standards were not included.

To fix this problem, I opted to change the test to create an instance of the File class (which requires an instance of the Config class) in the test itself instead of doing that in the data provider.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
    • This change is only breaking for integrators, not for external standards or end-users.
  • Documentation improvement

PR checklist

  • I have checked there is no other PR open for the same change.
  • I have read the Contribution Guidelines.
  • I grant the project the right to include and distribute the code under the BSD-3-Clause license (and I have the right to grant these rights).
  • I have added tests to cover my changes.
  • I have verified that the code complies with the projects coding standards.
  • [Required for new sniffs] I have added XML documentation for the sniff.
  • I have opened a sister-PR in the documentation repository to update the Wiki.

@jrfnl
Copy link
Member

jrfnl commented Sep 15, 2025

@rodrigoprimo Could you please re-push the branch ? You changed the base branch after pushing, which means CI will not run the correct checks and the build won't pass.

… tests

The AddFileTest.php tests introduced an issue that broke the ability to
run sniff tests for external standards using the PHPCS native test
framework.

This problem was happening because `self::initializeConfigAndRuleset()`
was called in a data provider method in `AddFileTest.php`. This means
that the `Config` instance created inside `initializeConfigAndRuleset()`
using `ConfigDouble` was created before `AllSniffs::suite()` had a
chance to get the installed standards from the `CodeSniffer.conf`
configuration file. When `AllSniffs::suite()` runs, `ConfigDouble`
already overrode the `configData` and `configDataFile` properties, and
`CodeSniffer.conf` is never read, and the tests for external standards
were not included.

To fix this problem, I opted to change the test to create an instance of
 the `File` class (which requires an instance of the `Config` class) in
 the test itself instead of doing that in the data provider.
@rodrigoprimo rodrigoprimo force-pushed the restore-file-list-tests branch from 2391174 to 0e289be Compare September 15, 2025 21:48
@rodrigoprimo
Copy link
Contributor Author

Force pushed without changes to ensure CI runs the correct checks since I changed the base branch after creating the PR.

@jrfnl jrfnl added this to the 3.13.5 milestone Sep 16, 2025
Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR @rodrigoprimo. I agree with the analysis. PHPUnit runs the data providers very early on to count the number of tests expected and that appears to be too early for this test.

There are some small things I'd do differently, like drop the assertSame() with the instanceof condition as the else is an assertInstanceOf() anyway; and maybe add a test with a non-File-object, but as this update is only going into the 3.x branch, let's just merge it ;-)

@jrfnl jrfnl merged commit 9d00e0e into PHPCSStandards:3.x Sep 16, 2025
63 checks passed
@jrfnl jrfnl deleted the restore-file-list-tests branch September 16, 2025 19:46
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