Skip to content

Commit 745a537

Browse files
committed
Code Modernization: Update tests to use null coalescing operator in place of isset() in ternaries.
Developed as a subset of #10654 Follow-up to [61404], [61403]. See #58874, #63430. git-svn-id: https://develop.svn.wordpress.org/trunk@61424 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 48b7610 commit 745a537

23 files changed

+39
-41
lines changed

tests/phpunit/data/WPHTTP-testcase-redirection-script.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function is_ssl() {
5454

5555
if ( isset( $_GET['post-redirect-to-method'] ) ) {
5656
$method = $_SERVER['REQUEST_METHOD'];
57-
$response_code = isset( $_GET['response_code'] ) ? $_GET['response_code'] : 301;
57+
$response_code = $_GET['response_code'] ?? 301;
5858

5959
if ( 'POST' == $method && ! isset( $_GET['redirection-performed'] ) ) {
6060
header( "Location: $url?post-redirect-to-method=1&redirection-performed=1", true, $response_code );
@@ -123,8 +123,8 @@ function is_ssl() {
123123
}
124124

125125

126-
$rt = isset($_GET['rt']) ? $_GET['rt'] : 5;
127-
$r = isset($_GET['r']) ? $_GET['r'] : 0;
126+
$rt = $_GET['rt'] ?? 5;
127+
$r = $_GET['r'] ?? 0;
128128

129129
if ( $r < $rt ) {
130130
$code = isset($_GET['code']) ? (int)$_GET['code'] : 302;

tests/phpunit/includes/abstract-testcase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,7 @@ public function go_to( $url ) {
13131313
}
13141314
$parts = parse_url( $url );
13151315
if ( isset( $parts['scheme'] ) ) {
1316-
$req = isset( $parts['path'] ) ? $parts['path'] : '';
1316+
$req = $parts['path'] ?? '';
13171317
if ( isset( $parts['query'] ) ) {
13181318
$req .= '?' . $parts['query'];
13191319
// Parse the URL query vars into $_GET.

tests/phpunit/includes/factory/class-wp-unittest-factory-for-term.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function create_and_get( $args = array(), $generation_definitions = null
109109
return $term_id;
110110
}
111111

112-
$taxonomy = isset( $args['taxonomy'] ) ? $args['taxonomy'] : $this->taxonomy;
112+
$taxonomy = $args['taxonomy'] ?? $this->taxonomy;
113113

114114
return get_term( $term_id, $taxonomy );
115115
}

tests/phpunit/includes/mock-fs.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function init( $paths = '', $home_dir = '/' ) {
4646
'/' => $this->fs,
4747
);
4848
$this->cache = array(); // Used by find_folder() and friends.
49-
$this->cwd = isset( $this->fs_map[ $home_dir ] ) ? $this->fs_map[ $home_dir ] : '/';
49+
$this->cwd = $this->fs_map[ $home_dir ] ?? '/';
5050
$this->setfs( $paths );
5151
}
5252

@@ -79,7 +79,7 @@ public function setfs( $paths ) {
7979
* Locates a filesystem "node"
8080
*/
8181
private function locate_node( $path ) {
82-
return isset( $this->fs_map[ $path ] ) ? $this->fs_map[ $path ] : false;
82+
return $this->fs_map[ $path ] ?? false;
8383
}
8484

8585
/**

tests/phpunit/tests/abilities-api/wpRegisterAbility.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public function test_register_ability_no_init_action(): void {
154154
global $wp_actions;
155155

156156
// Store the original action count.
157-
$original_count = isset( $wp_actions['init'] ) ? $wp_actions['init'] : 0;
157+
$original_count = $wp_actions['init'] ?? 0;
158158

159159
// Reset the action count to simulate it not being fired.
160160
unset( $wp_actions['init'] );
@@ -450,7 +450,7 @@ public function test_unregister_ability_no_init_action(): void {
450450
global $wp_actions;
451451

452452
// Store the original action count.
453-
$original_count = isset( $wp_actions['init'] ) ? $wp_actions['init'] : 0;
453+
$original_count = $wp_actions['init'] ?? 0;
454454

455455
// Reset the action count to simulate it not being fired.
456456
unset( $wp_actions['init'] );
@@ -496,7 +496,7 @@ public function test_get_ability_no_init_action(): void {
496496
global $wp_actions;
497497

498498
// Store the original action count.
499-
$original_count = isset( $wp_actions['init'] ) ? $wp_actions['init'] : 0;
499+
$original_count = $wp_actions['init'] ?? 0;
500500

501501
// Reset the action count to simulate it not being fired.
502502
unset( $wp_actions['init'] );
@@ -559,7 +559,7 @@ public function test_has_ability_no_init_action(): void {
559559
global $wp_actions;
560560

561561
// Store the original action count.
562-
$original_count = isset( $wp_actions['init'] ) ? $wp_actions['init'] : 0;
562+
$original_count = $wp_actions['init'] ?? 0;
563563

564564
// Reset the action count to simulate it not being fired.
565565
unset( $wp_actions['init'] );
@@ -615,7 +615,7 @@ public function test_get_abilities_no_init_action(): void {
615615
global $wp_actions;
616616

617617
// Store the original action count.
618-
$original_count = isset( $wp_actions['init'] ) ? $wp_actions['init'] : 0;
618+
$original_count = $wp_actions['init'] ?? 0;
619619

620620
// Reset the action count to simulate it not being fired.
621621
unset( $wp_actions['init'] );

tests/phpunit/tests/abilities-api/wpRegisterAbilityCategory.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function test_register_ability_category_no_init_action(): void {
8282
global $wp_actions;
8383

8484
// Store the original action count.
85-
$original_count = isset( $wp_actions['init'] ) ? $wp_actions['init'] : 0;
85+
$original_count = $wp_actions['init'] ?? 0;
8686

8787
// Reset the action count to simulate it not being fired.
8888
unset( $wp_actions['init'] );
@@ -132,7 +132,7 @@ public function test_unregister_ability_category_no_init_action(): void {
132132
global $wp_actions;
133133

134134
// Store the original action count.
135-
$original_count = isset( $wp_actions['init'] ) ? $wp_actions['init'] : 0;
135+
$original_count = $wp_actions['init'] ?? 0;
136136

137137
// Reset the action count to simulate it not being fired.
138138
unset( $wp_actions['init'] );
@@ -194,7 +194,7 @@ public function test_has_ability_category_no_init_action(): void {
194194
global $wp_actions;
195195

196196
// Store the original action count.
197-
$original_count = isset( $wp_actions['init'] ) ? $wp_actions['init'] : 0;
197+
$original_count = $wp_actions['init'] ?? 0;
198198

199199
// Reset the action count to simulate it not being fired.
200200
unset( $wp_actions['init'] );
@@ -255,7 +255,7 @@ public function test_get_ability_category_no_init_action(): void {
255255
global $wp_actions;
256256

257257
// Store the original action count.
258-
$original_count = isset( $wp_actions['init'] ) ? $wp_actions['init'] : 0;
258+
$original_count = $wp_actions['init'] ?? 0;
259259

260260
// Reset the action count to simulate it not being fired.
261261
unset( $wp_actions['init'] );
@@ -328,7 +328,7 @@ public function test_get_ability_categories_no_init_action(): void {
328328
global $wp_actions;
329329

330330
// Store the original action count.
331-
$original_count = isset( $wp_actions['init'] ) ? $wp_actions['init'] : 0;
331+
$original_count = $wp_actions['init'] ?? 0;
332332

333333
// Reset the action count to simulate it not being fired.
334334
unset( $wp_actions['init'] );

tests/phpunit/tests/admin/wpPluginsListTable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function test_get_views_should_return_views_by_default() {
137137
* @param string $status The value for $_REQUEST['plugin_status'].
138138
*/
139139
public function test_construct_should_not_set_show_autoupdates_to_false_for_mustuse_and_dropins( $status ) {
140-
$original_status = isset( $_REQUEST['plugin_status'] ) ? $_REQUEST['plugin_status'] : null;
140+
$original_status = $_REQUEST['plugin_status'] ?? null;
141141
$_REQUEST['plugin_status'] = $status;
142142

143143
// Enable plugin auto-updates.

tests/phpunit/tests/block-bindings/postMetaSource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ private function get_modified_post_content( $content ) {
2828
*/
2929
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
3030
self::$post = $factory->post->create_and_get();
31-
self::$wp_meta_keys_saved = isset( $GLOBALS['wp_meta_keys'] ) ? $GLOBALS['wp_meta_keys'] : array();
31+
self::$wp_meta_keys_saved = $GLOBALS['wp_meta_keys'] ?? array();
3232
}
3333

3434
/**

tests/phpunit/tests/cron.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ public function filter_pre_schedule_event_filter( $result, $event ) {
460460

461461
$this->preflight_cron_array[ $event->timestamp ][ $event->hook ][ $key ] = array(
462462
'schedule' => $event->schedule,
463-
'interval' => isset( $event->interval ) ? $event->interval : 0,
463+
'interval' => $event->interval ?? 0,
464464
'args' => $event->args,
465465
);
466466
uksort( $this->preflight_cron_array, 'strnatcasecmp' );

tests/phpunit/tests/dependencies/scripts.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ class Tests_Dependencies_Scripts extends WP_UnitTestCase {
3737

3838
public function set_up() {
3939
parent::set_up();
40-
$this->old_wp_scripts = isset( $GLOBALS['wp_scripts'] ) ? $GLOBALS['wp_scripts'] : null;
41-
$this->old_wp_styles = isset( $GLOBALS['wp_styles'] ) ? $GLOBALS['wp_styles'] : null;
42-
$this->old_concatenate_scripts = isset( $GLOBALS['concatenate_scripts'] ) ? $GLOBALS['concatenate_scripts'] : null;
40+
$this->old_wp_scripts = $GLOBALS['wp_scripts'] ?? null;
41+
$this->old_wp_styles = $GLOBALS['wp_styles'] ?? null;
42+
$this->old_concatenate_scripts = $GLOBALS['concatenate_scripts'] ?? null;
4343
remove_action( 'wp_default_scripts', 'wp_default_scripts' );
4444
remove_action( 'wp_default_scripts', 'wp_default_packages' );
4545
$GLOBALS['wp_scripts'] = new WP_Scripts();

0 commit comments

Comments
 (0)