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/xmlrpc/mw/newPost.php

    r51415 r51968  
    2323
    2424    function test_no_content() {
     25        if ( PHP_VERSION_ID >= 80100 ) {
     26            /*
     27             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     28             * via hooked in filter functions until a more structural solution to the
     29             * "missing input validation" conundrum has been architected and implemented.
     30             */
     31            $this->expectDeprecation();
     32            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     33        }
     34
    2535        $this->make_user_by_role( 'author' );
    2636
     
    3343
    3444    function test_basic_content() {
     45        if ( PHP_VERSION_ID >= 80100 ) {
     46            /*
     47             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     48             * via hooked in filter functions until a more structural solution to the
     49             * "missing input validation" conundrum has been architected and implemented.
     50             */
     51            $this->expectDeprecation();
     52            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     53        }
     54
    3555        $this->make_user_by_role( 'author' );
    3656
     
    4262
    4363    function test_ignore_id() {
     64        if ( PHP_VERSION_ID >= 80100 ) {
     65            /*
     66             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     67             * via hooked in filter functions until a more structural solution to the
     68             * "missing input validation" conundrum has been architected and implemented.
     69             */
     70            $this->expectDeprecation();
     71            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     72        }
     73
    4474        $this->make_user_by_role( 'author' );
    4575
     
    5484
    5585    function test_capable_publish() {
     86        if ( PHP_VERSION_ID >= 80100 ) {
     87            /*
     88             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     89             * via hooked in filter functions until a more structural solution to the
     90             * "missing input validation" conundrum has been architected and implemented.
     91             */
     92            $this->expectDeprecation();
     93            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     94        }
     95
    5696        $this->make_user_by_role( 'author' );
    5797
     
    77117
    78118    function test_capable_other_author() {
     119        if ( PHP_VERSION_ID >= 80100 ) {
     120            /*
     121             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     122             * via hooked in filter functions until a more structural solution to the
     123             * "missing input validation" conundrum has been architected and implemented.
     124             */
     125            $this->expectDeprecation();
     126            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     127        }
     128
    79129        $this->make_user_by_role( 'editor' );
    80130        $other_author_id = $this->make_user_by_role( 'author' );
     
    117167
    118168    function test_empty_author() {
     169        if ( PHP_VERSION_ID >= 80100 ) {
     170            /*
     171             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     172             * via hooked in filter functions until a more structural solution to the
     173             * "missing input validation" conundrum has been architected and implemented.
     174             */
     175            $this->expectDeprecation();
     176            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     177        }
     178
    119179        $my_author_id = $this->make_user_by_role( 'author' );
    120180
     
    165225
    166226    function test_capable_set_post_type_as_page() {
     227        if ( PHP_VERSION_ID >= 80100 ) {
     228            /*
     229             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     230             * via hooked in filter functions until a more structural solution to the
     231             * "missing input validation" conundrum has been architected and implemented.
     232             */
     233            $this->expectDeprecation();
     234            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     235        }
     236
    167237        $this->make_user_by_role( 'editor' );
    168238
     
    185255     */
    186256    function test_draft_post_date() {
     257        if ( PHP_VERSION_ID >= 80100 ) {
     258            /*
     259             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     260             * via hooked in filter functions until a more structural solution to the
     261             * "missing input validation" conundrum has been architected and implemented.
     262             */
     263            $this->expectDeprecation();
     264            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     265        }
     266
    187267        $this->make_user_by_role( 'editor' );
    188268
Note: See TracChangeset for help on using the changeset viewer.