FIX Correctly identify deprecated API in withNoReplacement (#10706)

This commit is contained in:
Guy Sartorelli 2023-02-27 15:25:27 +13:00 committed by GitHub
parent ab566b0a15
commit 652281507f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 3 deletions

View File

@ -177,6 +177,12 @@ class Deprecation
$level = 1;
}
$newLevel = $level;
// handle closures inside withNoReplacement()
if (self::$insideWithNoReplacement
&& substr($backtrace[$newLevel]['function'], -strlen('{closure}')) === '{closure}'
) {
$newLevel = $newLevel + 2;
}
// handle call_user_func
if ($level === 4 && strpos($backtrace[2]['function'] ?? '', 'call_user_func') !== false) {
$newLevel = 5;

View File

@ -151,6 +151,22 @@ class DeprecationTest extends SapphireTest
Deprecation::outputNotices();
}
public function testNoticeWithNoReplacementTrue()
{
$message = implode(' ', [
'SilverStripe\Dev\Tests\DeprecationTest->testNoticeWithNoReplacementTrue is deprecated.',
'My message.',
'Called from PHPUnit\Framework\TestCase->runTest.'
]);
$this->expectDeprecation();
$this->expectDeprecationMessage($message);
Deprecation::enable(true);
Deprecation::withNoReplacement(function () {
Deprecation::notice('123', 'My message.');
});
Deprecation::outputNotices();
}
public function testClassWithNoReplacement()
{
$message = implode(' ', [