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/admin/includesPost.php

    r51639 r51968  
    877877     */
    878878    public function test_post_exists_should_support_post_type() {
     879        if ( PHP_VERSION_ID >= 80100 ) {
     880            /*
     881             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     882             * via hooked in filter functions until a more structural solution to the
     883             * "missing input validation" conundrum has been architected and implemented.
     884             */
     885            $this->expectDeprecation();
     886            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     887        }
     888
    879889        $title     = 'Foo Bar';
    880890        $post_type = 'page';
     
    894904     */
    895905    public function test_post_exists_should_not_match_a_page_for_post() {
     906        if ( PHP_VERSION_ID >= 80100 ) {
     907            /*
     908             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     909             * via hooked in filter functions until a more structural solution to the
     910             * "missing input validation" conundrum has been architected and implemented.
     911             */
     912            $this->expectDeprecation();
     913            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     914        }
     915
    896916        $title     = 'Foo Bar';
    897917        $post_type = 'page';
     
    911931     */
    912932    public function test_post_exists_should_support_post_status() {
     933        if ( PHP_VERSION_ID >= 80100 ) {
     934            /*
     935             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     936             * via hooked in filter functions until a more structural solution to the
     937             * "missing input validation" conundrum has been architected and implemented.
     938             */
     939            $this->expectDeprecation();
     940            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     941        }
     942
    913943        $title       = 'Foo Bar';
    914944        $post_type   = 'post';
     
    931961     */
    932962    public function test_post_exists_should_support_post_type_status_combined() {
     963        if ( PHP_VERSION_ID >= 80100 ) {
     964            /*
     965             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     966             * via hooked in filter functions until a more structural solution to the
     967             * "missing input validation" conundrum has been architected and implemented.
     968             */
     969            $this->expectDeprecation();
     970            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     971        }
     972
    933973        $title       = 'Foo Bar';
    934974        $post_type   = 'post';
     
    950990     */
    951991    public function test_post_exists_should_only_match_correct_post_status() {
     992        if ( PHP_VERSION_ID >= 80100 ) {
     993            /*
     994             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     995             * via hooked in filter functions until a more structural solution to the
     996             * "missing input validation" conundrum has been architected and implemented.
     997             */
     998            $this->expectDeprecation();
     999            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     1000        }
     1001
    9521002        $title       = 'Foo Bar';
    9531003        $post_type   = 'post';
     
    9691019     */
    9701020    public function test_post_exists_should_not_match_invalid_post_type_and_status_combined() {
     1021        if ( PHP_VERSION_ID >= 80100 ) {
     1022            /*
     1023             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     1024             * via hooked in filter functions until a more structural solution to the
     1025             * "missing input validation" conundrum has been architected and implemented.
     1026             */
     1027            $this->expectDeprecation();
     1028            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     1029        }
     1030
    9711031        $title       = 'Foo Bar';
    9721032        $post_type   = 'post';
Note: See TracChangeset for help on using the changeset viewer.