Code Modernization: Remove dynamic properties in Tests_Comment_Walker.

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 this test file, the `Tests_Comment_Walker::set_up()` method created a dynamic `$post_id` property, which should have been explicitly declared.

Along the same lines, the `Comment_Callback_Test::__construct()` method also assigned values to two undeclared properties.

This is now fixed by explicitly declaring the properties in both classes.

Includes renaming the `Comment_Callback_Test` class to `Comment_Callback_Test_Helper` as it does not contain any test methods and its only purpose is as a “helper” class for the `Tests_Comment_Walker::test_has_children()` test.

Follow-up to [28824], [53557], [53558], [53850], [53851], [53852], [53853], [53854], [53856], [53916], [53935], [53936], [53937].

Props jrf.
See #56033.

git-svn-id: https://develop.svn.wordpress.org/trunk@53938 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2022-08-24 14:03:12 +00:00
parent 28716eb8a6
commit e75087cf72

View File

@ -7,6 +7,13 @@
*/
class Tests_Comment_Walker extends WP_UnitTestCase {
/**
* Comment post ID.
*
* @var int
*/
private $post_id;
public function set_up() {
parent::set_up();
@ -28,7 +35,7 @@ class Tests_Comment_Walker extends WP_UnitTestCase {
$comment_child = get_comment( $comment_child );
$comment_walker = new Walker_Comment();
$comment_callback = new Comment_Callback_Test( $this, $comment_walker );
$comment_callback = new Comment_Callback_Test_Helper( $this, $comment_walker );
wp_list_comments(
array(
@ -49,7 +56,10 @@ class Tests_Comment_Walker extends WP_UnitTestCase {
}
}
class Comment_Callback_Test {
class Comment_Callback_Test_Helper {
private $test_walker;
private $walker;
public function __construct( Tests_Comment_Walker $test_walker, Walker_Comment $walker ) {
$this->test_walker = $test_walker;
$this->walker = $walker;