From 278081ed1d5efd99c7e536c7dd9ca2ac15b4b875 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 7 Aug 2022 14:41:04 +0000 Subject: [PATCH] Code Modernization: Remove dynamic properties in `Tests_Post_Revisions`. 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 particular case, the test class contains a `set_up()` method that sets the `$post_type` property, which is ''used'' by the tests, but never ''changed'' by the tests. In other words, setting this property in the `set_up()` is an unnecessary overhead and the property should be changed to a class constant. Follow-up to [1212/tests], [52389], [53557], [53558], [53850], [53851], [53852]. Props jrf. See #56033. git-svn-id: https://develop.svn.wordpress.org/trunk@53853 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/post/revisions.php | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/tests/phpunit/tests/post/revisions.php b/tests/phpunit/tests/post/revisions.php index e4e0c500d5..c8effbccc2 100644 --- a/tests/phpunit/tests/post/revisions.php +++ b/tests/phpunit/tests/post/revisions.php @@ -5,6 +5,9 @@ * @group revision */ class Tests_Post_Revisions extends WP_UnitTestCase { + + const POST_TYPE = 'test-revision'; + protected static $admin_user_id; protected static $editor_user_id; protected static $author_user_id; @@ -15,11 +18,6 @@ class Tests_Post_Revisions extends WP_UnitTestCase { self::$author_user_id = $factory->user->create( array( 'role' => 'author' ) ); } - public function set_up() { - parent::set_up(); - $this->post_type = 'test-revision'; - } - /** * Note: Test needs reviewing when #16215 is fixed because I'm not sure the test current tests the "correct" behavior * @@ -318,7 +316,7 @@ class Tests_Post_Revisions extends WP_UnitTestCase { */ public function test_revision_view_caps_cpt() { register_post_type( - $this->post_type, + self::POST_TYPE, array( 'capability_type' => 'event', 'map_meta_cap' => true, @@ -328,7 +326,7 @@ class Tests_Post_Revisions extends WP_UnitTestCase { $post_id = self::factory()->post->create( array( - 'post_type' => $this->post_type, + 'post_type' => self::POST_TYPE, 'post_author' => self::$editor_user_id, ) ); @@ -360,7 +358,7 @@ class Tests_Post_Revisions extends WP_UnitTestCase { */ public function test_revision_restore_caps_cpt() { register_post_type( - $this->post_type, + self::POST_TYPE, array( 'capability_type' => 'event', 'map_meta_cap' => true, @@ -375,7 +373,7 @@ class Tests_Post_Revisions extends WP_UnitTestCase { // Create a post as Editor. $post_id = self::factory()->post->create( array( - 'post_type' => $this->post_type, + 'post_type' => self::POST_TYPE, 'post_author' => self::$editor_user_id, ) ); @@ -406,7 +404,7 @@ class Tests_Post_Revisions extends WP_UnitTestCase { */ public function test_revision_restore_caps_before_publish() { register_post_type( - $this->post_type, + self::POST_TYPE, array( 'capability_type' => 'post', 'capabilities' => array( @@ -424,7 +422,7 @@ class Tests_Post_Revisions extends WP_UnitTestCase { $post_id = self::factory()->post->create( array( - 'post_type' => $this->post_type, + 'post_type' => self::POST_TYPE, 'post_status' => 'draft', ) ); @@ -466,7 +464,7 @@ class Tests_Post_Revisions extends WP_UnitTestCase { */ public function test_revision_diff_caps_cpt() { register_post_type( - $this->post_type, + self::POST_TYPE, array( 'capability_type' => 'event', 'map_meta_cap' => true, @@ -476,7 +474,7 @@ class Tests_Post_Revisions extends WP_UnitTestCase { $post_id = self::factory()->post->create( array( - 'post_type' => $this->post_type, + 'post_type' => self::POST_TYPE, 'post_author' => self::$editor_user_id, ) );