Make WordPress Core


Ignore:
Timestamp:
11/01/2021 10:22:49 PM (3 years ago)
Author:
hellofromTonya
Message:

Build/Test Tools: Ignore "null to nullable" deprecations for select tests.

Adds an expectation for PHP 8.1 "passing null to non-nullable" deprecation notice to select tests where the deprecation is generated by one of the functions in the wp-includes/formatting.php file, either via a filter hook callback or by a direct call.

Instead of haphazardly fixing these issues exposed by the tests, a more structural and all-encompassing solution for input validation should be architected and implemented as otherwise, we'll keep running into similar issues time and again with each new PHP version.

To discourage people from "fixing" these issues now anyway, this commit "hides" nearly all of these issues from the test runs.

Once a more structural solution is designed, these tests and the underlying functions causing the deprecation notices should be revisited and the structural solution put in place.

Includes a few minor other tweaks to select tests:

  • Removing a stray return (twice) from assertion statements.
  • Removing calls to ob_*() functions in favour of letting PHPUnit manage the output catching. This prevents warnings along the lines of Test code or tested code did not (only) close its own output buffers.

Props jrf, hellofromTonya.
See #53635.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/dependencies/scripts.php

    r51576 r51968  
    721721        $wp_scripts->base_url  = '';
    722722        $wp_scripts->do_concat = true;
     723
     724        if ( PHP_VERSION_ID >= 80100 ) {
     725            /*
     726             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     727             * via hooked in filter functions until a more structural solution to the
     728             * "missing input validation" conundrum has been architected and implemented.
     729             */
     730            $this->expectDeprecation();
     731            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     732        }
    723733
    724734        $ver       = get_bloginfo( 'version' );
     
    747757        wp_add_inline_script( 'test-example2', 'console.log("after");', 'after' );
    748758
    749         $print_scripts  = get_echo( 'wp_print_scripts' );
    750         $print_scripts .= get_echo( '_print_scripts' );
     759        // Effectively ignore the output until retrieving it later via `getActualOutput()`.
     760        $this->expectOutputRegex( '`.`' );
     761
     762        wp_print_scripts();
     763        _print_scripts();
     764        $print_scripts = $this->getActualOutput();
    751765
    752766        /*
     
    777791        $wp_scripts->do_concat = true;
    778792
     793        if ( PHP_VERSION_ID >= 80100 ) {
     794            /*
     795             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     796             * via hooked in filter functions until a more structural solution to the
     797             * "missing input validation" conundrum has been architected and implemented.
     798             */
     799            $this->expectDeprecation();
     800            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     801        }
     802
    779803        $expected_tail  = "<script type='text/javascript' src='/customize-dependency.js' id='customize-dependency-js'></script>\n";
    780804        $expected_tail .= "<script type='text/javascript' id='customize-dependency-js-after'>\n";
     
    786810        wp_add_inline_script( $handle, 'tryCustomizeDependency()' );
    787811
    788         $print_scripts  = get_echo( 'wp_print_scripts' );
    789         $print_scripts .= get_echo( '_print_scripts' );
     812        // Effectively ignore the output until retrieving it later via `getActualOutput()`.
     813        $this->expectOutputRegex( '`.`' );
     814
     815        wp_print_scripts();
     816        _print_scripts();
     817        $print_scripts = $this->getActualOutput();
    790818
    791819        $tail = substr( $print_scripts, strrpos( $print_scripts, "<script type='text/javascript' src='/customize-dependency.js' id='customize-dependency-js'>" ) );
Note: See TracChangeset for help on using the changeset viewer.