Make WordPress Core

Changeset 53936


Ignore:
Timestamp:
08/24/2022 01:18:31 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Code Modernization: Remove dynamic properties in WP_Test_REST_Users_Controller.

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 these particular cases, individual tests set a couple of properties ($author_id, $post_id) that are never used outside of the context of the test in which they are created.

In other words: these should never have been properties, but should be local variables instead.

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

Props jrf.
See #56033.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-users-controller.php

    r53510 r53936  
    11101110
    11111111    public function test_get_item_published_author_post() {
    1112         $this->author_id = $this->factory->user->create(
     1112        $author_id = $this->factory->user->create(
    11131113            array(
    11141114                'role' => 'author',
     
    11161116        );
    11171117
    1118         $this->post_id = $this->factory->post->create(
    1119             array(
    1120                 'post_author' => $this->author_id,
     1118        $post_id = $this->factory->post->create(
     1119            array(
     1120                'post_author' => $author_id,
    11211121            )
    11221122        );
     
    11241124        wp_set_current_user( 0 );
    11251125
    1126         $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $this->author_id ) );
     1126        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $author_id ) );
    11271127        $response = rest_get_server()->dispatch( $request );
    11281128        $this->check_get_user_response( $response, 'embed' );
     
    11301130
    11311131    public function test_get_item_published_author_pages() {
    1132         $this->author_id = $this->factory->user->create(
     1132        $author_id = $this->factory->user->create(
    11331133            array(
    11341134                'role' => 'author',
     
    11381138        wp_set_current_user( 0 );
    11391139
    1140         $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $this->author_id ) );
     1140        $request  = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $author_id ) );
    11411141        $response = rest_get_server()->dispatch( $request );
    11421142        $this->assertSame( 401, $response->get_status() );
    11431143
    1144         $this->post_id = $this->factory->post->create(
    1145             array(
    1146                 'post_author' => $this->author_id,
     1144        $post_id = $this->factory->post->create(
     1145            array(
     1146                'post_author' => $author_id,
    11471147                'post_type'   => 'page',
    11481148            )
     
    11651165
    11661166    public function test_get_item_published_author_wrong_context() {
    1167         $this->author_id = $this->factory->user->create(
     1167        $author_id = $this->factory->user->create(
    11681168            array(
    11691169                'role' => 'author',
     
    11711171        );
    11721172
    1173         $this->post_id = $this->factory->post->create(
    1174             array(
    1175                 'post_author' => $this->author_id,
     1173        $post_id = $this->factory->post->create(
     1174            array(
     1175                'post_author' => $author_id,
    11761176            )
    11771177        );
     
    11791179        wp_set_current_user( 0 );
    11801180
    1181         $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $this->author_id ) );
     1181        $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $author_id ) );
    11821182        $request->set_param( 'context', 'edit' );
    11831183        $response = rest_get_server()->dispatch( $request );
Note: See TracChangeset for help on using the changeset viewer.