Make WordPress Core

Changeset 61424


Ignore:
Timestamp:
01/03/2026 06:15:57 AM (2 months ago)
Author:
westonruter
Message:

Code Modernization: Update tests to use null coalescing operator in place of isset() in ternaries.

Developed as a subset of https://github.com/WordPress/wordpress-develop/pull/10654

Follow-up to [61404], [61403].

See #58874, #63430.

Location:
trunk/tests/phpunit
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/data/WPHTTP-testcase-redirection-script.php

    r55210 r61424  
    5555if ( 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'] ) ) {
     
    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
    129129if ( $r < $rt ) {
  • trunk/tests/phpunit/includes/abstract-testcase.php

    r61038 r61424  
    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'];
  • trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-term.php

    r55019 r61424  
    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 );
  • trunk/tests/phpunit/includes/mock-fs.php

    r56548 r61424  
    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    }
     
    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
  • trunk/tests/phpunit/tests/abilities-api/wpRegisterAbility.php

    r61364 r61424  
    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.
     
    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.
     
    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.
     
    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.
     
    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.
  • trunk/tests/phpunit/tests/abilities-api/wpRegisterAbilityCategory.php

    r61130 r61424  
    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.
     
    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.
     
    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.
     
    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.
     
    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.
  • trunk/tests/phpunit/tests/admin/wpPluginsListTable.php

    r60729 r61424  
    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
  • trunk/tests/phpunit/tests/block-bindings/postMetaSource.php

    r58972 r61424  
    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
  • trunk/tests/phpunit/tests/cron.php

    r60925 r61424  
    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        );
  • trunk/tests/phpunit/tests/dependencies/scripts.php

    r61415 r61424  
    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' );
  • trunk/tests/phpunit/tests/filesystem/wpFilesystemDirect/base.php

    r58684 r61424  
    9191                $this->create_file_if_needed(
    9292                    $entry['path'],
    93                     isset( $entry['contents'] ) ? $entry['contents'] : ''
     93                    $entry['contents'] ?? ''
    9494                );
    9595            }
  • trunk/tests/phpunit/tests/fonts/font-library/wpRestFontFamiliesController.php

    r60918 r61424  
    10491049            $this->assertSame( $expected, $link['href'], 'The links for a font faces URL from the response data should match the REST endpoint.' );
    10501050
    1051             $embeddable = isset( $link['attributes']['embeddable'] )
    1052                 ? $link['attributes']['embeddable']
    1053                 : $link['embeddable'];
     1051            $embeddable = $link['attributes']['embeddable'] ?? $link['embeddable'];
    10541052            $this->assertTrue( $embeddable, 'The embeddable should be true.' );
    10551053        }
  • trunk/tests/phpunit/tests/general/wpResourceHints.php

    r56548 r61424  
    1313    public function set_up() {
    1414        parent::set_up();
    15         $this->old_wp_scripts = isset( $GLOBALS['wp_scripts'] ) ? $GLOBALS['wp_scripts'] : null;
    16         $this->old_wp_styles  = isset( $GLOBALS['wp_styles'] ) ? $GLOBALS['wp_styles'] : null;
     15        $this->old_wp_scripts = $GLOBALS['wp_scripts'] ?? null;
     16        $this->old_wp_styles  = $GLOBALS['wp_styles'] ?? null;
    1717
    1818        remove_action( 'wp_default_scripts', 'wp_default_scripts' );
  • trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-router-region.php

    r59130 r61424  
    4646
    4747        // Removes all registered styles.
    48         $this->original_wp_styles = isset( $GLOBALS['wp_styles'] ) ? $GLOBALS['wp_styles'] : null;
     48        $this->original_wp_styles = $GLOBALS['wp_styles'] ?? null;
    4949        $GLOBALS['wp_styles']     = new WP_Styles();
    5050        remove_action( 'wp_default_styles', 'wp_default_styles' );
  • trunk/tests/phpunit/tests/l10n/loadScriptTextdomain.php

    r59264 r61424  
    2121    public function test_resolve_relative_path( $translation_path, $handle, $src, $textdomain, $filter = array() ) {
    2222        if ( ! empty( $filter ) ) {
    23             add_filter( $filter[0], $filter[1], 10, isset( $filter[2] ) ? $filter[2] : 1 );
     23            add_filter( $filter[0], $filter[1], 10, $filter[2] ?? 1 );
    2424        }
    2525        wp_enqueue_script( $handle, $src, array(), null );
  • trunk/tests/phpunit/tests/link/getAdjacentPost.php

    r61066 r61424  
    193193
    194194        // Fake current page.
    195         $_post           = isset( $GLOBALS['post'] ) ? $GLOBALS['post'] : null;
     195        $_post           = $GLOBALS['post'] ?? null;
    196196        $GLOBALS['post'] = get_post( $p1 );
    197197
     
    230230
    231231        // Fake current page.
    232         $_post           = isset( $GLOBALS['post'] ) ? $GLOBALS['post'] : null;
     232        $_post           = $GLOBALS['post'] ?? null;
    233233        $GLOBALS['post'] = get_post( $p1 );
    234234
  • trunk/tests/phpunit/tests/oembed/controller.php

    r60253 r61424  
    9494
    9595        $parsed_url = wp_parse_url( $url );
    96         $query      = isset( $parsed_url['query'] ) ? $parsed_url['query'] : '';
     96        $query      = $parsed_url['query'] ?? '';
    9797        parse_str( $query, $query_params );
    9898        $this->request_count += 1;
  • trunk/tests/phpunit/tests/post/thumbnails.php

    r59235 r61424  
    288288     */
    289289    public function test__wp_preview_post_thumbnail_filter() {
    290         $old_post = isset( $GLOBALS['post'] ) ? $GLOBALS['post'] : null;
     290        $old_post = $GLOBALS['post'] ?? null;
    291291
    292292        $GLOBALS['post']           = self::$post;
     
    308308     */
    309309    public function test__wp_preview_post_thumbnail_filter_secondary_post() {
    310         $old_post = isset( $GLOBALS['post'] ) ? $GLOBALS['post'] : null;
     310        $old_post = $GLOBALS['post'] ?? null;
    311311
    312312        $secondary_post = self::factory()->post->create(
  • trunk/tests/phpunit/tests/rest-api/application-passwords.php

    r59084 r61424  
    155155        $updated_item = WP_Application_Passwords::get_user_application_password( self::$user_id, $uuid );
    156156        foreach ( $updated_item as $key => $update_value ) {
    157             $expected_value = isset( $update[ $key ] ) ? $update[ $key ] : $original_item[ $key ];
     157            $expected_value = $update[ $key ] ?? $original_item[ $key ];
    158158            $this->assertSame( $expected_value, $update_value );
    159159        }
  • trunk/tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php

    r60729 r61424  
    8383    public function assertPatternMatchesSchema( $pattern ) {
    8484        $schema     = static::$controller->get_item_schema();
    85         $pattern_id = isset( $pattern->id ) ? $pattern->id : '{pattern ID is missing}';
     85        $pattern_id = $pattern->id ?? '{pattern ID is missing}';
    8686
    8787        $this->assertTrue(
  • trunk/tests/phpunit/tests/rest-api/rest-post-meta-fields.php

    r59023 r61424  
    2222        );
    2323
    24         self::$wp_meta_keys_saved = isset( $GLOBALS['wp_meta_keys'] ) ? $GLOBALS['wp_meta_keys'] : array();
     24        self::$wp_meta_keys_saved = $GLOBALS['wp_meta_keys'] ?? array();
    2525        self::$post_id            = $factory->post->create();
    2626        self::$cpt_post_id        = $factory->post->create( array( 'post_type' => 'cpt' ) );
  • trunk/tests/phpunit/tests/rest-api/rest-term-meta-fields.php

    r55457 r61424  
    2222        );
    2323
    24         self::$wp_meta_keys_saved = isset( $GLOBALS['wp_meta_keys'] ) ? $GLOBALS['wp_meta_keys'] : array();
     24        self::$wp_meta_keys_saved = $GLOBALS['wp_meta_keys'] ?? array();
    2525        self::$category_id        = $factory->category->create();
    2626        self::$customtax_term_id  = $factory->term->create( array( 'taxonomy' => 'customtax' ) );
  • trunk/tests/phpunit/tests/shortcode.php

    r60251 r61424  
    4949    // [footag foo="bar"]
    5050    public function shortcode_footag( $atts ) {
    51         $foo = isset( $atts['foo'] ) ? $atts['foo'] : '';
     51        $foo = $atts['foo'] ?? '';
    5252        return "foo = $foo";
    5353    }
Note: See TracChangeset for help on using the changeset viewer.