diff --git a/core/lib/Drupal/Component/Utility/DeprecationHelper.php b/core/lib/Drupal/Component/Utility/DeprecationHelper.php new file mode 100644 index 0000000000..726c976993 --- /dev/null +++ b/core/lib/Drupal/Component/Utility/DeprecationHelper.php @@ -0,0 +1,43 @@ +=') ? $currentCallable() : $deprecatedCallable(); + } + +} diff --git a/core/tests/Drupal/Tests/Component/Utility/DeprecationHelperTest.php b/core/tests/Drupal/Tests/Component/Utility/DeprecationHelperTest.php new file mode 100644 index 0000000000..85ecae7927 --- /dev/null +++ b/core/tests/Drupal/Tests/Component/Utility/DeprecationHelperTest.php @@ -0,0 +1,96 @@ +currentImplementation(...); + $deprecated = $this->deprecatedImplementation(...); + foreach ($tests as $version => $expected) { + $result = DeprecationHelper::backwardsCompatibleCall( + currentVersion: $core, + currentCallable: fn() => $current('current'), + deprecatedVersion: $version, + deprecatedCallable: fn() => $deprecated('deprecated'), + ); + $this->assertEquals($expected, $result, "Change introduced in $version should return $expected for core version $core"); + } + } + + public static function deprecatedHelperTestCases(): array { + return [ + [ + 'core' => '10.2.x-dev', + 'introduced' => [ + '11.0.0' => 'deprecated', + '10.3.0' => 'deprecated', + '10.2.1' => 'deprecated', + '10.2.0' => 'current', + '10.1.0' => 'current', + '10.0.0' => 'current', + '9.5.0' => 'current', + ], + ], + [ + 'core' => '10.2.1', + 'introduced' => [ + '11.0.0' => 'deprecated', + '10.2.2' => 'deprecated', + '10.2.1' => 'current', + '10.2.0' => 'current', + '10.1.0' => 'current', + '10.0.0' => 'current', + '9.5.0' => 'current', + ], + ], + [ + 'core' => '11.0-dev', + 'introduced' => [ + '11.5.0' => 'deprecated', + '11.0.1' => 'deprecated', + '11.0.0' => 'current', + '10.1.0' => 'current', + '9.5.0' => 'current', + ], + ], + [ + 'core' => '11.0.0', + 'introduced' => [ + '11.5.0' => 'deprecated', + '11.2.1' => 'deprecated', + '11.0.1' => 'deprecated', + '11.0.0' => 'current', + '10.1.0' => 'current', + '9.5.0' => 'current', + ], + ], + ]; + } + +}