WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/15/2019 11:03:45 AM (2 months ago)
Author:
SergeyBiryukov
Message:

Code Modernisation: Introduce the spread operator in tests/phpunit/*.

Rather than relying func_get_args() to retrieve arbitrary function arguments, we can now use the spread operator to assign them directly to a variable.

Props jrf.
See #47678.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/abstract-testcase.php

    r45588 r46127  
    904904     *
    905905     * Any properties that are listed by name as parameters will be expected to be true; all others are
    906      * expected to be false. For example, assertQueryTrue('is_single', 'is_feed') means is_single()
     906     * expected to be false. For example, assertQueryTrue( 'is_single', 'is_feed' ) means is_single()
    907907     * and is_feed() must be true and everything else must be false to pass.
    908908     *
     
    912912     * @param string ...$prop Any number of WP_Query properties that are expected to be true for the current request.
    913913     */
    914     public function assertQueryTrue() {
     914    public function assertQueryTrue( ...$prop ) {
    915915        global $wp_query;
    916         $all  = array(
     916
     917        $all = array(
    917918            'is_404',
    918919            'is_admin',
     
    945946            'is_year',
    946947        );
    947         $true = func_get_args();
    948 
    949         foreach ( $true as $true_thing ) {
     948
     949        foreach ( $prop as $true_thing ) {
    950950            $this->assertContains( $true_thing, $all, "Unknown conditional: {$true_thing}." );
    951951        }
     
    957957            $result = is_callable( $query_thing ) ? call_user_func( $query_thing ) : $wp_query->$query_thing;
    958958
    959             if ( in_array( $query_thing, $true, true ) ) {
     959            if ( in_array( $query_thing, $prop, true ) ) {
    960960                if ( ! $result ) {
    961961                    $message .= $query_thing . ' is false but is expected to be true. ' . PHP_EOL;
Note: See TracChangeset for help on using the changeset viewer.