From 4e51c9b5e4326cfddddbbcdcc67442c5550d909a Mon Sep 17 00:00:00 2001
From: Dave Long <dave@longwaveconsulting.com>
Date: Wed, 29 Mar 2023 10:42:26 +0100
Subject: [PATCH] Revert "Issue #3306554 by andypost, mondrake:
 InvocationMocker::withConsecutive() is deprecated in PHPUnit 9.6 and removed
 from PHPUnit 10 - easy replacements"

This reverts commit 7d2f5dd13d114aa494f64e7966a3b9c02b3ab29d.
---
 .../tests/src/Unit/FormErrorHandlerTest.php          |  4 ++--
 .../src/Unit/MigrateSqlIdMapEnsureTablesTest.php     |  4 ++--
 core/modules/pgsql/tests/src/Unit/SchemaTest.php     |  2 +-
 .../src/Unit/Normalizer/EntityNormalizerTest.php     |  6 +++---
 core/modules/views/tests/src/Unit/ViewsDataTest.php  |  4 ++--
 .../Drupal/Tests/Core/Entity/EntityUnitTest.php      |  4 ++--
 .../KeyValueStore/KeyValueEntityStorageTest.php      | 12 ++++++------
 .../Entity/Sql/SqlContentEntityStorageSchemaTest.php |  2 +-
 .../Tests/Core/Extension/ModuleHandlerTest.php       |  2 +-
 core/tests/Drupal/Tests/Core/Form/FormCacheTest.php  |  2 +-
 .../Drupal/Tests/Core/Form/FormErrorHandlerTest.php  |  2 +-
 .../Tests/Core/Menu/ContextualLinkManagerTest.php    |  2 +-
 .../Drupal/Tests/Core/Menu/LocalTaskManagerTest.php  |  2 +-
 13 files changed, 24 insertions(+), 24 deletions(-)

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 4cb8a8537d40..962f1079559e 100644
--- a/core/modules/inline_form_errors/tests/src/Unit/FormErrorHandlerTest.php
+++ b/core/modules/inline_form_errors/tests/src/Unit/FormErrorHandlerTest.php
@@ -120,7 +120,7 @@ protected function setUp(): void {
   public function testErrorMessagesInline() {
     $this->messenger->expects($this->exactly(4))
       ->method('addError')
-      ->willReturnOnConsecutiveCalls(
+      ->withConsecutive(
         ['no title given', FALSE],
         ['element is invisible', FALSE],
         ['this missing element is invalid', FALSE],
@@ -164,7 +164,7 @@ public function testErrorMessagesNotInline() {
     // Asserts all messages are summarized.
     $this->messenger->expects($this->exactly(7))
       ->method('addMessage')
-      ->willReturnOnConsecutiveCalls(
+      ->withConsecutive(
         ['invalid', 'error', FALSE],
         ['invalid', 'error', FALSE],
         ['invalid', 'error', FALSE],
diff --git a/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapEnsureTablesTest.php b/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapEnsureTablesTest.php
index 606d3e61afef..cdcbc4468e43 100644
--- a/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapEnsureTablesTest.php
+++ b/core/modules/migrate/tests/src/Unit/MigrateSqlIdMapEnsureTablesTest.php
@@ -125,7 +125,7 @@ public function testEnsureTablesNotExist() {
       ]);
     $schema->expects($this->exactly(2))
       ->method('createTable')
-      ->willReturnOnConsecutiveCalls(
+      ->withConsecutive(
         ['migrate_map_sql_idmap_test', $map_table_schema],
         ['migrate_message_sql_idmap_test', $table_schema],
       );
@@ -153,7 +153,7 @@ public function testEnsureTablesExist() {
       ]);
     $schema->expects($this->exactly(3))
       ->method('addField')
-      ->willReturnOnConsecutiveCalls(
+      ->withConsecutive(
         [
           'migrate_map_sql_idmap_test', 'rollback_action', [
             'type' => 'int',
diff --git a/core/modules/pgsql/tests/src/Unit/SchemaTest.php b/core/modules/pgsql/tests/src/Unit/SchemaTest.php
index 3beb61a09980..3b9192fdea4e 100644
--- a/core/modules/pgsql/tests/src/Unit/SchemaTest.php
+++ b/core/modules/pgsql/tests/src/Unit/SchemaTest.php
@@ -55,7 +55,7 @@ public function testComputedConstraintName($table_name, $name, $expected) {
 
     $this->connection->expects($this->exactly(2))
       ->method('query')
-      ->willReturnOnConsecutiveCalls(
+      ->withConsecutive(
         [$this->anything()],
         ["SELECT 1 FROM pg_constraint WHERE conname = '$expected'"],
       )
diff --git a/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php b/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php
index ccb7ec11a6d4..453f527579c2 100644
--- a/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php
+++ b/core/modules/serialization/tests/src/Unit/Normalizer/EntityNormalizerTest.php
@@ -95,7 +95,7 @@ public function testNormalize() {
       ->getMock();
     $serializer->expects($this->exactly(2))
       ->method('normalize')
-      ->willReturnOnConsecutiveCalls(
+      ->withConsecutive(
         [$list_item_1, 'test_format'],
         [$list_item_2, 'test_format'],
       );
@@ -221,7 +221,7 @@ public function testDenormalizeWithValidBundle() {
       ->getMock();
     $serializer->expects($this->exactly(2))
       ->method('denormalize')
-      ->willReturnOnConsecutiveCalls(
+      ->withConsecutive(
         ['value_1', get_class($key_1), NULL, ['target_instance' => $key_1, 'entity_type' => 'test']],
         ['value_2', get_class($key_2), NULL, ['target_instance' => $key_2, 'entity_type' => 'test']],
       );
@@ -370,7 +370,7 @@ public function testDenormalizeWithNoBundle() {
       ->getMock();
     $serializer->expects($this->exactly(2))
       ->method('denormalize')
-      ->willReturnOnConsecutiveCalls(
+      ->withConsecutive(
         ['value_1', get_class($key_1), NULL, ['target_instance' => $key_1, 'entity_type' => 'test']],
         ['value_2', get_class($key_2), NULL, ['target_instance' => $key_2, 'entity_type' => 'test']],
       );
diff --git a/core/modules/views/tests/src/Unit/ViewsDataTest.php b/core/modules/views/tests/src/Unit/ViewsDataTest.php
index cd9b88108bc3..0177af2b7ab2 100644
--- a/core/modules/views/tests/src/Unit/ViewsDataTest.php
+++ b/core/modules/views/tests/src/Unit/ViewsDataTest.php
@@ -369,7 +369,7 @@ public function testCacheCallsWithSameTableMultipleTimes() {
       );
     $this->cacheBackend->expects($this->exactly(2))
       ->method('set')
-      ->willReturnOnConsecutiveCalls(
+      ->withConsecutive(
         ['views_data:en', $expected_views_data],
         ['views_data:views_test_data:en', $expected_views_data['views_test_data']],
       );
@@ -600,7 +600,7 @@ public function testCacheCallsWithoutWarmCacheAndGetMultipleTables() {
       );
     $this->cacheBackend->expects($this->exactly(2))
       ->method('set')
-      ->willReturnOnConsecutiveCalls(
+      ->withConsecutive(
         ["views_data:$table_name:en", $expected_views_data[$table_name]],
         ["views_data:$table_name_2:en", $expected_views_data[$table_name_2]],
       );
diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php
index b5bfc2a0d7f9..864851279c2b 100644
--- a/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/EntityUnitTest.php
@@ -398,7 +398,7 @@ public function testPreSave() {
   public function testPostSave() {
     $this->cacheTagsInvalidator->expects($this->exactly(2))
       ->method('invalidateTags')
-      ->willReturnOnConsecutiveCalls([
+      ->withConsecutive([
         [
           // List cache tag.
           $this->entityTypeId . '_list',
@@ -429,7 +429,7 @@ public function testPostSave() {
   public function testPostSaveBundle() {
     $this->cacheTagsInvalidator->expects($this->exactly(2))
       ->method('invalidateTags')
-      ->willReturnOnConsecutiveCalls([
+      ->withConsecutive([
         [
           // List cache tag.
           $this->entityTypeId . '_list',
diff --git a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php
index 3db613bb747c..90b0f1c6ce90 100644
--- a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php
@@ -157,7 +157,7 @@ public function testCreateWithPredefinedUuid() {
 
     $this->moduleHandler->expects($this->exactly(2))
       ->method('invokeAll')
-      ->willReturnOnConsecutiveCalls(['test_entity_type_create'], ['entity_create']);
+      ->withConsecutive(['test_entity_type_create'], ['entity_create']);
     $this->uuidService->expects($this->never())
       ->method('generate');
 
@@ -180,7 +180,7 @@ public function testCreateWithoutUuidKey() {
 
     $this->moduleHandler->expects($this->exactly(2))
       ->method('invokeAll')
-      ->willReturnOnConsecutiveCalls(['test_entity_type_create'], ['entity_create']);
+      ->withConsecutive(['test_entity_type_create'], ['entity_create']);
     $this->uuidService->expects($this->never())
       ->method('generate');
 
@@ -205,7 +205,7 @@ public function testCreate() {
 
     $this->moduleHandler->expects($this->exactly(2))
       ->method('invokeAll')
-      ->willReturnOnConsecutiveCalls(['test_entity_type_create'], ['entity_create']);
+      ->withConsecutive(['test_entity_type_create'], ['entity_create']);
     $this->uuidService->expects($this->once())
       ->method('generate')
       ->willReturn('bar');
@@ -247,7 +247,7 @@ public function testSaveInsert(EntityInterface $entity) {
 
     $this->moduleHandler->expects($this->exactly(4))
       ->method('invokeAll')
-      ->willReturnOnConsecutiveCalls(
+      ->withConsecutive(
         ['test_entity_type_presave'],
         ['entity_presave'],
         ['test_entity_type_insert'],
@@ -291,7 +291,7 @@ public function testSaveUpdate(EntityInterface $entity) {
       ->method('delete');
     $this->moduleHandler->expects($this->exactly(4))
       ->method('invokeAll')
-      ->willReturnOnConsecutiveCalls(
+      ->withConsecutive(
         ['test_entity_type_presave'],
         ['entity_presave'],
         ['test_entity_type_update'],
@@ -569,7 +569,7 @@ public function testDelete() {
 
     $this->moduleHandler->expects($this->exactly(8))
       ->method('invokeAll')
-      ->willReturnOnConsecutiveCalls(
+      ->withConsecutive(
         ['test_entity_type_predelete'],
         ['entity_predelete'],
       );
diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php
index ad1ba5c0bc1c..02b2c7e0603d 100644
--- a/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/Sql/SqlContentEntityStorageSchemaTest.php
@@ -1538,7 +1538,7 @@ public function testonEntityTypeUpdateWithNewIndex() {
     // The original indexes should be dropped before the new one is added.
     $this->dbSchemaHandler->expects($this->exactly(3))
       ->method('dropIndex')
-      ->willReturnOnConsecutiveCalls(
+      ->withConsecutive(
         ['entity_test', 'entity_test__b588603cb9'],
         ['entity_test', 'entity_test__removed_field'],
       );
diff --git a/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
index d2f98f078663..6edf3f03e1bc 100644
--- a/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
+++ b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
@@ -115,7 +115,7 @@ public function testModuleReloading() {
       ->getMock();
     $module_handler->expects($this->exactly(3))
       ->method('load')
-      ->willReturnOnConsecutiveCalls(
+      ->withConsecutive(
         // First reload.
         ['module_handler_test'],
         // Second reload.
diff --git a/core/tests/Drupal/Tests/Core/Form/FormCacheTest.php b/core/tests/Drupal/Tests/Core/Form/FormCacheTest.php
index 01aeed92b1a1..765fcfe2814e 100644
--- a/core/tests/Drupal/Tests/Core/Form/FormCacheTest.php
+++ b/core/tests/Drupal/Tests/Core/Form/FormCacheTest.php
@@ -313,7 +313,7 @@ public function testLoadCachedFormStateWithFiles() {
     ];
     $this->moduleHandler->expects($this->exactly(2))
       ->method('loadInclude')
-      ->willReturnOnConsecutiveCalls(
+      ->withConsecutive(
         ['a_module', 'the_type', 'some_name'],
         ['another_module', 'inc', 'another_module'],
       );
diff --git a/core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php b/core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php
index d27fd5e84d68..237050d1b735 100644
--- a/core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php
+++ b/core/tests/Drupal/Tests/Core/Form/FormErrorHandlerTest.php
@@ -50,7 +50,7 @@ protected function setUp(): void {
   public function testDisplayErrorMessages() {
     $this->messenger->expects($this->exactly(6))
       ->method('addMessage')
-      ->willReturnOnConsecutiveCalls(
+      ->withConsecutive(
         ['invalid', 'error'],
         ['invalid', 'error'],
         ['invalid', 'error'],
diff --git a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php
index 56a03c6c4396..3dea04ef2721 100644
--- a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php
+++ b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php
@@ -246,7 +246,7 @@ public function testGetContextualLinksArrayByGroup() {
 
     $this->moduleHandler->expects($this->exactly(2))
       ->method('alter')
-      ->willReturnOnConsecutiveCalls(
+      ->withConsecutive(
         ['contextual_links_plugins'],
         ['contextual_links', new Count(2), 'group1', ['key' => 'value']],
       );
diff --git a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php
index 19d8f815d382..8e6acbf0c024 100644
--- a/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php
+++ b/core/tests/Drupal/Tests/Core/Menu/LocalTaskManagerTest.php
@@ -186,7 +186,7 @@ public function testGetLocalTaskForRouteWithEmptyCache() {
       );
     $this->cacheBackend->expects($this->exactly(2))
       ->method('set')
-      ->willReturnOnConsecutiveCalls(
+      ->withConsecutive(
         ['local_task_plugins:en', $definitions, Cache::PERMANENT],
         ['local_task_plugins:en:menu_local_task_test_tasks_view', $this->getLocalTasksCache(), Cache::PERMANENT, ['local_task']],
       );
-- 
GitLab