Make WordPress Core

Changeset 53853


Ignore:
Timestamp:
08/07/2022 02:41:04 PM (4 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/revisions.php

    r53841 r53853  
    66 */
    77class Tests_Post_Revisions extends WP_UnitTestCase {
     8
     9        const POST_TYPE = 'test-revision';
     10
    811        protected static $admin_user_id;
    912        protected static $editor_user_id;
    … …  
    1417                self::$editor_user_id = $factory->user->create( array( 'role' => 'editor' ) );
    1518                self::$author_user_id = $factory->user->create( array( 'role' => 'author' ) );
    16         }
    17 
    18         public function set_up() {
    19                 parent::set_up();
    20                 $this->post_type = 'test-revision';
    2119        }
    2220
    … …  
    319317        public function test_revision_view_caps_cpt() {
    320318                register_post_type(
    321                         $this->post_type,
     319                        self::POST_TYPE,
    322320                        array(
    323321                                'capability_type' => 'event',
    … …  
    329327                $post_id = self::factory()->post->create(
    330328                        array(
    331                                 'post_type'   => $this->post_type,
     329                                'post_type'   => self::POST_TYPE,
    332330                                'post_author' => self::$editor_user_id,
    333331                        )
    … …  
    361359        public function test_revision_restore_caps_cpt() {
    362360                register_post_type(
    363                         $this->post_type,
     361                        self::POST_TYPE,
    364362                        array(
    365363                                'capability_type' => 'event',
    … …  
    376374                $post_id = self::factory()->post->create(
    377375                        array(
    378                                 'post_type'   => $this->post_type,
     376                                'post_type'   => self::POST_TYPE,
    379377                                'post_author' => self::$editor_user_id,
    380378                        )
    … …  
    407405        public function test_revision_restore_caps_before_publish() {
    408406                register_post_type(
    409                         $this->post_type,
     407                        self::POST_TYPE,
    410408                        array(
    411409                                'capability_type' => 'post',
    … …  
    425423                $post_id = self::factory()->post->create(
    426424                        array(
    427                                 'post_type'   => $this->post_type,
     425                                'post_type'   => self::POST_TYPE,
    428426                                'post_status' => 'draft',
    429427                        )
    … …  
    467465        public function test_revision_diff_caps_cpt() {
    468466                register_post_type(
    469                         $this->post_type,
     467                        self::POST_TYPE,
    470468                        array(
    471469                                'capability_type' => 'event',
    … …  
    477475                $post_id = self::factory()->post->create(
    478476                        array(
    479                                 'post_type'   => $this->post_type,
     477                                'post_type'   => self::POST_TYPE,
    480478                                'post_author' => self::$editor_user_id,
    481479                        )
Note: See TracChangeset for help on using the changeset viewer.