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/formatting/wpRelUgc.php

    r51623 r51968  
    1010     */
    1111    public function test_add_ugc() {
     12        if ( PHP_VERSION_ID >= 80100 ) {
     13            /*
     14             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     15             * via hooked in filter functions until a more structural solution to the
     16             * "missing input validation" conundrum has been architected and implemented.
     17             */
     18            $this->expectDeprecation();
     19            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     20        }
     21
    1222        $content  = '<p>This is some cool <a href="/">Code</a></p>';
    1323        $expected = '<p>This is some cool <a href=\"/\" rel=\"nofollow ugc\">Code</a></p>';
     
    1929     */
    2030    public function test_convert_ugc() {
     31        if ( PHP_VERSION_ID >= 80100 ) {
     32            /*
     33             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     34             * via hooked in filter functions until a more structural solution to the
     35             * "missing input validation" conundrum has been architected and implemented.
     36             */
     37            $this->expectDeprecation();
     38            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     39        }
     40
    2141        $content  = '<p>This is some cool <a href="/" rel="weird">Code</a></p>';
    2242        $expected = '<p>This is some cool <a href=\"/\" rel=\"weird nofollow ugc\">Code</a></p>';
     
    2848     * @dataProvider data_wp_rel_ugc
    2949     */
    30     public function test_wp_rel_ugc( $input, $output ) {
    31         return $this->assertSame( wp_slash( $output ), wp_rel_ugc( $input ) );
     50    public function test_wp_rel_ugc( $input, $output, $expect_deprecation = false ) {
     51        if ( true === $expect_deprecation && PHP_VERSION_ID >= 80100 ) {
     52            /*
     53             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     54             * via hooked in filter functions until a more structural solution to the
     55             * "missing input validation" conundrum has been architected and implemented.
     56             */
     57            $this->expectDeprecation();
     58            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     59        }
     60
     61        $this->assertSame( wp_slash( $output ), wp_rel_ugc( $input ) );
    3262    }
    3363
     
    4070                '<a href="">Double Quotes</a>',
    4171                '<a href="" rel="nofollow ugc">Double Quotes</a>',
     72                true,
    4273            ),
    4374            array(
     
    77108
    78109    public function test_append_ugc_with_valueless_attribute() {
     110        if ( PHP_VERSION_ID >= 80100 ) {
     111            /*
     112             * For the time being, ignoring PHP 8.1 "null to non-nullable" deprecations coming in
     113             * via hooked in filter functions until a more structural solution to the
     114             * "missing input validation" conundrum has been architected and implemented.
     115             */
     116            $this->expectDeprecation();
     117            $this->expectDeprecationMessageMatches( '`Passing null to parameter \#[0-9]+ \(\$[^\)]+\) of type [^ ]+ is deprecated`' );
     118        }
     119
    79120        $content  = '<p>This is some cool <a href="demo.com" download rel="hola">Code</a></p>';
    80121        $expected = '<p>This is some cool <a href=\"demo.com\" download rel=\"hola nofollow ugc\">Code</a></p>';
Note: See TracChangeset for help on using the changeset viewer.