Make WordPress Core

Ticket #48074: 48074-tests-Remove-work-arounds-for-get_called_class.patch

File 48074-tests-Remove-work-arounds-for-get_called_class.patch, 1.9 KB (added by jrf, 5 years ago)

The get_called_class() function was introduced in PHP 5.3, so no longer needs a work-around. See: https://www.php.net/manual/en/function.get-called-class.php All instances were this method was called within the WP core codebase have been adjusted. Leaving the method in place for now as plugins/themes which use the WP unit test framework could still call this method.

  • tests/phpunit/includes/abstract-testcase.php

    From 5e528bd801a432506f916f0fd4e469734ded21fe Mon Sep 17 00:00:00 2001
    From: jrfnl <jrfnl@users.noreply.github.com>
    Date: Sat, 27 Jul 2019 04:33:43 +0200
    Subject: [PATCH] [tests] Remove work-arounds for get_called_class()
    
    ---
     tests/phpunit/includes/abstract-testcase.php | 19 +++++--------------
     1 file changed, 5 insertions(+), 14 deletions(-)
    
    diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php
    index f1c08657cb..b31b7a2c90 100644
    a b abstract class WP_UnitTestCase_Base extends PHPUnit_Framework_TestCase { 
    4949        /**
    5050         * Retrieves the name of the class the static method is called in.
    5151         *
     52         * @deprecated 5.3.0 Use the PHP native get_called_class() function instead.
     53         *
    5254         * @return string The class name.
    5355         */
    5456        public static function get_called_class() {
    55                 if ( function_exists( 'get_called_class' ) ) {
    56                         return get_called_class();
    57                 }
    58 
    59                 // PHP 5.2 only
    60                 $backtrace = debug_backtrace();
    61                 // [0] WP_UnitTestCase::get_called_class()
    62                 // [1] WP_UnitTestCase::setUpBeforeClass()
    63                 if ( 'call_user_func' === $backtrace[2]['function'] ) {
    64                         return $backtrace[2]['args'][0][0];
    65                 }
    66                 return $backtrace[2]['class'];
     57                return get_called_class();
    6758        }
    6859
    6960        /**
    abstract class WP_UnitTestCase_Base extends PHPUnit_Framework_TestCase { 
    7970
    8071                parent::setUpBeforeClass();
    8172
    82                 $c = self::get_called_class();
     73                $c = get_called_class();
    8374                if ( ! method_exists( $c, 'wpSetUpBeforeClass' ) ) {
    8475                        self::commit_transaction();
    8576                        return;
    abstract class WP_UnitTestCase_Base extends PHPUnit_Framework_TestCase { 
    9990                _delete_all_data();
    10091                self::flush_cache();
    10192
    102                 $c = self::get_called_class();
     93                $c = get_called_class();
    10394                if ( ! method_exists( $c, 'wpTearDownAfterClass' ) ) {
    10495                        self::commit_transaction();
    10596                        return;