Skip to content

Build/Test Tools: Add tests for the PHPStan extensions - #15850

Open
johnbillion wants to merge 4 commits into
WordPress:trunkfrom
johnbillion:66634-phpstan-extension-tests
Open

johnbillion wants to merge 4 commits into
WordPress:trunkfrom
johnbillion:66634-phpstan-extension-tests

Conversation

@johnbillion

@johnbillion johnbillion commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Adds a PHPUnit suite for the custom PHPStan extensions in tests/phpstan, built on PHPStan's test harness.

Run with composer phpstan:test or npm run typecheck:php:test. The suite also runs in the PHPStan workflow.

Trac ticket: https://core.trac.wordpress.org/ticket/66634

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Writing the tests and preparing this PR.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Adds a PHPUnit suite for the custom PHPStan extensions in `tests/phpstan`, built on PHPStan's test harness. The suite runs with `composer phpstan:test` or `npm run typecheck:php:test`, and runs in CI ahead of the static analysis.

See #66634.
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@johnbillion
johnbillion marked this pull request as draft November 9, 2026 16:58
@johnbillion
johnbillion marked this pull request as ready for review November 9, 2026 16:58
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props johnbillion, lucatume, westonruter.

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The pinned PHPStan test harness was unavailable for inspection, so the new CI gate’s bootstrap and reflection behavior needs validation via composer phpstan:test with installed dependencies before approval.

No open issues 🎉

What changed in this PR

Adds a dedicated PHPUnit suite for WordPress’s custom PHPStan extensions, covering their behavior independently of core analysis.

Changes:

  • Tests hook documentation, parameter counts, docblock visitors, and inferred types using isolated fixtures.
  • Adds test configuration and Composer/npm commands.
  • Runs the suite before PHPStan analysis in CI and documents local usage.
File Description
tests/​phpstan/​Tests/​tests.neon Registers extensions and fixture dependencies.
tests/​phpstan/​Tests/​HookParamCountRuleTest.php Checks parameter-count diagnostics and identifiers.
tests/​phpstan/​Tests/​HookDocumentationRuleTest.php Checks documentation diagnostics and reference resolution.
tests/​phpstan/​Tests/​HookDocsVisitorTest.php Tests docblock attachment and traversal isolation.
tests/​phpstan/​Tests/​HookDocBlockTest.php Tests hook-name and parameter-documentation helpers.
tests/​phpstan/​Tests/​HashNotationVisitorTest.php Tests hash-notation translation and text preservation.
tests/​phpstan/​Tests/​HashNotationTypeTest.php Checks inferred hash-notation types.
tests/​phpstan/​Tests/​GlobalDocBlockVisitorTest.php Checks types inferred from global documentation.
tests/​phpstan/​Tests/​data/​wordpress/​wp-includes/​other.php Supplies unrelated hook documentation.
tests/​phpstan/​Tests/​data/​wordpress/​wp-includes/​canonical.php Supplies canonical hook-reference targets.
tests/​phpstan/​Tests/​data/​wordpress/​wp-content/​themes/​wptests/​index.php Exercises theme-relative documentation references.
tests/​phpstan/​Tests/​data/​wordpress/​wp-content/​themes/​wptests/​author.php Supplies a sibling theme reference target.
tests/​phpstan/​Tests/​data/​wordpress/​wp-admin/​admin.php Exercises relative paths and root boundaries.
tests/​phpstan/​Tests/​data/​outside.php Supplies an out-of-root reference target.
tests/​phpstan/​Tests/​data/​hook-param-count.php Provides matching and mismatched argument counts.
tests/​phpstan/​Tests/​data/​hook-documentation.php Provides valid and invalid hook documentation.
tests/​phpstan/​Tests/​data/​hash-notation.php Provides hash-shape type assertions.
tests/​phpstan/​Tests/​data/​GlobalDocBlockTestClass.php Covers globals within namespaced methods.
tests/​phpstan/​Tests/​data/​global-docblock.php Covers global types, precedence, and scope.
tests/​phpstan/​Tests/​data/​functions.php Supplies a generic fixture helper.
tests/​phpstan/​Tests/​data/​ApplyFiltersTestClass.php Covers filter typing within classes.
tests/​phpstan/​Tests/​data/​apply-filters.php Covers filter return-type inference.
tests/​phpstan/​Tests/​bootstrap.php Sets the fixture root and loads dependencies.
tests/​phpstan/​Tests/​ApplyFiltersDynamicFunctionReturnTypeExtensionTest.php Checks filter return-type assertions.
tests/​phpstan/​README.md Documents the suite and execution commands.
tests/​phpstan/​phpunit.xml.dist Configures test discovery and strict checks.
tests/​phpstan/​base.neon Scans tests while excluding intentional-error fixtures.
package.json Adds the Docker-backed test command.
composer.json Adds the PHPUnit suite command.
.github/​workflows/​reusable-phpstan-static-analysis-v1.yml Runs extension tests before analysis.
.github/​workflows/​phpstan-static-analysis.yml Triggers CI for test-configuration changes.

Review effort: Balanced

@westonruter westonruter left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for doing this.

* @return iterable<string, mixed[]>
*/
public function data_file_asserts(): iterable {
yield from self::gatherAssertTypes( __DIR__ . '/data/apply-filters.php' );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oooo. Cool language feature I haven't seen before.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah unfortunately PHPUnit collects all data provider data for all tests before starting (so it can show progress) so it doesn't actually provide the memory benefit that a generator usually does. Neat though.

Comment thread tests/phpstan/Tests/data/functions.php Resolved
Co-authored-by: theAverageDev (Luca Tumedei) <2749650+lucatume@users.noreply.github.com>
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.

4 participants