mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Compare commits
No commits in common. "82b0851a2a5e8bc11d45d7ae6ca303d19208c7aa" and "969d7b4bd21602e3b4f54f145a2d9f0db64648ff" have entirely different histories.
82b0851a2a
...
969d7b4bd2
@ -36,9 +36,8 @@
|
|||||||
"psr/container": "^1.1 || ^2.0",
|
"psr/container": "^1.1 || ^2.0",
|
||||||
"psr/http-message": "^1",
|
"psr/http-message": "^1",
|
||||||
"sebastian/diff": "^4.0",
|
"sebastian/diff": "^4.0",
|
||||||
"silverstripe/config": "^2.2",
|
"silverstripe/config": "^2",
|
||||||
"silverstripe/assets": "^2.3",
|
"silverstripe/assets": "^2.3",
|
||||||
"silverstripe/supported-modules": "^1.1",
|
|
||||||
"silverstripe/vendor-plugin": "^2",
|
"silverstripe/vendor-plugin": "^2",
|
||||||
"sminnee/callbacklist": "^0.1.1",
|
"sminnee/callbacklist": "^0.1.1",
|
||||||
"symfony/cache": "^6.1",
|
"symfony/cache": "^6.1",
|
||||||
|
@ -19,6 +19,7 @@ use SilverStripe\View\TemplateGlobalProvider;
|
|||||||
*/
|
*/
|
||||||
class Controller extends RequestHandler implements TemplateGlobalProvider
|
class Controller extends RequestHandler implements TemplateGlobalProvider
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An array of arguments extracted from the URL.
|
* An array of arguments extracted from the URL.
|
||||||
*
|
*
|
||||||
|
@ -3,14 +3,11 @@
|
|||||||
namespace SilverStripe\Dev;
|
namespace SilverStripe\Dev;
|
||||||
|
|
||||||
use BadMethodCallException;
|
use BadMethodCallException;
|
||||||
use RuntimeException;
|
|
||||||
use SilverStripe\Control\Director;
|
use SilverStripe\Control\Director;
|
||||||
use SilverStripe\Core\Environment;
|
use SilverStripe\Core\Environment;
|
||||||
use SilverStripe\Core\Injector\InjectionCreator;
|
use SilverStripe\Core\Injector\InjectionCreator;
|
||||||
use SilverStripe\Core\Injector\InjectorLoader;
|
use SilverStripe\Core\Injector\InjectorLoader;
|
||||||
use SilverStripe\Core\Manifest\Module;
|
use SilverStripe\Core\Manifest\Module;
|
||||||
use SilverStripe\Core\Path;
|
|
||||||
use SilverStripe\SupportedModules\MetaData;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles raising an notice when accessing a deprecated method, class, configuration, or behaviour.
|
* Handles raising an notice when accessing a deprecated method, class, configuration, or behaviour.
|
||||||
@ -80,18 +77,6 @@ class Deprecation
|
|||||||
*/
|
*/
|
||||||
private static bool $showNoReplacementNotices = false;
|
private static bool $showNoReplacementNotices = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
private static bool $showNoticesCalledFromSupportedCode = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Cache of supported module directories, read from silverstripe/supported-modules repositories.json
|
|
||||||
*
|
|
||||||
* @internal
|
|
||||||
*/
|
|
||||||
private static array $supportedModuleDirectories = [];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable throwing deprecation warnings. By default, this excludes warnings for
|
* Enable throwing deprecation warnings. By default, this excludes warnings for
|
||||||
* deprecated code which is called by core Silverstripe modules.
|
* deprecated code which is called by core Silverstripe modules.
|
||||||
@ -161,12 +146,6 @@ class Deprecation
|
|||||||
if (!$level) {
|
if (!$level) {
|
||||||
$level = 1;
|
$level = 1;
|
||||||
}
|
}
|
||||||
$called = Deprecation::get_called_from_trace($backtrace, $level);
|
|
||||||
return ($called['class'] ?? '') . ($called['type'] ?? '') . ($called['function'] ?? '');
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function get_called_from_trace(array $backtrace, int $level): array
|
|
||||||
{
|
|
||||||
$newLevel = $level;
|
$newLevel = $level;
|
||||||
// handle closures inside withSuppressedNotice()
|
// handle closures inside withSuppressedNotice()
|
||||||
if (Deprecation::$insideNoticeSuppression
|
if (Deprecation::$insideNoticeSuppression
|
||||||
@ -184,51 +163,8 @@ class Deprecation
|
|||||||
if ($level == 4 && ($backtrace[$newLevel]['class'] ?? '') === InjectionCreator::class) {
|
if ($level == 4 && ($backtrace[$newLevel]['class'] ?? '') === InjectionCreator::class) {
|
||||||
$newLevel = $newLevel + 4;
|
$newLevel = $newLevel + 4;
|
||||||
}
|
}
|
||||||
// handle noticeWithNoReplacment()
|
|
||||||
foreach ($backtrace as $trace) {
|
|
||||||
if (($trace['class'] ?? '') === Deprecation::class
|
|
||||||
&& ($trace['function'] ?? '') === 'noticeWithNoReplacment'
|
|
||||||
) {
|
|
||||||
$newLevel = $newLevel + 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$called = $backtrace[$newLevel] ?? [];
|
$called = $backtrace[$newLevel] ?? [];
|
||||||
return $called;
|
return ($called['class'] ?? '') . ($called['type'] ?? '') . ($called['function'] ?? '');
|
||||||
}
|
|
||||||
|
|
||||||
private static function isCalledFromSupportedCode(array $backtrace): bool
|
|
||||||
{
|
|
||||||
$called = Deprecation::get_called_from_trace($backtrace, 1);
|
|
||||||
$file = $called['file'] ?? '';
|
|
||||||
if (!$file) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return Deprecation::fileIsInSupportedModule($file);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check whether a file (path to file) is in a supported module
|
|
||||||
*/
|
|
||||||
public static function fileIsInSupportedModule(string $file): bool
|
|
||||||
{
|
|
||||||
// Cache the supported modules list
|
|
||||||
if (count(Deprecation::$supportedModuleDirectories) === 0) {
|
|
||||||
// Do not make a network request when fetching metadata which could slow down a website
|
|
||||||
// While there is a small risk of the list being out of date, there is minimal downside to this
|
|
||||||
$metaData = MetaData::getAllRepositoryMetaData(fromRemote: false);
|
|
||||||
$dirs = array_map(fn($module) => "/vendor/{$module['packagist']}/", $metaData['supportedModules']);
|
|
||||||
// This is a special case for silverstripe-framework when running in CI
|
|
||||||
// Needed because module is run in the root folder rather than in the vendor folder
|
|
||||||
$dirs[] = '/silverstripe-framework/';
|
|
||||||
Deprecation::$supportedModuleDirectories = $dirs;
|
|
||||||
}
|
|
||||||
foreach (Deprecation::$supportedModuleDirectories as $dir) {
|
|
||||||
if (str_contains($file, $dir)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function isEnabled(): bool
|
public static function isEnabled(): bool
|
||||||
@ -309,22 +245,6 @@ class Deprecation
|
|||||||
return Deprecation::$shouldShowForCli;
|
return Deprecation::$shouldShowForCli;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* If true, deprecation warnings will be shown for deprecated code which is called by core Silverstripe modules.
|
|
||||||
*/
|
|
||||||
public static function getShowNoticesCalledFromSupportedCode(): bool
|
|
||||||
{
|
|
||||||
return Deprecation::$showNoticesCalledFromSupportedCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set whether deprecation warnings will be shown for deprecated code which is called by core Silverstripe modules.
|
|
||||||
*/
|
|
||||||
public static function setShowNoticesCalledFromSupportedCode(bool $value): void
|
|
||||||
{
|
|
||||||
Deprecation::$showNoticesCalledFromSupportedCode = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function outputNotices(): void
|
public static function outputNotices(): void
|
||||||
{
|
{
|
||||||
if (!Deprecation::isEnabled()) {
|
if (!Deprecation::isEnabled()) {
|
||||||
@ -338,13 +258,9 @@ class Deprecation
|
|||||||
$arr = array_shift(Deprecation::$userErrorMessageBuffer);
|
$arr = array_shift(Deprecation::$userErrorMessageBuffer);
|
||||||
$message = $arr['message'];
|
$message = $arr['message'];
|
||||||
$calledWithNoticeSuppression = $arr['calledWithNoticeSuppression'];
|
$calledWithNoticeSuppression = $arr['calledWithNoticeSuppression'];
|
||||||
$isCalledFromSupportedCode = $arr['isCalledFromSupportedCode'];
|
|
||||||
if ($calledWithNoticeSuppression && !Deprecation::$showNoReplacementNotices) {
|
if ($calledWithNoticeSuppression && !Deprecation::$showNoReplacementNotices) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ($isCalledFromSupportedCode && !Deprecation::$showNoticesCalledFromSupportedCode) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Deprecation::$isTriggeringError = true;
|
Deprecation::$isTriggeringError = true;
|
||||||
user_error($message, E_USER_DEPRECATED);
|
user_error($message, E_USER_DEPRECATED);
|
||||||
Deprecation::$isTriggeringError = false;
|
Deprecation::$isTriggeringError = false;
|
||||||
@ -378,10 +294,6 @@ class Deprecation
|
|||||||
$data = [
|
$data = [
|
||||||
'key' => sha1($string),
|
'key' => sha1($string),
|
||||||
'message' => $string,
|
'message' => $string,
|
||||||
// Setting to `false` as here as any SCOPE_CONFIG notices from supported modules have
|
|
||||||
// already been filtered out if needed if they came from a supported module in
|
|
||||||
// SilverStripe\Config\Transformer\YamlTransformer::checkForDeprecatedConfig()
|
|
||||||
'isCalledFromSupportedCode' => false,
|
|
||||||
'calledWithNoticeSuppression' => Deprecation::$insideNoticeSuppression
|
'calledWithNoticeSuppression' => Deprecation::$insideNoticeSuppression
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
@ -410,13 +322,13 @@ class Deprecation
|
|||||||
|
|
||||||
$level = Deprecation::$insideNoticeSuppression ? 4 : 2;
|
$level = Deprecation::$insideNoticeSuppression ? 4 : 2;
|
||||||
$string .= " Called from " . Deprecation::get_called_method_from_trace($backtrace, $level) . '.';
|
$string .= " Called from " . Deprecation::get_called_method_from_trace($backtrace, $level) . '.';
|
||||||
|
|
||||||
if ($caller) {
|
if ($caller) {
|
||||||
$string = $caller . ' is deprecated.' . ($string ? ' ' . $string : '');
|
$string = $caller . ' is deprecated.' . ($string ? ' ' . $string : '');
|
||||||
}
|
}
|
||||||
$data = [
|
$data = [
|
||||||
'key' => sha1($string),
|
'key' => sha1($string),
|
||||||
'message' => $string,
|
'message' => $string,
|
||||||
'isCalledFromSupportedCode' => Deprecation::isCalledFromSupportedCode($backtrace),
|
|
||||||
'calledWithNoticeSuppression' => Deprecation::$insideNoticeSuppression
|
'calledWithNoticeSuppression' => Deprecation::$insideNoticeSuppression
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -448,23 +360,6 @@ class Deprecation
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Shorthand method to create a suppressed notice for something with no immediate replacement.
|
|
||||||
* If $message is empty, then a standardised message will be used
|
|
||||||
*/
|
|
||||||
public static function noticeWithNoReplacment(
|
|
||||||
string $atVersion,
|
|
||||||
string $message = '',
|
|
||||||
int $scope = Deprecation::SCOPE_METHOD
|
|
||||||
): void {
|
|
||||||
if ($message === '') {
|
|
||||||
$message = 'Will be removed without equivalent functionality to replace it.';
|
|
||||||
}
|
|
||||||
Deprecation::withSuppressedNotice(
|
|
||||||
fn() => Deprecation::notice($atVersion, $message, $scope)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function varAsBoolean($val): bool
|
private static function varAsBoolean($val): bool
|
||||||
{
|
{
|
||||||
if (is_string($val)) {
|
if (is_string($val)) {
|
||||||
|
@ -23,8 +23,6 @@ class DeprecationTest extends SapphireTest
|
|||||||
|
|
||||||
private bool $noticesWereEnabled = false;
|
private bool $noticesWereEnabled = false;
|
||||||
|
|
||||||
private bool $showSupportedNoticesWasEnabled = false;
|
|
||||||
|
|
||||||
protected function setup(): void
|
protected function setup(): void
|
||||||
{
|
{
|
||||||
// Use custom error handler for two reasons:
|
// Use custom error handler for two reasons:
|
||||||
@ -33,7 +31,6 @@ class DeprecationTest extends SapphireTest
|
|||||||
// https://github.com/laminas/laminas-di/pull/30#issuecomment-927585210
|
// https://github.com/laminas/laminas-di/pull/30#issuecomment-927585210
|
||||||
parent::setup();
|
parent::setup();
|
||||||
$this->noticesWereEnabled = Deprecation::isEnabled();
|
$this->noticesWereEnabled = Deprecation::isEnabled();
|
||||||
$this->showSupportedNoticesWasEnabled = Deprecation::getShowNoticesCalledFromSupportedCode();
|
|
||||||
$this->oldHandler = set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) {
|
$this->oldHandler = set_error_handler(function (int $errno, string $errstr, string $errfile, int $errline) {
|
||||||
if ($errno === E_USER_DEPRECATED) {
|
if ($errno === E_USER_DEPRECATED) {
|
||||||
if (str_contains($errstr, 'SilverStripe\\Dev\\Tests\\DeprecationTest')) {
|
if (str_contains($errstr, 'SilverStripe\\Dev\\Tests\\DeprecationTest')) {
|
||||||
@ -49,8 +46,6 @@ class DeprecationTest extends SapphireTest
|
|||||||
// Fallback to default PHP error handler
|
// Fallback to default PHP error handler
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
// This is required to clear out the notice from instantiating DeprecationTestObject in TableBuilder::buildTables().
|
|
||||||
Deprecation::outputNotices();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function tearDown(): void
|
protected function tearDown(): void
|
||||||
@ -60,7 +55,6 @@ class DeprecationTest extends SapphireTest
|
|||||||
} else {
|
} else {
|
||||||
Deprecation::disable();
|
Deprecation::disable();
|
||||||
}
|
}
|
||||||
Deprecation::setShowNoticesCalledFromSupportedCode($this->showSupportedNoticesWasEnabled);
|
|
||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
$this->oldHandler = null;
|
$this->oldHandler = null;
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
@ -72,18 +66,6 @@ class DeprecationTest extends SapphireTest
|
|||||||
return 'abc';
|
return 'abc';
|
||||||
}
|
}
|
||||||
|
|
||||||
private function myDeprecatedMethodNoReplacement(): string
|
|
||||||
{
|
|
||||||
Deprecation::noticeWithNoReplacment('1.2.3');
|
|
||||||
return 'abc';
|
|
||||||
}
|
|
||||||
|
|
||||||
private function enableDeprecationNotices(bool $showNoReplacementNotices = false): void
|
|
||||||
{
|
|
||||||
Deprecation::enable($showNoReplacementNotices);
|
|
||||||
Deprecation::setShowNoticesCalledFromSupportedCode(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testNotice()
|
public function testNotice()
|
||||||
{
|
{
|
||||||
$message = implode(' ', [
|
$message = implode(' ', [
|
||||||
@ -93,7 +75,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
]);
|
]);
|
||||||
$this->expectDeprecation();
|
$this->expectDeprecation();
|
||||||
$this->expectDeprecationMessage($message);
|
$this->expectDeprecationMessage($message);
|
||||||
$this->enableDeprecationNotices();
|
Deprecation::enable();
|
||||||
$ret = $this->myDeprecatedMethod();
|
$ret = $this->myDeprecatedMethod();
|
||||||
$this->assertSame('abc', $ret);
|
$this->assertSame('abc', $ret);
|
||||||
// call outputNotices() directly because the regular shutdown function that emits
|
// call outputNotices() directly because the regular shutdown function that emits
|
||||||
@ -101,29 +83,6 @@ class DeprecationTest extends SapphireTest
|
|||||||
Deprecation::outputNotices();
|
Deprecation::outputNotices();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNoticeNoReplacement()
|
|
||||||
{
|
|
||||||
$message = implode(' ', [
|
|
||||||
'SilverStripe\Dev\Tests\DeprecationTest->myDeprecatedMethodNoReplacement is deprecated.',
|
|
||||||
'Will be removed without equivalent functionality to replace it.',
|
|
||||||
'Called from SilverStripe\Dev\Tests\DeprecationTest->testNoticeNoReplacement.'
|
|
||||||
]);
|
|
||||||
$this->expectDeprecation();
|
|
||||||
$this->expectDeprecationMessage($message);
|
|
||||||
$this->enableDeprecationNotices(true);
|
|
||||||
$ret = $this->myDeprecatedMethodNoReplacement();
|
|
||||||
$this->assertSame('abc', $ret);
|
|
||||||
Deprecation::outputNotices();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testNoticeNoReplacementNoSupressed()
|
|
||||||
{
|
|
||||||
$this->enableDeprecationNotices();
|
|
||||||
$ret = $this->myDeprecatedMethodNoReplacement();
|
|
||||||
$this->assertSame('abc', $ret);
|
|
||||||
Deprecation::outputNotices();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testCallUserFunc()
|
public function testCallUserFunc()
|
||||||
{
|
{
|
||||||
$message = implode(' ', [
|
$message = implode(' ', [
|
||||||
@ -133,7 +92,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
]);
|
]);
|
||||||
$this->expectDeprecation();
|
$this->expectDeprecation();
|
||||||
$this->expectDeprecationMessage($message);
|
$this->expectDeprecationMessage($message);
|
||||||
$this->enableDeprecationNotices();
|
Deprecation::enable();
|
||||||
$ret = call_user_func([$this, 'myDeprecatedMethod']);
|
$ret = call_user_func([$this, 'myDeprecatedMethod']);
|
||||||
$this->assertSame('abc', $ret);
|
$this->assertSame('abc', $ret);
|
||||||
Deprecation::outputNotices();
|
Deprecation::outputNotices();
|
||||||
@ -148,7 +107,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
]);
|
]);
|
||||||
$this->expectDeprecation();
|
$this->expectDeprecation();
|
||||||
$this->expectDeprecationMessage($message);
|
$this->expectDeprecationMessage($message);
|
||||||
$this->enableDeprecationNotices();
|
Deprecation::enable();
|
||||||
$ret = call_user_func_array([$this, 'myDeprecatedMethod'], []);
|
$ret = call_user_func_array([$this, 'myDeprecatedMethod'], []);
|
||||||
$this->assertSame('abc', $ret);
|
$this->assertSame('abc', $ret);
|
||||||
Deprecation::outputNotices();
|
Deprecation::outputNotices();
|
||||||
@ -156,7 +115,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
|
|
||||||
public function testwithSuppressedNoticeDefault()
|
public function testwithSuppressedNoticeDefault()
|
||||||
{
|
{
|
||||||
$this->enableDeprecationNotices();
|
Deprecation::enable();
|
||||||
$ret = Deprecation::withSuppressedNotice(function () {
|
$ret = Deprecation::withSuppressedNotice(function () {
|
||||||
return $this->myDeprecatedMethod();
|
return $this->myDeprecatedMethod();
|
||||||
});
|
});
|
||||||
@ -173,7 +132,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
]);
|
]);
|
||||||
$this->expectDeprecation();
|
$this->expectDeprecation();
|
||||||
$this->expectDeprecationMessage($message);
|
$this->expectDeprecationMessage($message);
|
||||||
$this->enableDeprecationNotices(true);
|
Deprecation::enable(true);
|
||||||
$ret = Deprecation::withSuppressedNotice(function () {
|
$ret = Deprecation::withSuppressedNotice(function () {
|
||||||
return $this->myDeprecatedMethod();
|
return $this->myDeprecatedMethod();
|
||||||
});
|
});
|
||||||
@ -190,7 +149,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
]);
|
]);
|
||||||
$this->expectDeprecation();
|
$this->expectDeprecation();
|
||||||
$this->expectDeprecationMessage($message);
|
$this->expectDeprecationMessage($message);
|
||||||
$this->enableDeprecationNotices(true);
|
Deprecation::enable(true);
|
||||||
$ret = Deprecation::withSuppressedNotice(function () {
|
$ret = Deprecation::withSuppressedNotice(function () {
|
||||||
return call_user_func([$this, 'myDeprecatedMethod']);
|
return call_user_func([$this, 'myDeprecatedMethod']);
|
||||||
});
|
});
|
||||||
@ -207,7 +166,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
]);
|
]);
|
||||||
$this->expectDeprecation();
|
$this->expectDeprecation();
|
||||||
$this->expectDeprecationMessage($message);
|
$this->expectDeprecationMessage($message);
|
||||||
$this->enableDeprecationNotices(true);
|
Deprecation::enable(true);
|
||||||
Deprecation::withSuppressedNotice(function () {
|
Deprecation::withSuppressedNotice(function () {
|
||||||
Deprecation::notice('123', 'My message.');
|
Deprecation::notice('123', 'My message.');
|
||||||
});
|
});
|
||||||
@ -223,7 +182,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
]);
|
]);
|
||||||
$this->expectDeprecation();
|
$this->expectDeprecation();
|
||||||
$this->expectDeprecationMessage($message);
|
$this->expectDeprecationMessage($message);
|
||||||
$this->enableDeprecationNotices(true);
|
Deprecation::enable(true);
|
||||||
// using this syntax because my IDE was complaining about DeprecationTestObject not existing
|
// using this syntax because my IDE was complaining about DeprecationTestObject not existing
|
||||||
// when trying to use `new DeprecationTestObject();`
|
// when trying to use `new DeprecationTestObject();`
|
||||||
$class = DeprecationTestObject::class;
|
$class = DeprecationTestObject::class;
|
||||||
@ -240,7 +199,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
]);
|
]);
|
||||||
$this->expectDeprecation();
|
$this->expectDeprecation();
|
||||||
$this->expectDeprecationMessage($message);
|
$this->expectDeprecationMessage($message);
|
||||||
$this->enableDeprecationNotices(true);
|
Deprecation::enable(true);
|
||||||
Injector::inst()->get(DeprecationTestObject::class);
|
Injector::inst()->get(DeprecationTestObject::class);
|
||||||
Deprecation::outputNotices();
|
Deprecation::outputNotices();
|
||||||
}
|
}
|
||||||
@ -258,50 +217,6 @@ class DeprecationTest extends SapphireTest
|
|||||||
Deprecation::outputNotices();
|
Deprecation::outputNotices();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testshowNoticesCalledFromSupportedCode()
|
|
||||||
{
|
|
||||||
$this->expectNotToPerformAssertions();
|
|
||||||
$this->enableDeprecationNotices(true);
|
|
||||||
// showNoticesCalledFromSupportedCode is set to true by default for these unit tests
|
|
||||||
// as it is testing code within vendor/silverstripe
|
|
||||||
// This test is to ensure that the method works as expected when we disable this
|
|
||||||
// and we should expect no exceptions to be thrown
|
|
||||||
//
|
|
||||||
// Note specifically NOT testing the following because it's counted as being called
|
|
||||||
// from phpunit itself, which is not considered supported code
|
|
||||||
// Deprecation::withSuppressedNotice(function () {
|
|
||||||
// Deprecation::notice('123', 'My message.');
|
|
||||||
// });
|
|
||||||
Deprecation::setShowNoticesCalledFromSupportedCode(false);
|
|
||||||
// notice()
|
|
||||||
$this->myDeprecatedMethod();
|
|
||||||
// noticeNoReplacement()
|
|
||||||
$this->myDeprecatedMethodNoReplacement();
|
|
||||||
// callUserFunc()
|
|
||||||
call_user_func([$this, 'myDeprecatedMethod']);
|
|
||||||
// callUserFuncArray()
|
|
||||||
call_user_func_array([$this, 'myDeprecatedMethod'], []);
|
|
||||||
// withSuppressedNotice()
|
|
||||||
Deprecation::withSuppressedNotice(
|
|
||||||
fn() => $this->myDeprecatedMethod()
|
|
||||||
);
|
|
||||||
// withSuppressedNoticeTrue()
|
|
||||||
Deprecation::withSuppressedNotice(function () {
|
|
||||||
$this->myDeprecatedMethod();
|
|
||||||
});
|
|
||||||
// withSuppressedNoticeTrueCallUserFunc()
|
|
||||||
Deprecation::withSuppressedNotice(function () {
|
|
||||||
call_user_func([$this, 'myDeprecatedMethod']);
|
|
||||||
});
|
|
||||||
// classWithSuppressedNotice()
|
|
||||||
$class = DeprecationTestObject::class;
|
|
||||||
new $class();
|
|
||||||
// classWithInjectorwithSuppressedNotice()
|
|
||||||
Injector::inst()->get(DeprecationTestObject::class);
|
|
||||||
// Output notices - there should be none
|
|
||||||
Deprecation::outputNotices();
|
|
||||||
}
|
|
||||||
|
|
||||||
// The following tests would be better to put in the silverstripe/config module, however this is not
|
// The following tests would be better to put in the silverstripe/config module, however this is not
|
||||||
// possible to do in a clean way as the config for the DeprecationTestObject will not load if it
|
// possible to do in a clean way as the config for the DeprecationTestObject will not load if it
|
||||||
// is inside the silverstripe/config directory, as there is no _config.php file or _config folder.
|
// is inside the silverstripe/config directory, as there is no _config.php file or _config folder.
|
||||||
@ -316,7 +231,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
]);
|
]);
|
||||||
$this->expectDeprecation();
|
$this->expectDeprecation();
|
||||||
$this->expectDeprecationMessage($message);
|
$this->expectDeprecationMessage($message);
|
||||||
$this->enableDeprecationNotices();
|
Deprecation::enable();
|
||||||
Config::inst()->get(DeprecationTestObject::class, 'first_config');
|
Config::inst()->get(DeprecationTestObject::class, 'first_config');
|
||||||
Deprecation::outputNotices();
|
Deprecation::outputNotices();
|
||||||
}
|
}
|
||||||
@ -329,7 +244,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
]);
|
]);
|
||||||
$this->expectDeprecation();
|
$this->expectDeprecation();
|
||||||
$this->expectDeprecationMessage($message);
|
$this->expectDeprecationMessage($message);
|
||||||
$this->enableDeprecationNotices();
|
Deprecation::enable();
|
||||||
Config::inst()->get(DeprecationTestObject::class, 'second_config');
|
Config::inst()->get(DeprecationTestObject::class, 'second_config');
|
||||||
Deprecation::outputNotices();
|
Deprecation::outputNotices();
|
||||||
}
|
}
|
||||||
@ -339,7 +254,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
$message = 'Config SilverStripe\Dev\Tests\DeprecationTest\DeprecationTestObject.third_config is deprecated.';
|
$message = 'Config SilverStripe\Dev\Tests\DeprecationTest\DeprecationTestObject.third_config is deprecated.';
|
||||||
$this->expectDeprecation();
|
$this->expectDeprecation();
|
||||||
$this->expectDeprecationMessage($message);
|
$this->expectDeprecationMessage($message);
|
||||||
$this->enableDeprecationNotices();
|
Deprecation::enable();
|
||||||
Config::inst()->get(DeprecationTestObject::class, 'third_config');
|
Config::inst()->get(DeprecationTestObject::class, 'third_config');
|
||||||
Deprecation::outputNotices();
|
Deprecation::outputNotices();
|
||||||
}
|
}
|
||||||
@ -352,7 +267,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
]);
|
]);
|
||||||
$this->expectDeprecation();
|
$this->expectDeprecation();
|
||||||
$this->expectDeprecationMessage($message);
|
$this->expectDeprecationMessage($message);
|
||||||
$this->enableDeprecationNotices();
|
Deprecation::enable();
|
||||||
Config::modify()->set(DeprecationTestObject::class, 'first_config', 'abc');
|
Config::modify()->set(DeprecationTestObject::class, 'first_config', 'abc');
|
||||||
Deprecation::outputNotices();
|
Deprecation::outputNotices();
|
||||||
}
|
}
|
||||||
@ -365,7 +280,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
]);
|
]);
|
||||||
$this->expectDeprecation();
|
$this->expectDeprecation();
|
||||||
$this->expectDeprecationMessage($message);
|
$this->expectDeprecationMessage($message);
|
||||||
$this->enableDeprecationNotices();
|
Deprecation::enable();
|
||||||
Config::modify()->merge(DeprecationTestObject::class, 'array_config', ['abc']);
|
Config::modify()->merge(DeprecationTestObject::class, 'array_config', ['abc']);
|
||||||
Deprecation::outputNotices();
|
Deprecation::outputNotices();
|
||||||
}
|
}
|
||||||
@ -451,7 +366,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
switch ($varName) {
|
switch ($varName) {
|
||||||
case 'SS_DEPRECATION_ENABLED':
|
case 'SS_DEPRECATION_ENABLED':
|
||||||
if ($configVal) {
|
if ($configVal) {
|
||||||
$this->enableDeprecationNotices();
|
Deprecation::enable();
|
||||||
} else {
|
} else {
|
||||||
Deprecation::disable();
|
Deprecation::disable();
|
||||||
}
|
}
|
||||||
@ -627,7 +542,7 @@ class DeprecationTest extends SapphireTest
|
|||||||
private function setEnabledViaStatic(bool $enabled): void
|
private function setEnabledViaStatic(bool $enabled): void
|
||||||
{
|
{
|
||||||
if ($enabled) {
|
if ($enabled) {
|
||||||
$this->enableDeprecationNotices();
|
Deprecation::enable();
|
||||||
} else {
|
} else {
|
||||||
Deprecation::disable();
|
Deprecation::disable();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user