Skip to content

Conversation

@anubisthejackle
Copy link
Contributor

@anubisthejackle anubisthejackle commented Sep 29, 2025

Summary

Fixes #46

This PR enhances the reliability and accuracy of failing test fixtures by ensuring that the errors reported by PHPCS in stub files match the expected errors defined in new "expectations" files. It introduces per-test error expectations, so stub files now fail only for the intended, documented reasons, not for unrelated issues.

Key Changes

  • Test Enhancements:

    • The test suite now supports expectations for failing fixtures by allowing each test to reference an associated expectations file.
    • The testing logic has been updated so that failures are only accepted if they match the expected error(s) listed in the corresponding expectations file.
    • Improved logic in process_phpcs_output ensures that unexpected errors cause test failures, increasing test reliability.
  • Expectations Directory:

    • Created tests/fixtures/fail/expectations/ directory containing new PHP files that specify the expected code standard violations for each failing fixture.
    • Added expectation files for a variety of test cases, including array syntax, function arguments, short echo tags, and strict type declarations.
  • Composer Script:

    • Added a new Composer script phpcs:expectations to easily run PHPCS checks specifically against the expectations directory and surface only relevant errors.
  • Documentation Updates:

    • Expanded the README with clearer instructions for contributing and running tests, including a new section detailing the use of expectations files.
    • Clarified the process for maintaining focused, concise failing fixtures.

Motivation

Previously, stub files intended to fail could do so for reasons unrelated to the specific test, making it difficult to ensure that the right coding standard was being enforced. This update aligns test failures with explicit expectations, inspired by practices in Automattic/VIP-Coding-Standards, and directly addresses the concerns raised in #46.

Testing

  • Verify that each failing stub file is checked against its expectation file and only fails for the correct, intended reason.
  • Confirm that the new Composer script (composer phpcs:expectations) runs successfully and surfaces only expected errors.
  • Ensure that documentation clearly explains how to contribute new failing fixture tests with expectations.

Additional Notes

  • This update introduces a more maintainable and robust workflow for testing coding standard violations.
  • Expectation files make it easier to pinpoint and fix unintended issues in the test suite.
  • The approach strengthens the reliability of the coding standards enforcement process.

@anubisthejackle anubisthejackle added enhancement New feature or request php Requires understanding PHP labels Sep 29, 2025
@anubisthejackle anubisthejackle marked this pull request as ready for review September 29, 2025 17:58
@anubisthejackle anubisthejackle requested a review from a team as a code owner September 29, 2025 17:58
Copy link
Member

@srtfisher srtfisher left a comment

Choose a reason for hiding this comment

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

flipping sweet!

@anubisthejackle anubisthejackle merged commit 29374b7 into develop Sep 29, 2025
1 check passed
@anubisthejackle anubisthejackle deleted the feature/issue-46/compare-stub-errors-with-expected branch September 29, 2025 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request php Requires understanding PHP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve tests to match the error reported for the stub files with the expected error

3 participants