wordpress-develop/tests/phpunit/tests/user
Tonya Mork 6fe193ce54 Code Modernization: Deprecate dynamic properties in WP_User_Query magic methods.
The unknown use of unknown dynamic property within the `WP_User_Query` property magic methods is now deprecated. A descriptive deprecation notice is provided to alert developers to declare the property on the child class extending `WP_User_Query`.

Changes in this commit:
* Adds a deprecation notice to the `__get()`, `__set()`, `__isset()`, `__unset()` magic methods, i.e. to alert and inform developers when attempting to get/set/isset/unset a dynamic property.
* Fixes `__get()` to explicitly returns `null` when attempting to get a dynamic property.
* Fixes `__set()` by removing the value return after setting a declared property, as (a) unnecessary and (b) `__set()` should return `void` [https://www.php.net/manual/en/language.oop5.overloading.php#object.set per the PHP handbook].
* Fixes `__isset()` to return `false` if not in the `$compat_fields`, as `isset()` and `__isset()` should always return `bool`:
   * [https://www.php.net/manual/en/language.oop5.overloading.php#object.isset `__isset()` in the PHP manual] 
   * [https://www.php.net/manual/en/function.isset.php `isset()` in the PHP manual] 
* Adds unit tests for happy and unhappy paths.

For backward compatibility, no changes are made to the internal declared properties listed in `$compat_fields` and accessed through the magic methods. 

For example:
A child class uses a property named `$data` that is not declared as a property on the child class. When getting its value, e.g. `$user_query->data`, the `WP_User_Query::__get()` magic method is invoked, the following deprecation notice thrown, and `null` returned:

>The property `data` is not declared. Setting a dynamic property is deprecated since version 6.4.0! Instead, declare the property on the class.

=== Why not remove the magic methods, remove the `$compat_fields` property, and restore the properties `public`?

tl;dr Backward compatibility.

If a plugin adds a property to `$compat_fields` array, then sites using that plugin would experience (a) an `Undefined property` `Warning` (PHP 8) | `Notice` (PHP 7) and (b) a possible change in behavior.

=== Why not limit the deprecation for PHP versions >= 8.2?

tl;dr original design intent and inform

The magic methods and `$compat_fields` property were added for one purpose: to continue providing external access to internal properties declared on `WP_User_Query`. They were not intended to be used for dynamic properties.

Deprecating that unintended usage both alerts developers a change is needed in their child class and informs them what to change.

References: 
* Dynamic (non-explicitly declared) properties are deprecated as of PHP 8.2 and are expected to become a fatal error in PHP 9.0.
* A [https://www.youtube.com/live/vDZWepDQQVE?feature=share&t=10097 live open public working session] where these changes were discussed and agreed to.
* [https://wiki.php.net/rfc/deprecate_dynamic_properties PHP RFC: Deprecate dynamic properties.]

Related to #14579, #27881, #30891.

Follow-up to [15491], [28528], [31144].

Props antonvlasenko, rajinsharwar, jrf, markjaquith, hellofromTonya, SergeyBiryukov, desrosj, peterwilsoncc, audrasjb, costdev, oglekler, jeffpaul.
Fixes #58897.
See #56034.

git-svn-id: https://develop.svn.wordpress.org/trunk@56353 602fd350-edb4-49c9-b593-d223f7449a82
2023-08-03 16:25:25 +00:00
..
capabilities.php Tests: Use the data_ prefix for various data provider methods. 2023-03-19 12:03:30 +00:00
countUserPosts.php Tests: Replace some occurrences of assertEquals() with assertSame(). 2022-10-07 01:02:07 +00:00
countUsers.php Tests: Replace some occurrences of assertEquals() with assertSame(). 2022-10-07 01:02:07 +00:00
dateQuery.php Tests: Introduce assertSameSets() and assertSameSetsWithIndex(), and use them where appropriate. 2020-09-04 07:01:00 +00:00
getActiveBlogForUser.php Tests: Rename classes in phpunit/tests/user/ per the naming conventions. 2022-06-11 15:48:31 +00:00
getTheAuthor.php Code Modernization: Correct fallback return value in get_the_author(). 2023-05-14 17:56:26 +00:00
getTheAuthorLink.php Tests: Split the tests from user/author.php into individual test classes. 2023-05-13 13:33:33 +00:00
getTheAuthorMeta.php Code Modernization: Correct fallback return value in get_the_author(). 2023-05-14 17:56:26 +00:00
getTheAuthorPosts.php Tests: Split the tests from user/author.php into individual test classes. 2023-05-13 13:33:33 +00:00
getTheAuthorPostsLink.php Code Modernization: Correct fallback return value in get_the_author(). 2023-05-14 17:56:26 +00:00
getTheModifiedAuthor.php Code Modernization: Correct fallback return value in get_the_author(). 2023-05-14 17:56:26 +00:00
getUserCount.php Tests: Remove skipWithMultisite() and skipWithoutMultisite() from get_user_count() tests. 2022-10-29 15:42:26 +00:00
mapMetaCap.php Users: Fail gracefully when checking mapped capabilities without providing the required object ID. 2022-05-17 18:59:24 +00:00
multisite.php Tests: Rename classes in phpunit/tests/user/ per the naming conventions. 2022-06-11 15:48:31 +00:00
passwordHash.php Tests: Move PasswordHash test file to a more appropriate place. 2023-02-13 14:20:30 +00:00
query.php Code Modernization: Deprecate dynamic properties in WP_User_Query magic methods. 2023-08-03 16:25:25 +00:00
queryCache.php Users: Cache database queries within WP_User_Query class. 2023-04-18 11:48:46 +00:00
retrievePassword.php Tests: Second pass at merging file-level and class-level DocBlocks in various unit test files. 2023-03-03 14:42:42 +00:00
session.php Code Modernization: Explicitly declare all properties created in set_up() methods of various test classes. 2022-08-27 12:30:08 +00:00
slashes.php Cache API: Validate cache key in WP_Object_Cache methods. 2022-08-03 14:34:58 +00:00
updateUserCaches.php Tests: Use assertInstanceOf() instead of assertTrue() in some tests. 2021-05-18 21:04:31 +00:00
wpAuthenticateSpamCheck.php Tests: Rename classes in phpunit/tests/user/ per the naming conventions. 2022-06-11 15:48:31 +00:00
wpDeleteUser.php Tests: Rename classes in phpunit/tests/user/ per the naming conventions. 2022-06-11 15:48:31 +00:00
wpDropdownUsers.php Tests: Use the factory method instead of the property. 2022-09-06 22:09:49 +00:00
wpGetUsersWithNoRole.php Tests: Rename classes in phpunit/tests/user/ per the naming conventions. 2022-06-11 15:48:31 +00:00
wpListAuthors.php Users: Use a separate variable for the post counts query in wp_list_authors(). 2023-03-01 15:37:06 +00:00
wpListUsers.php Tests: Rename classes in phpunit/tests/user/ per the naming conventions. 2022-06-11 15:48:31 +00:00
wpRegisterPersistedPreferencesMeta.php Users: Correctly pass the context property for persisted preferences. 2022-09-27 15:21:48 +00:00
wpSendUserRequest.php Tests: Merge file-level and class-level DocBlocks in various unit test files. 2023-02-14 16:10:13 +00:00
wpSetCurrentUser.php Tests: Rename classes in phpunit/tests/user/ per the naming conventions. 2022-06-11 15:48:31 +00:00