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
This commit is contained in:
Sergey Biryukov 2022-08-24 13:18:31 +00:00
parent ad00d45c9b
commit 6a854ec257

View File

@ -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 );