From 6a854ec257faacbec50a23858e4192a338dd7ec6 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 24 Aug 2022 13:18:31 +0000 Subject: [PATCH] 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. git-svn-id: https://develop.svn.wordpress.org/trunk@53936 602fd350-edb4-49c9-b593-d223f7449a82 --- .../tests/rest-api/rest-users-controller.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-users-controller.php b/tests/phpunit/tests/rest-api/rest-users-controller.php index c83c59d21d..bb586134cb 100644 --- a/tests/phpunit/tests/rest-api/rest-users-controller.php +++ b/tests/phpunit/tests/rest-api/rest-users-controller.php @@ -1109,27 +1109,27 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { } public function test_get_item_published_author_post() { - $this->author_id = $this->factory->user->create( + $author_id = $this->factory->user->create( array( 'role' => 'author', ) ); - $this->post_id = $this->factory->post->create( + $post_id = $this->factory->post->create( array( - 'post_author' => $this->author_id, + 'post_author' => $author_id, ) ); wp_set_current_user( 0 ); - $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $this->author_id ) ); + $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $author_id ) ); $response = rest_get_server()->dispatch( $request ); $this->check_get_user_response( $response, 'embed' ); } public function test_get_item_published_author_pages() { - $this->author_id = $this->factory->user->create( + $author_id = $this->factory->user->create( array( 'role' => 'author', ) @@ -1137,13 +1137,13 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { wp_set_current_user( 0 ); - $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $this->author_id ) ); + $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $author_id ) ); $response = rest_get_server()->dispatch( $request ); $this->assertSame( 401, $response->get_status() ); - $this->post_id = $this->factory->post->create( + $post_id = $this->factory->post->create( array( - 'post_author' => $this->author_id, + 'post_author' => $author_id, 'post_type' => 'page', ) ); @@ -1164,21 +1164,21 @@ class WP_Test_REST_Users_Controller extends WP_Test_REST_Controller_Testcase { } public function test_get_item_published_author_wrong_context() { - $this->author_id = $this->factory->user->create( + $author_id = $this->factory->user->create( array( 'role' => 'author', ) ); - $this->post_id = $this->factory->post->create( + $post_id = $this->factory->post->create( array( - 'post_author' => $this->author_id, + 'post_author' => $author_id, ) ); wp_set_current_user( 0 ); - $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $this->author_id ) ); + $request = new WP_REST_Request( 'GET', sprintf( '/wp/v2/users/%d', $author_id ) ); $request->set_param( 'context', 'edit' ); $response = rest_get_server()->dispatch( $request ); $this->assertErrorResponse( 'rest_user_cannot_view', $response, 401 );