Fix static type error in REST API endpoint and add Generic.PHP.RequireStrictTypes to PHPCS ruleset#2436
Conversation
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Cast query params to strings in create_request() since real HTTP requests always deliver parameter values as strings. Also add test cases for invalid cache_purge_post_id values (negative, zero, non-numeric string). Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
…st scripts The wp-env Docker container has PHPUnit 10.5 installed globally (at ~/.composer/vendor/bin/phpunit), while the project requires PHPUnit 8.5 (in vendor/bin/phpunit). When Composer runs the `test` script, it prepends vendor/bin to PATH, so the local phpunit should take precedence. However, Docker Desktop on macOS does not preserve the execute bit on files mapped into the container via the wp-env `.wp-env.json` mappings config. This causes vendor/bin/phpunit to be non-executable inside the container (-rw-r--r-- instead of -rwxr-xr-x), so Composer silently falls back to the global PHPUnit 10.5 which does not support the --verbose flag and has other incompatibilities with the project's test configuration. By using `php vendor/bin/phpunit` explicitly, we bypass the execute permission issue entirely and ensure the correct project-local PHPUnit version is always used regardless of Docker's permission mapping behavior. Note: the `.wp-env.json` "mappings" for the tests container copies files into a Docker volume rather than creating a live bind mount. After changing composer.json (or any mapped file), you must run `npx wp-env start --update` for the container to pick up the changes. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The manual rest_validate_value_from_schema() call fails when cache_purge_post_id is not provided because $request['...'] returns null, which doesn't satisfy type 'integer'. The REST API's own validation skips absent optional params, but this manual call doesn't know the param is absent vs explicitly null. Add a null guard to match the REST API's behavior. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## trunk #2436 +/- ##
=======================================
Coverage 69.33% 69.33%
=======================================
Files 90 90
Lines 7749 7749
=======================================
Hits 5373 5373
Misses 2376 2376
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…ave been validated and sanitized
| "test": "phpunit --strict-coverage", | ||
| "test": "php vendor/bin/phpunit --strict-coverage", | ||
| "test-multisite": [ | ||
| "WP_MULTISITE=1 phpunit --exclude-group=ms-excluded" | ||
| "WP_MULTISITE=1 php vendor/bin/phpunit --exclude-group=ms-excluded" |
Summary
See #2348.
This is a follow-up to #2424.
This PR ensures that new PHP files (aside from tests) will fail PHPCS if
declare( strict_types = 1 );is absent.This also fixes an error I encountered when attempting to store a new URL Metric via the REST API:
This is fixed in 563764d. The issue is that when a
validate_callbackobtains the REST API params, no validation or sanitization is applied. So the string value is passed through. But it needs to be enforced asint<1, max>|null. So this is now fixed.AI Use
I prompted Claude to help me debug issues with
wp-env, PHPUnit, and tests.