diff --git a/core/modules/inline_form_errors/tests/src/Unit/FormErrorHandlerTest.php b/core/modules/inline_form_errors/tests/src/Unit/FormErrorHandlerTest.php
index ac80dbe713b28a03b9e58991bec7a127014156ee..554691d1fc6d6048f486188ba6912ab024d02a26 100644
--- a/core/modules/inline_form_errors/tests/src/Unit/FormErrorHandlerTest.php
+++ b/core/modules/inline_form_errors/tests/src/Unit/FormErrorHandlerTest.php
@@ -120,13 +120,20 @@ protected function setUp(): void {
    * @covers ::setElementErrorsFromFormState
    */
   public function testErrorMessagesInline() {
-    $this->messenger->expects($this->exactly(4))
+    $messages = [
+      'no title given',
+      'element is invisible',
+      'this missing element is invalid',
+      '3 errors have been found: <ul-comma-list-mock><li-mock>Test 1</li-mock><li-mock>Test 2 &amp; a half</li-mock><li-mock>Test 3</li-mock></ul-comma-list-mock>',
+    ];
+
+    $this->messenger->expects($this->exactly(count($messages)))
       ->method('addError')
-      ->withConsecutive(
-        ['no title given', FALSE],
-        ['element is invisible', FALSE],
-        ['this missing element is invalid', FALSE],
-        ['3 errors have been found: <ul-comma-list-mock><li-mock>Test 1</li-mock><li-mock>Test 2 &amp; a half</li-mock><li-mock>Test 3</li-mock></ul-comma-list-mock>', FALSE],
+      ->with(
+        $this->callback(function (string $message) use (&$messages): bool {
+          return array_shift($messages) === $message;
+        }),
+        FALSE
       );
 
     $this->renderer->expects($this->once())
@@ -164,16 +171,24 @@ public function testErrorMessagesInline() {
    */
   public function testErrorMessagesNotInline() {
     // Asserts all messages are summarized.
-    $this->messenger->expects($this->exactly(7))
+    $messages = [
+      'invalid',
+      'invalid',
+      'invalid',
+      'no error message',
+      'no title given',
+      'element is invisible',
+      'this missing element is invalid',
+    ];
+
+    $this->messenger->expects($this->exactly(count($messages)))
       ->method('addMessage')
-      ->withConsecutive(
-        ['invalid', 'error', FALSE],
-        ['invalid', 'error', FALSE],
-        ['invalid', 'error', FALSE],
-        ['no error message', 'error', FALSE],
-        ['no title given', 'error', FALSE],
-        ['element is invisible', 'error', FALSE],
-        ['this missing element is invalid', 'error', FALSE],
+      ->with(
+        $this->callback(function (string $message) use (&$messages): bool {
+          return array_shift($messages) === $message;
+        }),
+        'error',
+        FALSE
       );
 
     $this->renderer->expects($this->never())
diff --git a/core/phpstan-baseline.neon b/core/phpstan-baseline.neon
index 7c2d0ddf3e0579551e01da01274adfffb64fcd1f..e3790ef21ab895020923b50fa02f33e43e659078 100644
--- a/core/phpstan-baseline.neon
+++ b/core/phpstan-baseline.neon
@@ -1534,11 +1534,6 @@ parameters:
 			count: 1
 			path: modules/image/tests/src/Functional/ImageStyleFlushTest.php
 
-		-
-			message: "#^Call to deprecated method withConsecutive\\(\\) of class PHPUnit\\\\Framework\\\\MockObject\\\\Builder\\\\InvocationMocker\\.$#"
-			count: 2
-			path: modules/inline_form_errors/tests/src/Unit/FormErrorHandlerTest.php
-
 		-
 			message: "#^Variable \\$reason in empty\\(\\) always exists and is not falsy\\.$#"
 			count: 1
@@ -3343,11 +3338,6 @@ parameters:
 			count: 1
 			path: tests/Drupal/Tests/Core/Form/FormCacheTest.php
 
-		-
-			message: "#^Call to deprecated method withConsecutive\\(\\) of class PHPUnit\\\\Framework\\\\MockObject\\\\Builder\\\\InvocationMocker\\.$#"
-			count: 1
-			path: tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php
-
 		-
 			message: """
 				#^Call to deprecated method getConfig\\(\\) of class GuzzleHttp\\\\Client\\:
diff --git a/core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php b/core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php
index 163df6a1fa794e53e665933bbe2e3d5e26960ee1..f60ab6d0dff64e9c600d50140ac00a8ce8126440 100644
--- a/core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php
+++ b/core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php
@@ -50,15 +50,22 @@ protected function setUp(): void {
    * @covers ::displayErrorMessages
    */
   public function testDisplayErrorMessages() {
-    $this->messenger->expects($this->exactly(6))
+    $messages = [
+      'invalid',
+      'invalid',
+      'invalid',
+      'no title given',
+      'element is invisible',
+      'this missing element is invalid',
+    ];
+
+    $this->messenger->expects($this->exactly(count($messages)))
       ->method('addMessage')
-      ->withConsecutive(
-        ['invalid', 'error'],
-        ['invalid', 'error'],
-        ['invalid', 'error'],
-        ['no title given', 'error'],
-        ['element is invisible', 'error'],
-        ['this missing element is invalid', 'error'],
+      ->with(
+        $this->callback(function (string $message) use (&$messages): bool {
+          return array_shift($messages) === $message;
+        }),
+        'error',
       );
 
     $form = [