diff --git a/core/.phpstan-baseline.php b/core/.phpstan-baseline.php index ba6babd797f4de3652a6ca9d4a04147df8998dcb..f587c034f38ee4e67af1ee7443792524ee5b9011 100644 --- a/core/.phpstan-baseline.php +++ b/core/.phpstan-baseline.php @@ -2573,18 +2573,6 @@ 'count' => 1, '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[] = [ 'message' => '#^Variable \\$value in isset\\(\\) always exists and is not nullable\\.$#', 'count' => 1, diff --git a/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php b/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php index 5c1079b9e0c78a9dba0e21d577753fbf06fa2bdf..da6783d2289cfffa900e4a16bd7351e7fbf5c4a6 100644 --- a/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php +++ b/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php @@ -37,7 +37,7 @@ trait DoTrustedCallbackTrait { * @param string $error_type * (optional) The type of error to trigger. One of: * - TrustedCallbackInterface::THROW_EXCEPTION - * - TrustedCallbackInterface::TRIGGER_WARNING + * - (deprecated) TrustedCallbackInterface::TRIGGER_WARNING * - TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION * Defaults to TrustedCallbackInterface::THROW_EXCEPTION. * @param string $extra_trusted_interface @@ -99,7 +99,9 @@ public function doTrustedCallback(callable $callback, array $args, $message, $er if ($error_type === TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION) { @trigger_error($message, E_USER_DEPRECATED); } + // @phpstan-ignore-next-line 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); } else { diff --git a/core/lib/Drupal/Core/Security/StaticTrustedCallbackHelper.php b/core/lib/Drupal/Core/Security/StaticTrustedCallbackHelper.php index f406c7a278d90192c84676b6834ae4b9e6d329b0..a368ae867add4746dc0585b8d1624de61e0a516e 100644 --- a/core/lib/Drupal/Core/Security/StaticTrustedCallbackHelper.php +++ b/core/lib/Drupal/Core/Security/StaticTrustedCallbackHelper.php @@ -23,7 +23,7 @@ class StaticTrustedCallbackHelper { * @param string $error_type * (optional) The type of error to trigger. One of: * - TrustedCallbackInterface::THROW_EXCEPTION - * - TrustedCallbackInterface::TRIGGER_WARNING + * - (deprecated) TrustedCallbackInterface::TRIGGER_WARNING * - TrustedCallbackInterface::TRIGGER_SILENCED_DEPRECATION * Defaults to TrustedCallbackInterface::THROW_EXCEPTION. * @param string $extra_trusted_interface diff --git a/core/lib/Drupal/Core/Security/TrustedCallbackInterface.php b/core/lib/Drupal/Core/Security/TrustedCallbackInterface.php index 78f6bb934393323ad7054b4e0df9f9cdb041ff18..68f2329cb7ce21298a83f3acbd32f02b056fb0a1 100644 --- a/core/lib/Drupal/Core/Security/TrustedCallbackInterface.php +++ b/core/lib/Drupal/Core/Security/TrustedCallbackInterface.php @@ -16,6 +16,12 @@ interface TrustedCallbackInterface { /** * 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'; diff --git a/core/tests/Drupal/Tests/Core/Security/DoTrustedCallbackTraitTest.php b/core/tests/Drupal/Tests/Core/Security/DoTrustedCallbackTraitTest.php index a97a5b6ab68416fe9d7fb0e70ecb6f2211bfd579..99361ac8923e096097f715b7bcc84268e0dd3534 100644 --- a/core/tests/Drupal/Tests/Core/Security/DoTrustedCallbackTraitTest.php +++ b/core/tests/Drupal/Tests/Core/Security/DoTrustedCallbackTraitTest.php @@ -89,8 +89,10 @@ public function testSilencedDeprecation($callback) { /** * @dataProvider errorTypeProvider + * @group legacy */ 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->expectWarningMessage('Drupal\Tests\Core\Security\UntrustedObject::callback is not trusted'); $this->doTrustedCallback($callback, [], '%s is not trusted', TrustedCallbackInterface::TRIGGER_WARNING);