Skip to content

Tests: Add unit test coverage for Amend_Check_Result trait - #1485

Open
noruzzamans wants to merge 3 commits into
WordPress:trunkfrom
noruzzamans:test/amend-check-result-trait-tests
Open

noruzzamans wants to merge 3 commits into
WordPress:trunkfrom
noruzzamans:test/amend-check-result-trait-tests

Conversation

@noruzzamans

@noruzzamans noruzzamans commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Description

This pull request introduces a comprehensive unit test suite for the WordPress\Plugin_Check\Traits\Amend_Check_Result trait (includes/Traits/Amend_Check_Result.php).

Amend_Check_Result is a core architectural trait composed by over 25 check classes across WordPress/plugin-check (including Plugin_Content_Check, Direct_File_Access_Check, File_Type_Check, Trademarks_Check, Setting_Sanitization_Check, Write_File_Check, Safe_Redirect_Check, and No_Unfiltered_Uploads_Check) to format and record issue notices into Check_Result.

While companion traits such as File_Editor_URL, Readme_Utils, Language_Utils, License_Utils, Version_Utils, and Amend_DB_Base_Prefix possess dedicated unit tests under tests/phpunit/tests/Traits/, Amend_Check_Result previously lacked dedicated unit test coverage.

Test Coverage Highlights

The new test suite in tests/phpunit/tests/Traits/Amend_Check_Result_Tests.php validates:

  • Error Reporting (add_result_error_for_file): Confirms that errors are added to the result stack, error count increments, and warning stack remains unaffected.
  • Warning Reporting (add_result_warning_for_file): Confirms that warnings are added to the result stack, warning count increments, and error stack remains unaffected.
  • Boolean Flag Casting (add_result_message_for_file): Verifies proper casting of truthy and falsy values to error versus warning stacks.
  • Plugin Path Stripping: Asserts that absolute file paths within the plugin root have the base path stripped, producing clean relative file paths in message metadata.
  • Relative Path Handling: Validates that paths already relative to the plugin root are preserved.
  • Default Arguments: Verifies defaults for line (0), column (0), docs (''), and severity (5).
  • Custom Arguments: Validates proper preservation of custom line, column, documentation URL, and severity levels.
  • Editor Link Integration: Asserts integration with File_Editor_URL and wp_plugin_check_validation_error_source_url filter to populate 'link' in message metadata.
  • Permission Fallback: Confirms editor link defaults to null when the user lacks edit capabilities and no custom filter is set.
  • Message Accumulation: Ensures multiple errors and warnings across different files and coordinates accumulate without collision.

Quality & Standards

  • 100% test-only addition (0 production code modifications).
  • Fully validated with composer lint (PHPCS VIPWPCS / WordPress-Core).
  • Fully validated with composer phpstan (PHPStan Level 8, 0 errors).
  • All 10 tests and 45 assertions pass cleanly via PHPUnit.
Open WordPress Playground Preview

@noruzzamans
noruzzamans marked this pull request as ready for review September 22, 2026 10:57
@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: noruzzamans <noruzzaman@git.wordpress.org>
Co-authored-by: davidperezgar <davidperez@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@davidperezgar

davidperezgar commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Thanks for your contribution. The test setup creates a symlink in WP_PLUGIN_DIR, but tear_down() never removes it. This leaves global fixture state behind for the remainder of the suite — and potentially in the wp-env volume — which can affect later tests that enumerate plugins or use the same path. Please clean it up in tear_down(), ideally tracking whether this test class created the symlink so it does not remove one owned by another test.

@noruzzamans

Copy link
Copy Markdown
Contributor Author

Thanks for catching this, @davidperezgar! That's a great point regarding global fixture state leakage and preserving symlinks owned by other tests or prior suite runs.

I have updated the test class in commit 8496bb1b:

  1. Added a $fixture_symlink_created property to explicitly track when symlink() was created by this test class.
  2. In tear_down(), safely unlink() the fixture symlink only if $fixture_symlink_created is true and reset tracking state.

Local PHPCS (composer run-script lint) and PHPStan analyse pass cleanly with 0 errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants