mirror of
git://develop.git.wordpress.org/
synced 2025-02-22 15:42:29 +01:00
This fixes `parse_str(): Passing null to parameter #1 ($string) of type string is deprecated` notices on PHP 8.1, without change in behaviour. Impact: 311 of the pre-existing tests are affected by this issue. The PHP native `parse_str()` function expects a string, however, based on the failing tests, it is clear there are functions in WordPress which passes a non-string – including `null` – value to the `wp_parse_str()` function, which would subsequently pass it onto the PHP native function without further input validation. Most notable offender is the `wp_parse_args()` function which special cases arrays and objects, but passes everything else off to `wp_parse_str()`. Several ways to fix this issue have been explored, including checking the received value with `is_string()` or `is_scalar()` before passing it off to the PHP native `parse_str()` function. In the end it was decided against these in favor of a string cast as: * `is_string()` would significantly change the behavior for anything non-string. * `is_scalar()` up to a point as well, as it does not take objects with a `__toString()` method into account. Executing a string cast on the received value before passing it on maintains the pre-existing behavior while still preventing the deprecation notice coming from PHP 8.1. Reference: [https://www.php.net/manual/en/function.parse-str.php PHP Manual: parse_str()] Follow-up to [5709]. Props jrf, hellofromTonya, lucatume, SergeyBiryukov. See #53635. git-svn-id: https://develop.svn.wordpress.org/trunk@51624 602fd350-edb4-49c9-b593-d223f7449a82
The short version: 1. Create a clean MySQL database and user. DO NOT USE AN EXISTING DATABASE or you will lose data, guaranteed. 2. Copy wp-tests-config-sample.php to wp-tests-config.php, edit it and include your database name/user/password. 3. $ svn up 4. Run the tests from the "trunk" directory: To execute a particular test: $ phpunit tests/phpunit/tests/test_case.php To execute all tests: $ phpunit Notes: Test cases live in the 'tests' subdirectory. All files in that directory will be included by default. Extend the WP_UnitTestCase class to ensure your test is run. phpunit will initialize and install a (more or less) complete running copy of WordPress each time it is run. This makes it possible to run functional interface and module tests against a fully working database and codebase, as opposed to pure unit tests with mock objects and stubs. Pure unit tests may be used also, of course. Changes to the test database will be rolled back as tests are finished, to ensure a clean start next time the tests are run. phpunit is intended to run at the command line, not via a web server.