From e75087cf72fc973f30a103169d268d06db66ff41 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 24 Aug 2022 14:03:12 +0000 Subject: [PATCH] Code Modernization: Remove dynamic properties in `Tests_Comment_Walker`. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- tests/phpunit/tests/comment/walker.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/comment/walker.php b/tests/phpunit/tests/comment/walker.php index 443ca0c1cf..504c5e3b0f 100644 --- a/tests/phpunit/tests/comment/walker.php +++ b/tests/phpunit/tests/comment/walker.php @@ -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;