Skip to content

Commit fe28df6

Browse files
committed
Coding Standards: Fix the Squiz.PHP.DisallowMultipleAssignments violations in tests.
See #47632. git-svn-id: https://develop.svn.wordpress.org/trunk@45588 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 969c17d commit fe28df6

36 files changed

+279
-133
lines changed

tests/phpunit/includes/abstract-testcase.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,8 @@ public function go_to( $url ) {
706706
// note: the WP and WP_Query classes like to silently fetch parameters
707707
// from all over the place (globals, GET, etc), which makes it tricky
708708
// to run them more than once without very carefully clearing everything
709-
$_GET = $_POST = array();
709+
$_GET = array();
710+
$_POST = array();
710711
foreach ( array( 'query_string', 'id', 'postdata', 'authordata', 'day', 'currentmonth', 'page', 'pages', 'multipage', 'more', 'numpages', 'pagenow', 'current_screen' ) as $v ) {
711712
if ( isset( $GLOBALS[ $v ] ) ) {
712713
unset( $GLOBALS[ $v ] );

tests/phpunit/includes/bootstrap.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@
7171

7272
define( 'REST_TESTS_IMPOSSIBLY_HIGH_NUMBER', 99999999 );
7373

74-
$PHP_SELF = $GLOBALS['PHP_SELF'] = $_SERVER['PHP_SELF'] = '/index.php';
74+
$PHP_SELF = '/index.php';
75+
$GLOBALS['PHP_SELF'] = '/index.php';
76+
$_SERVER['PHP_SELF'] = '/index.php';
7577

7678
// Should we run in multisite mode?
7779
$multisite = '1' == getenv( 'WP_MULTISITE' );

tests/phpunit/includes/install.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020

2121
tests_reset__SERVER();
2222

23-
$PHP_SELF = $GLOBALS['PHP_SELF'] = $_SERVER['PHP_SELF'] = '/index.php';
23+
$PHP_SELF = '/index.php';
24+
$GLOBALS['PHP_SELF'] = '/index.php';
25+
$_SERVER['PHP_SELF'] = '/index.php';
2426

2527
tests_add_filter( 'wp_die_handler', '_wp_die_handler_filter_exit' );
2628

tests/phpunit/includes/phpunit7/speed-trap-listener.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ protected function renderBody() {
266266
* Renders slow test report footer.
267267
*/
268268
protected function renderFooter() {
269-
if ( $hidden = $this->getHiddenCount( $this->slow ) ) {
269+
$hidden = $this->getHiddenCount( $this->slow );
270+
if ( $hidden ) {
270271
echo sprintf( '...and there %s %s more above your threshold hidden from view', $hidden == 1 ? 'is' : 'are', $hidden );
271272
}
272273
}

tests/phpunit/includes/testcase-canonical.php

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,22 @@ public static function generate_shared_fixtures( $factory ) {
6161
'post_date' => '2008-06-02 00:00:00',
6262
)
6363
);
64-
self::$post_ids[] = $post_id = $factory->post->create(
64+
$post_id = $factory->post->create(
6565
array(
6666
'post_title' => 'post-format-test-gallery',
6767
'post_date' => '2008-06-10 00:00:00',
6868
)
6969
);
70-
self::$post_ids[] = $factory->post->create(
70+
self::$post_ids[] = $post_id;
71+
$factory->post->create(
7172
array(
7273
'import_id' => 611,
7374
'post_type' => 'attachment',
7475
'post_title' => 'canola2',
7576
'post_parent' => $post_id,
7677
)
7778
);
79+
self::$post_ids[] = $post_id;
7880

7981
self::$post_ids[] = $factory->post->create(
8082
array(
@@ -84,13 +86,14 @@ public static function generate_shared_fixtures( $factory ) {
8486
)
8587
);
8688

87-
self::$post_ids[] = $post_id = $factory->post->create(
89+
$post_id = $factory->post->create(
8890
array(
8991
'import_id' => 149,
9092
'post_title' => 'comment-test',
9193
'post_date' => '2008-03-03 00:00:00',
9294
)
9395
);
96+
self::$post_ids[] = $post_id;
9497
self::$comment_ids = $factory->comment->create_post_comments( $post_id, 15 );
9598

9699
self::$post_ids[] = $factory->post->create( array( 'post_date' => '2008-09-05 00:00:00' ) );
@@ -111,12 +114,13 @@ public static function generate_shared_fixtures( $factory ) {
111114
'post_title' => 'about',
112115
)
113116
);
114-
self::$post_ids[] = $post_id = $factory->post->create(
117+
$post_id = $factory->post->create(
115118
array(
116119
'post_type' => 'page',
117120
'post_title' => 'parent-page',
118121
)
119122
);
123+
self::$post_ids[] = $post_id;
120124
self::$post_ids[] = $factory->post->create(
121125
array(
122126
'import_id' => 144,
@@ -126,40 +130,45 @@ public static function generate_shared_fixtures( $factory ) {
126130
)
127131
);
128132

129-
self::$post_ids[] = $parent_id = $factory->post->create(
133+
$parent_id = $factory->post->create(
130134
array(
131135
'post_name' => 'parent',
132136
'post_type' => 'page',
133137
)
134138
);
135-
self::$post_ids[] = $child_id_1 = $factory->post->create(
139+
self::$post_ids[] = $parent_id;
140+
$child_id_1 = $factory->post->create(
136141
array(
137142
'post_name' => 'child1',
138143
'post_type' => 'page',
139144
'post_parent' => $parent_id,
140145
)
141146
);
142-
self::$post_ids[] = $child_id_2 = $factory->post->create(
147+
self::$post_ids[] = $child_id_1;
148+
$child_id_2 = $factory->post->create(
143149
array(
144150
'post_name' => 'child2',
145151
'post_type' => 'page',
146152
'post_parent' => $parent_id,
147153
)
148154
);
149-
self::$post_ids[] = $grandchild_id_1 = $factory->post->create(
155+
self::$post_ids[] = $child_id_2;
156+
$grandchild_id_1 = $factory->post->create(
150157
array(
151158
'post_name' => 'grandchild',
152159
'post_type' => 'page',
153160
'post_parent' => $child_id_1,
154161
)
155162
);
156-
self::$post_ids[] = $grandchild_id_2 = $factory->post->create(
163+
self::$post_ids[] = $grandchild_id_1;
164+
$grandchild_id_2 = $factory->post->create(
157165
array(
158166
'post_name' => 'grandchild',
159167
'post_type' => 'page',
160168
'post_parent' => $child_id_2,
161169
)
162170
);
171+
self::$post_ids[] = $grandchild_id_2;
163172

164173
$cat1 = $factory->term->create(
165174
array(

tests/phpunit/tests/admin/includesPlugin.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,8 @@ private function _back_up_mu_plugins() {
406406
}
407407

408408
$files_to_move = array();
409-
if ( $mu_plugins = opendir( WPMU_PLUGIN_DIR ) ) {
409+
$mu_plugins = opendir( WPMU_PLUGIN_DIR );
410+
if ( $mu_plugins ) {
410411
while ( false !== $plugin = readdir( $mu_plugins ) ) {
411412
if ( 0 !== strpos( $plugin, '.' ) ) {
412413
$files_to_move[] = $plugin;
@@ -432,7 +433,8 @@ private function _back_up_mu_plugins() {
432433
private function _restore_mu_plugins() {
433434
$mu_bu_dir = WP_CONTENT_DIR . '/mu-plugin-backup';
434435
$files_to_move = array();
435-
if ( is_dir( $mu_bu_dir ) && $mu_plugins = opendir( $mu_bu_dir ) ) {
436+
$mu_plugins = @opendir( $mu_bu_dir );
437+
if ( $mu_plugins ) {
436438
while ( false !== $plugin = readdir( $mu_plugins ) ) {
437439
if ( 0 !== strpos( $plugin, '.' ) ) {
438440
$files_to_move[] = $plugin;

tests/phpunit/tests/admin/includesPost.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ class Tests_Admin_Includes_Post extends WP_UnitTestCase {
1313
protected static $user_ids = array();
1414

1515
public static function wpSetUpBeforeClass( $factory ) {
16-
self::$user_ids = self::$author_ids = $factory->user->create_many( 2, array( 'role' => 'author' ) );
17-
18-
self::$user_ids[] = self::$contributor_id = $factory->user->create( array( 'role' => 'contributor' ) );
19-
self::$user_ids[] = self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) );
20-
self::$user_ids[] = self::$admin_id = $factory->user->create( array( 'role' => 'administrator' ) );
16+
self::$user_ids = $factory->user->create_many( 2, array( 'role' => 'author' ) );
17+
self::$author_ids = self::$user_ids;
18+
19+
self::$contributor_id = $factory->user->create( array( 'role' => 'contributor' ) );
20+
self::$user_ids[] = self::$contributor_id;
21+
self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) );
22+
self::$user_ids[] = self::$editor_id;
23+
self::$admin_id = $factory->user->create( array( 'role' => 'administrator' ) );
24+
self::$user_ids[] = self::$admin_id;
2125

2226
self::$post_id = $factory->post->create();
2327
}

tests/phpunit/tests/admin/includesScreen.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,20 +171,32 @@ function test_set_current_screen_with_hook_suffix() {
171171
global $current_screen;
172172

173173
foreach ( $this->core_screens as $hook_name => $screen ) {
174-
$_GET = $_POST = $_REQUEST = array();
175-
$GLOBALS['taxnow'] = $GLOBALS['typenow'] = '';
176-
$screen = (object) $screen;
177-
$hook = parse_url( $hook_name );
174+
$_GET = array();
175+
$_POST = array();
176+
$_REQUEST = array();
177+
$GLOBALS['taxnow'] = '';
178+
$GLOBALS['typenow'] = '';
179+
$screen = (object) $screen;
180+
$hook = parse_url( $hook_name );
178181

179182
if ( ! empty( $hook['query'] ) ) {
180183
$args = wp_parse_args( $hook['query'] );
181184
if ( isset( $args['taxonomy'] ) ) {
182-
$GLOBALS['taxnow'] = $_GET['taxonomy'] = $_POST['taxonomy'] = $_REQUEST['taxonomy'] = $args['taxonomy'];
185+
$GLOBALS['taxnow'] = $args['taxonomy'];
186+
$_GET['taxonomy'] = $args['taxonomy'];
187+
$_POST['taxonomy'] = $args['taxonomy'];
188+
$_REQUEST['taxonomy'] = $args['taxonomy'];
183189
}
184190
if ( isset( $args['post_type'] ) ) {
185-
$GLOBALS['typenow'] = $_GET['post_type'] = $_POST['post_type'] = $_REQUEST['post_type'] = $args['post_type'];
191+
$GLOBALS['typenow'] = $args['post_type'];
192+
$_GET['post_type'] = $args['post_type'];
193+
$_POST['post_type'] = $args['post_type'];
194+
$_REQUEST['post_type'] = $args['post_type'];
186195
} elseif ( isset( $screen->post_type ) ) {
187-
$GLOBALS['typenow'] = $_GET['post_type'] = $_POST['post_type'] = $_REQUEST['post_type'] = $screen->post_type;
196+
$GLOBALS['typenow'] = $screen->post_type;
197+
$_GET['post_type'] = $screen->post_type;
198+
$_POST['post_type'] = $screen->post_type;
199+
$_REQUEST['post_type'] = $screen->post_type;
188200
}
189201
}
190202

@@ -484,7 +496,10 @@ function test_in_admin() {
484496
public function setup_block_editor_test( $hook = 'post.php' ) {
485497
register_post_type( 'type_shows_in_rest', array( 'show_in_rest' => true ) );
486498

487-
$GLOBALS['typenow'] = $_GET['post_type'] = $_POST['post_type'] = $_REQUEST['post_type'] = 'type_shows_in_rest';
499+
$GLOBALS['typenow'] = 'type_shows_in_rest';
500+
$_GET['post_type'] = 'type_shows_in_rest';
501+
$_POST['post_type'] = 'type_shows_in_rest';
502+
$_REQUEST['post_type'] = 'type_shows_in_rest';
488503
$GLOBALS['hook_suffix'] = $hook;
489504

490505
if ( 'post.php' === $hook ) {

tests/phpunit/tests/adminbar.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@ public static function setUpBeforeClass() {
2121
}
2222

2323
public static function wpSetUpBeforeClass( $factory ) {
24-
self::$user_ids[] = self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) );
25-
self::$user_ids[] = self::$admin_id = $factory->user->create( array( 'role' => 'administrator' ) );
26-
self::$user_ids[] = self::$no_role_id = $factory->user->create( array( 'role' => '' ) );
24+
self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) );
25+
self::$user_ids[] = self::$editor_id;
26+
self::$admin_id = $factory->user->create( array( 'role' => 'administrator' ) );
27+
self::$user_ids[] = self::$admin_id;
28+
self::$no_role_id = $factory->user->create( array( 'role' => '' ) );
29+
self::$user_ids[] = self::$no_role_id;
2730
}
2831

2932
/**

tests/phpunit/tests/ajax/Autosave.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ class Tests_Ajax_Autosave extends WP_Ajax_UnitTestCase {
2929
protected static $user_ids = array();
3030

3131
public static function wpSetUpBeforeClass( $factory ) {
32-
self::$user_ids[] = self::$admin_id = $factory->user->create( array( 'role' => 'administrator' ) );
33-
self::$user_ids[] = self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) );
32+
self::$admin_id = $factory->user->create( array( 'role' => 'administrator' ) );
33+
self::$user_ids[] = self::$admin_id;
34+
self::$editor_id = $factory->user->create( array( 'role' => 'editor' ) );
35+
self::$user_ids[] = self::$editor_id;
3436

3537
self::$post_id = $factory->post->create( array( 'post_status' => 'draft' ) );
3638
self::$post = get_post( self::$post_id );

0 commit comments

Comments
 (0)