mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX Correctly identify deprecated API in withNoReplacement (#10706)
This commit is contained in:
parent
ab566b0a15
commit
652281507f
@ -177,6 +177,12 @@ class Deprecation
|
|||||||
$level = 1;
|
$level = 1;
|
||||||
}
|
}
|
||||||
$newLevel = $level;
|
$newLevel = $level;
|
||||||
|
// handle closures inside withNoReplacement()
|
||||||
|
if (self::$insideWithNoReplacement
|
||||||
|
&& substr($backtrace[$newLevel]['function'], -strlen('{closure}')) === '{closure}'
|
||||||
|
) {
|
||||||
|
$newLevel = $newLevel + 2;
|
||||||
|
}
|
||||||
// handle call_user_func
|
// handle call_user_func
|
||||||
if ($level === 4 && strpos($backtrace[2]['function'] ?? '', 'call_user_func') !== false) {
|
if ($level === 4 && strpos($backtrace[2]['function'] ?? '', 'call_user_func') !== false) {
|
||||||
$newLevel = 5;
|
$newLevel = 5;
|
||||||
@ -277,10 +283,10 @@ class Deprecation
|
|||||||
// Do not add to self::$userErrorMessageBuffer, as the backtrace is too expensive
|
// Do not add to self::$userErrorMessageBuffer, as the backtrace is too expensive
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getting a backtrace is slow, so we only do it if we need it
|
// Getting a backtrace is slow, so we only do it if we need it
|
||||||
$backtrace = null;
|
$backtrace = null;
|
||||||
|
|
||||||
// Get the calling scope
|
// Get the calling scope
|
||||||
if ($scope == Deprecation::SCOPE_METHOD) {
|
if ($scope == Deprecation::SCOPE_METHOD) {
|
||||||
$backtrace = debug_backtrace(0);
|
$backtrace = debug_backtrace(0);
|
||||||
@ -291,7 +297,7 @@ class Deprecation
|
|||||||
} else {
|
} else {
|
||||||
$caller = false;
|
$caller = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (substr($string, -1) != '.') {
|
if (substr($string, -1) != '.') {
|
||||||
$string .= ".";
|
$string .= ".";
|
||||||
}
|
}
|
||||||
|
@ -151,6 +151,22 @@ class DeprecationTest extends SapphireTest
|
|||||||
Deprecation::outputNotices();
|
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()
|
public function testClassWithNoReplacement()
|
||||||
{
|
{
|
||||||
$message = implode(' ', [
|
$message = implode(' ', [
|
||||||
|
Loading…
Reference in New Issue
Block a user