Make WordPress Core

Ticket #53635: 53635-05-null-to-non-nullable-in-testcode.patch

File 53635-05-null-to-non-nullable-in-testcode.patch, 1.8 KB (added by jrf, 22 months ago)

PHP 8.1: Tests_Functions_DoEnclose: fix bug in test

  • tests/phpunit/tests/functions/doEnclose.php

    From 228f46a34566148aa17db333972e930a36e39912 Mon Sep 17 00:00:00 2001
    From: jrfnl <jrfnl@users.noreply.github.com>
    Date: Wed, 11 Aug 2021 03:15:49 +0200
    Subject: [PATCH] PHP 8.1: Tests_Functions_DoEnclose: fix bug in test
    
    As per the PHP manual:
    > If the component parameter is omitted, an associative array is returned.
    > If the component parameter is specified, parse_url() returns a string (or an int, in the case of PHP_URL_PORT) instead of an array. If the requested component doesn't exist within the given URL, null will be returned.
    
    Ref: https://www.php.net/manual/en/function.parse-url.php#refsect1-function.parse-url-returnvalues
    
    In this case, `parse_url()` is called with the `PHP_URL_PATH` as `$component`, but the returned value is subsequently checked against `false`.
    In other words, this condition would previously always result `true` and would lead to `null`, potentially, being passed to the PHP native `pathinfo()` function which expects a string.
    
    On PHP 8.1, this will result in a test failure with a `pathinfo(): Passing null to parameter #1 ($path) of type string is deprecated` error.
    
    Ref: https://www.php.net/manual/en/function.pathinfo.php
    ---
     tests/phpunit/tests/functions/doEnclose.php | 2 +-
     1 file changed, 1 insertion(+), 1 deletion(-)
    
    diff --git a/tests/phpunit/tests/functions/doEnclose.php b/tests/phpunit/tests/functions/doEnclose.php
    index a271e24f73..30a8e73dac 100644
    a b class Tests_Functions_DoEnclose extends WP_UnitTestCase { 
    280280
    281281                $path = parse_url( $url, PHP_URL_PATH );
    282282
    283                 if ( false !== $path ) {
     283                if ( null !== $path ) {
    284284                        $extension = pathinfo( $path, PATHINFO_EXTENSION );
    285285                        if ( isset( $fake_headers[ $extension ] ) ) {
    286286                                return $fake_headers[ $extension ];