Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.2 | Tests: explicitly declare all properties created in set_up() #2867

Closed

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jun 23, 2022

Dynamic (non-explicitly declared) properties are deprecated as of PHP 8.2 and are expected to become a fatal error in PHP 9.0.

In each of the cases included in this PR, one or more properties are dynamically created in the set_up() method of the test class.

This commit explicitly declares these properties.

As these properties are being declared on test classes, I'm making them all private.
Even though the original dynamic property was public, this should not be considered a BC break as this only involves test classes.

Notes:

  • As these properties receive assignments during test runs or a one-time assignment, but the assignment uses a function call or variable access, these properties can't be changed to class constants, but they should be declared explicitly as properties on the class.
  • In Tests_Theme_CustomHeader, I've given the $customize_manager property a default value of null, same as it was already being reset to null in the tear_down() method.
  • In Tests_Privacy_wpPrivacyProcessPersonalDataExportPage and the Tests_Privacy_wpPrivacyGeneratePersonalDataExportFile classes, the property name had a leading _ underscore. This is an outdated PHP 4 practice to indicate a private property. As PHP 4 is no longer supported, I have renamed the property to $orig_error_level.
  • Along the same lines, in Tests_Menu_Walker_Nav_Menu, the property name also had a leading _ underscore. I have renamed the property to $orig_wp_nav_menu_max_depth.
  • In the Tests_Shortcode class, three properties were already being (re)set in the set_up() method, while three others were being set for most tests via the shortcode_test_shortcode_tag() method or in the tests themselves.
    I've now made sure that all six properties are given their initial null value in the set_up() method and are explicitly declared.

Additionally:

  • In the Tests_User_Session class, the set_up() method is incorrect. No assertions should be executed in fixture methods, but the set_up() method contains two assertions.
    I've not addressed this as this is outside the scope of this PR, but this should be addressed at a later point in time.

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


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.

Dynamic (non-explicitly declared) properties are deprecated as of PHP 8.2 and are expected to become a fatal error in PHP 9.0.

In each of the cases included in this PR, one or more properties are dynamically created in the `set_up()` method of the test class.

This commit explicitly declares these properties.

As these properties are being declared on test classes, I'm making them all `private`.
Even though the original dynamic property was `public`, this should not be considered a BC break as this only involves test classes.

Notes:
* As these properties receive assignments during test runs or a one-time assignment, but the assignment uses a function call or variable access, these properties can't be changed to class constants, but they should be declared explicitly as properties on the class.
* In `Tests_Theme_CustomHeader`, I've given the `$customize_manager` property a default value of `null`, same as it was already being reset to `null` in the `tear_down()` method.
* In `Tests_Privacy_wpPrivacyProcessPersonalDataExportPage` and the `Tests_Privacy_wpPrivacyGeneratePersonalDataExportFile` classes, the property name had a leading `_` underscore. This is an outdated PHP 4 practice to indicate a `private` property. As PHP 4 is no longer supported, I have renamed the property to `$orig_error_level`.
* Along the same lines, in `Tests_Menu_Walker_Nav_Menu`, the property name also had a leading `_` underscore. I have renamed the property to `$orig_wp_nav_menu_max_depth`.
* In the `Tests_Shortcode` class, three properties were already being (re)set in the `set_up()` method, while three others were being set for most tests via the `shortcode_test_shortcode_tag()` method or in the tests themselves.
    I've now made sure that all six properties are given their initial `null` value in the `set_up()` method and are explicitly declared.

Additionally:
* In the `Tests_User_Session` class, the `set_up()` method is incorrect. No assertions should be executed in fixture methods, but the `set_up()` method contains two assertions.
    I've not addressed this as this is outside the scope of this PR, but this should be addressed at a later point in time.
@SergeyBiryukov
Copy link
Member

Thanks for the PR! Merged in r53948.

@jrfnl jrfnl deleted the php-8.2/declare-dynamic-properties-16 branch August 27, 2022 12:58
@jrfnl
Copy link
Member Author

jrfnl commented Aug 27, 2022

Thanks @SergeyBiryukov !

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.

2 participants