From 5f0fb23a3b6762e18a834c9d0a92a12d1dbdcc92 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 20 Sep 2019 22:39:23 +0000 Subject: [PATCH] Tests: Remove a workaround for `get_called_class()`. The `get_called_class()` function was introduced in PHP 5.3, so no longer needs a workaround. Mark `WP_UnitTestCase_Base::get_called_class()` as deprecated. Leave it in place for now as plugins or themes using the WP unit test framework might still call this method. Props jrf. See #48074. git-svn-id: https://develop.svn.wordpress.org/trunk@46221 602fd350-edb4-49c9-b593-d223f7449a82 --- 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/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -49,21 +49,12 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Framework_TestCase { /** * Retrieves the name of the class the static method is called in. * + * @deprecated 5.3.0 Use the PHP native get_called_class() function instead. + * * @return string The class name. */ public static function get_called_class() { - if ( function_exists( 'get_called_class' ) ) { - return get_called_class(); - } - - // PHP 5.2 only - $backtrace = debug_backtrace(); - // [0] WP_UnitTestCase::get_called_class() - // [1] WP_UnitTestCase::setUpBeforeClass() - if ( 'call_user_func' === $backtrace[2]['function'] ) { - return $backtrace[2]['args'][0][0]; - } - return $backtrace[2]['class']; + return get_called_class(); } /** @@ -79,7 +70,7 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Framework_TestCase { parent::setUpBeforeClass(); - $c = self::get_called_class(); + $c = get_called_class(); if ( ! method_exists( $c, 'wpSetUpBeforeClass' ) ) { self::commit_transaction(); return; @@ -99,7 +90,7 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Framework_TestCase { _delete_all_data(); self::flush_cache(); - $c = self::get_called_class(); + $c = get_called_class(); if ( ! method_exists( $c, 'wpTearDownAfterClass' ) ) { self::commit_transaction(); return;