Repository navigation
Build/Test Tools: Add tests for the PHPStan extensions - #15850
johnbillion wants to merge 4 commits into
Conversation
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.
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
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: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
There was a problem hiding this comment.
🔵 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
| * @return iterable<string, mixed[]> | ||
| */ | ||
| public function data_file_asserts(): iterable { | ||
| yield from self::gatherAssertTypes( __DIR__ . '/data/apply-filters.php' ); |
There was a problem hiding this comment.
Oooo. Cool language feature I haven't seen before.
There was a problem hiding this comment.
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.
Co-authored-by: theAverageDev (Luca Tumedei) <2749650+lucatume@users.noreply.github.com>
Adds a PHPUnit suite for the custom PHPStan extensions in
tests/phpstan, built on PHPStan's test harness.Run with
composer phpstan:testornpm 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.