Issue #3427178 by mondrake, longwave: Replace calls to ::expectWarning*() from Drupal\Tests\Core\Security\DoTrustedCallbackTraitTest

merge-requests/7441/head
catch 2024-04-10 22:07:05 +01:00
parent cfabdf59d3
commit a50c07aa93
5 changed files with 12 additions and 14 deletions

View File

@ -2573,18 +2573,6 @@ $ignoreErrors[] = [
'count' => 1, 'count' => 1,
'path' => __DIR__ . '/tests/Drupal/Tests/Core/Plugin/TestPluginManager.php', 'path' => __DIR__ . '/tests/Drupal/Tests/Core/Plugin/TestPluginManager.php',
]; ];
$ignoreErrors[] = [
'message' => '#^Call to deprecated method expectWarning\\(\\) of class PHPUnit\\\\Framework\\\\TestCase\\:
https\\://github\\.com/sebastianbergmann/phpunit/issues/5062$#',
'count' => 1,
'path' => __DIR__ . '/tests/Drupal/Tests/Core/Security/DoTrustedCallbackTraitTest.php',
];
$ignoreErrors[] = [
'message' => '#^Call to deprecated method expectWarningMessage\\(\\) of class PHPUnit\\\\Framework\\\\TestCase\\:
https\\://github\\.com/sebastianbergmann/phpunit/issues/5062$#',
'count' => 1,
'path' => __DIR__ . '/tests/Drupal/Tests/Core/Security/DoTrustedCallbackTraitTest.php',
];
$ignoreErrors[] = [ $ignoreErrors[] = [
'message' => '#^Variable \\$value in isset\\(\\) always exists and is not nullable\\.$#', 'message' => '#^Variable \\$value in isset\\(\\) always exists and is not nullable\\.$#',
'count' => 1, 'count' => 1,

View File

@ -37,7 +37,7 @@ trait DoTrustedCallbackTrait {
* @param string $error_type * @param string $error_type
* (optional) The type of error to trigger. One of: * (optional) The type of error to trigger. One of:
* - TrustedCallbackInterface::THROW_EXCEPTION * - TrustedCallbackInterface::THROW_EXCEPTION
* - TrustedCallbackInterface::TRIGGER_WARNING * - (deprecated) TrustedCallbackInterface::TRIGGER_WARNING
* - TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION * - TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION
* Defaults to TrustedCallbackInterface::THROW_EXCEPTION. * Defaults to TrustedCallbackInterface::THROW_EXCEPTION.
* @param string $extra_trusted_interface * @param string $extra_trusted_interface
@ -99,7 +99,9 @@ trait DoTrustedCallbackTrait {
if ($error_type === TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION) { if ($error_type === TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION) {
@trigger_error($message, E_USER_DEPRECATED); @trigger_error($message, E_USER_DEPRECATED);
} }
// @phpstan-ignore-next-line
elseif ($error_type === TrustedCallbackInterface::TRIGGER_WARNING) { elseif ($error_type === TrustedCallbackInterface::TRIGGER_WARNING) {
@trigger_error('Passing E_USER_WARNING for $error_type in ' . __METHOD__ . '() is deprecated in drupal:10.3.0 and will be removed from drupal:11.0.0. Use TrustedCallbackInterface::THROW_EXCEPTION or TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION instead. See https://www.drupal.org/node/3427367', E_USER_DEPRECATED);
trigger_error($message, E_USER_WARNING); trigger_error($message, E_USER_WARNING);
} }
else { else {

View File

@ -23,7 +23,7 @@ class StaticTrustedCallbackHelper {
* @param string $error_type * @param string $error_type
* (optional) The type of error to trigger. One of: * (optional) The type of error to trigger. One of:
* - TrustedCallbackInterface::THROW_EXCEPTION * - TrustedCallbackInterface::THROW_EXCEPTION
* - TrustedCallbackInterface::TRIGGER_WARNING * - (deprecated) TrustedCallbackInterface::TRIGGER_WARNING
* - TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION * - TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION
* Defaults to TrustedCallbackInterface::THROW_EXCEPTION. * Defaults to TrustedCallbackInterface::THROW_EXCEPTION.
* @param string $extra_trusted_interface * @param string $extra_trusted_interface

View File

@ -16,6 +16,12 @@ interface TrustedCallbackInterface {
/** /**
* Untrusted callbacks trigger E_USER_WARNING errors. * Untrusted callbacks trigger E_USER_WARNING errors.
*
* @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use
* TrustedCallbackInterface::THROW_EXCEPTION or
* TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION instead.
*
* @see https://www.drupal.org/node/3427367
*/ */
const TRIGGER_WARNING = 'warning'; const TRIGGER_WARNING = 'warning';

View File

@ -89,8 +89,10 @@ class DoTrustedCallbackTraitTest extends UnitTestCase {
/** /**
* @dataProvider errorTypeProvider * @dataProvider errorTypeProvider
* @group legacy
*/ */
public function testWarning($callback) { public function testWarning($callback) {
$this->expectDeprecation('Passing E_USER_WARNING for $error_type in Drupal\Core\Security\DoTrustedCallbackTrait::doTrustedCallback() is deprecated in drupal:10.3.0 and will be removed from drupal:11.0.0. Use TrustedCallbackInterface::THROW_EXCEPTION or TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION instead. See https://www.drupal.org/node/3427367');
$this->expectWarning(); $this->expectWarning();
$this->expectWarningMessage('Drupal\Tests\Core\Security\UntrustedObject::callback is not trusted'); $this->expectWarningMessage('Drupal\Tests\Core\Security\UntrustedObject::callback is not trusted');
$this->doTrustedCallback($callback, [], '%s is not trusted', TrustedCallbackInterface::TRIGGER_WARNING); $this->doTrustedCallback($callback, [], '%s is not trusted', TrustedCallbackInterface::TRIGGER_WARNING);