Introduce a _deprecated_class() function.

Similar to other function in the `_deprecated_*` series, `_deprecated_class()` comes with two new hooks: `deprecated_class_run` and `deprecated_class_trigger_error`.

Support has also been added for setting class deprecation expectations in tests.

Props jrf, wvega, ohryan.
See #41125.


git-svn-id: https://develop.svn.wordpress.org/trunk@56467 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Drew Jaynes
2023-08-25 03:24:00 +00:00
parent a5e6100443
commit 4ef1036e69
2 changed files with 77 additions and 0 deletions
@@ -568,12 +568,14 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase {
add_action( 'deprecated_function_run', array( $this, 'deprecated_function_run' ), 10, 3 );
add_action( 'deprecated_argument_run', array( $this, 'deprecated_function_run' ), 10, 3 );
add_action( 'deprecated_class_run', array( $this, 'deprecated_function_run' ), 10, 3 );
add_action( 'deprecated_file_included', array( $this, 'deprecated_function_run' ), 10, 4 );
add_action( 'deprecated_hook_run', array( $this, 'deprecated_function_run' ), 10, 4 );
add_action( 'doing_it_wrong_run', array( $this, 'doing_it_wrong_run' ), 10, 3 );
add_action( 'deprecated_function_trigger_error', '__return_false' );
add_action( 'deprecated_argument_trigger_error', '__return_false' );
add_action( 'deprecated_class_trigger_error', '__return_false' );
add_action( 'deprecated_file_trigger_error', '__return_false' );
add_action( 'deprecated_hook_trigger_error', '__return_false' );
add_action( 'doing_it_wrong_trigger_error', '__return_false' );
@@ -746,6 +748,23 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase {
}
break;
case 'deprecated_class_run':
if ( $replacement ) {
$message = sprintf(
'Class %1$s is deprecated since version %2$s! Use %3$s instead.',
$function_name,
$version,
$replacement
);
} else {
$message = sprintf(
'Class %1$s is deprecated since version %2$s with no alternative available.',
$function_name,
$version
);
}
break;
case 'deprecated_file_included':
if ( $replacement ) {
$message = sprintf(