From a50c07aa930363e64bda118adc24afa1e6b101da Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Wed, 10 Apr 2024 22:07:05 +0100
Subject: [PATCH] Issue #3427178 by mondrake, longwave: Replace calls to
 ::expectWarning*() from Drupal\Tests\Core\Security\DoTrustedCallbackTraitTest

---
 core/.phpstan-baseline.php                           | 12 ------------
 .../Drupal/Core/Security/DoTrustedCallbackTrait.php  |  4 +++-
 .../Core/Security/StaticTrustedCallbackHelper.php    |  2 +-
 .../Core/Security/TrustedCallbackInterface.php       |  6 ++++++
 .../Core/Security/DoTrustedCallbackTraitTest.php     |  2 ++
 5 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/core/.phpstan-baseline.php b/core/.phpstan-baseline.php
index ba6babd797f4..f587c034f38e 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 5c1079b9e0c7..da6783d2289c 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 f406c7a278d9..a368ae867add 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 78f6bb934393..68f2329cb7ce 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 a97a5b6ab684..99361ac8923e 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);
-- 
GitLab