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

    r51415 r51968  
    2121
    2222    function test_no_content() {
     23        if ( PHP_VERSION_ID >= 80100 ) {
     24            /*
     25             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     26             * via hooked in filter functions until a more structural solution to the
     27             * "missing input validation" conundrum has been architected and implemented.
     28             */
     29            $this->expectDeprecation();
     30            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     31        }
     32
    2333        $this->make_user_by_role( 'author' );
    2434
     
    3040
    3141    function test_basic_content() {
     42        if ( PHP_VERSION_ID >= 80100 ) {
     43            /*
     44             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     45             * via hooked in filter functions until a more structural solution to the
     46             * "missing input validation" conundrum has been architected and implemented.
     47             */
     48            $this->expectDeprecation();
     49            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     50        }
     51
    3252        $this->make_user_by_role( 'author' );
    3353
     
    3959
    4060    function test_ignore_id() {
     61        if ( PHP_VERSION_ID >= 80100 ) {
     62            /*
     63             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     64             * via hooked in filter functions until a more structural solution to the
     65             * "missing input validation" conundrum has been architected and implemented.
     66             */
     67            $this->expectDeprecation();
     68            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     69        }
     70
    4171        $this->make_user_by_role( 'author' );
    4272
     
    5181
    5282    function test_capable_publish() {
     83        if ( PHP_VERSION_ID >= 80100 ) {
     84            /*
     85             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     86             * via hooked in filter functions until a more structural solution to the
     87             * "missing input validation" conundrum has been architected and implemented.
     88             */
     89            $this->expectDeprecation();
     90            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     91        }
     92
    5393        $this->make_user_by_role( 'author' );
    5494
     
    74114
    75115    function test_capable_private() {
     116        if ( PHP_VERSION_ID >= 80100 ) {
     117            /*
     118             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     119             * via hooked in filter functions until a more structural solution to the
     120             * "missing input validation" conundrum has been architected and implemented.
     121             */
     122            $this->expectDeprecation();
     123            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     124        }
     125
    76126        $this->make_user_by_role( 'editor' );
    77127
     
    97147
    98148    function test_capable_other_author() {
     149        if ( PHP_VERSION_ID >= 80100 ) {
     150            /*
     151             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     152             * via hooked in filter functions until a more structural solution to the
     153             * "missing input validation" conundrum has been architected and implemented.
     154             */
     155            $this->expectDeprecation();
     156            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     157        }
     158
    99159        $other_author_id = $this->make_user_by_role( 'author' );
    100160        $this->make_user_by_role( 'editor' );
     
    134194
    135195    function test_empty_author() {
     196        if ( PHP_VERSION_ID >= 80100 ) {
     197            /*
     198             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     199             * via hooked in filter functions until a more structural solution to the
     200             * "missing input validation" conundrum has been architected and implemented.
     201             */
     202            $this->expectDeprecation();
     203            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     204        }
     205
    136206        $my_author_id = $this->make_user_by_role( 'author' );
    137207
     
    170240
    171241    function test_invalid_post_status() {
     242        if ( PHP_VERSION_ID >= 80100 ) {
     243            /*
     244             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     245             * via hooked in filter functions until a more structural solution to the
     246             * "missing input validation" conundrum has been architected and implemented.
     247             */
     248            $this->expectDeprecation();
     249            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     250        }
     251
    172252        $this->make_user_by_role( 'author' );
    173253
     
    194274
    195275    function test_capable_sticky() {
     276        if ( PHP_VERSION_ID >= 80100 ) {
     277            /*
     278             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     279             * via hooked in filter functions until a more structural solution to the
     280             * "missing input validation" conundrum has been architected and implemented.
     281             */
     282            $this->expectDeprecation();
     283            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     284        }
     285
    196286        $this->make_user_by_role( 'editor' );
    197287
     
    219309
    220310    function test_post_format() {
     311        if ( PHP_VERSION_ID >= 80100 ) {
     312            /*
     313             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     314             * via hooked in filter functions until a more structural solution to the
     315             * "missing input validation" conundrum has been architected and implemented.
     316             */
     317            $this->expectDeprecation();
     318            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     319        }
     320
    221321        $this->make_user_by_role( 'editor' );
    222322
     
    231331
    232332    function test_invalid_post_format() {
     333        if ( PHP_VERSION_ID >= 80100 ) {
     334            /*
     335             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     336             * via hooked in filter functions until a more structural solution to the
     337             * "missing input validation" conundrum has been architected and implemented.
     338             */
     339            $this->expectDeprecation();
     340            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     341        }
     342
    233343        $this->make_user_by_role( 'editor' );
    234344
     
    281391
    282392    function test_terms() {
     393        if ( PHP_VERSION_ID >= 80100 ) {
     394            /*
     395             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     396             * via hooked in filter functions until a more structural solution to the
     397             * "missing input validation" conundrum has been architected and implemented.
     398             */
     399            $this->expectDeprecation();
     400            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     401        }
     402
    283403        $this->make_user_by_role( 'editor' );
    284404
     
    306426
    307427    function test_terms_names() {
     428        if ( PHP_VERSION_ID >= 80100 ) {
     429            /*
     430             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     431             * via hooked in filter functions until a more structural solution to the
     432             * "missing input validation" conundrum has been architected and implemented.
     433             */
     434            $this->expectDeprecation();
     435            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     436        }
     437
    308438        $this->make_user_by_role( 'editor' );
    309439
     
    349479     */
    350480    function test_invalid_post_date_does_not_fatal() {
     481        if ( PHP_VERSION_ID >= 80100 ) {
     482            /*
     483             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     484             * via hooked in filter functions until a more structural solution to the
     485             * "missing input validation" conundrum has been architected and implemented.
     486             */
     487            $this->expectDeprecation();
     488            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     489        }
     490
    351491        $this->make_user_by_role( 'author' );
    352492        $date_string  = 'invalid_date';
     
    366506     */
    367507    function test_invalid_post_date_gmt_does_not_fatal() {
     508        if ( PHP_VERSION_ID >= 80100 ) {
     509            /*
     510             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     511             * via hooked in filter functions until a more structural solution to the
     512             * "missing input validation" conundrum has been architected and implemented.
     513             */
     514            $this->expectDeprecation();
     515            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     516        }
     517
    368518        $this->make_user_by_role( 'author' );
    369519        $date_string  = 'invalid_date';
     
    383533     */
    384534    function test_valid_string_post_date() {
     535        if ( PHP_VERSION_ID >= 80100 ) {
     536            /*
     537             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     538             * via hooked in filter functions until a more structural solution to the
     539             * "missing input validation" conundrum has been architected and implemented.
     540             */
     541            $this->expectDeprecation();
     542            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     543        }
     544
    385545        $this->make_user_by_role( 'author' );
    386546        $date_string  = '1984-01-11 05:00:00';
     
    400560     */
    401561    function test_valid_string_post_date_gmt() {
     562        if ( PHP_VERSION_ID >= 80100 ) {
     563            /*
     564             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     565             * via hooked in filter functions until a more structural solution to the
     566             * "missing input validation" conundrum has been architected and implemented.
     567             */
     568            $this->expectDeprecation();
     569            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     570        }
     571
    402572        $this->make_user_by_role( 'author' );
    403573        $date_string  = '1984-01-11 05:00:00';
     
    417587     */
    418588    function test_valid_IXR_post_date() {
     589        if ( PHP_VERSION_ID >= 80100 ) {
     590            /*
     591             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     592             * via hooked in filter functions until a more structural solution to the
     593             * "missing input validation" conundrum has been architected and implemented.
     594             */
     595            $this->expectDeprecation();
     596            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     597        }
     598
    419599        $this->make_user_by_role( 'author' );
    420600        $date_string  = '1984-01-11 05:00:00';
     
    434614     */
    435615    function test_valid_IXR_post_date_gmt() {
     616        if ( PHP_VERSION_ID >= 80100 ) {
     617            /*
     618             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     619             * via hooked in filter functions until a more structural solution to the
     620             * "missing input validation" conundrum has been architected and implemented.
     621             */
     622            $this->expectDeprecation();
     623            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     624        }
     625
    436626        $this->make_user_by_role( 'author' );
    437627        $date_string  = '1984-01-11 05:00:00';
Note: See TracChangeset for help on using the changeset viewer.