PHP 8.2 | Tests: explicitly declare all properties created in set_up() #2867
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
Tests_Theme_CustomHeader
, I've given the$customize_manager
property a default value ofnull
, same as it was already being reset tonull
in thetear_down()
method.Tests_Privacy_wpPrivacyProcessPersonalDataExportPage
and theTests_Privacy_wpPrivacyGeneratePersonalDataExportFile
classes, the property name had a leading_
underscore. This is an outdated PHP 4 practice to indicate aprivate
property. As PHP 4 is no longer supported, I have renamed the property to$orig_error_level
.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
.Tests_Shortcode
class, three properties were already being (re)set in theset_up()
method, while three others were being set for most tests via theshortcode_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 theset_up()
method and are explicitly declared.Additionally:
Tests_User_Session
class, theset_up()
method is incorrect. No assertions should be executed in fixture methods, but theset_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.