From 0ce407c41df3193bea4970aab7f44a93671bfcd7 Mon Sep 17 00:00:00 2001
From: catch <catch@35733.no-reply.drupal.org>
Date: Thu, 1 Feb 2024 04:09:18 +0000
Subject: [PATCH] Issue #3418182 by longwave: Remove withConsecutive() in
 ViewsDataTest

---
 .../views/tests/src/Unit/ViewsDataTest.php    | 131 ++++++++++--------
 core/phpstan-baseline.neon                    |   5 -
 2 files changed, 76 insertions(+), 60 deletions(-)

diff --git a/core/modules/views/tests/src/Unit/ViewsDataTest.php b/core/modules/views/tests/src/Unit/ViewsDataTest.php
index 84d7835037af..49fbbbcc71a0 100644
--- a/core/modules/views/tests/src/Unit/ViewsDataTest.php
+++ b/core/modules/views/tests/src/Unit/ViewsDataTest.php
@@ -220,23 +220,33 @@ public function testFullAndTableGetCache() {
 
     // The cache should only be called once (before the clear() call) as get
     // will get all table data in the first get().
-    $this->cacheBackend->expects($this->exactly(4))
+    $gets = [
+      'views_data:en',
+      "views_data:$random_table_name:en",
+      'views_data:en',
+      "views_data:$random_table_name:en",
+    ];
+    $this->cacheBackend->expects($this->exactly(count($gets)))
       ->method('get')
-      ->withConsecutive(
-        ['views_data:en'],
-        ["views_data:$random_table_name:en"],
-        ['views_data:en'],
-        ["views_data:$random_table_name:en"],
-      )
+      ->with($this->callback(function (string $key) use (&$gets): bool {
+        return $key === array_shift($gets);
+      }))
       ->willReturn(FALSE);
-    $this->cacheBackend->expects($this->exactly(4))
+
+    $sets = [
+      'views_data:en', $expected_views_data,
+      "views_data:$random_table_name:en", [],
+      'views_data:en', $expected_views_data,
+      "views_data:$random_table_name:en", [],
+    ];
+    $this->cacheBackend->expects($this->exactly(count($sets) / 2))
       ->method('set')
-      ->withConsecutive(
-        ['views_data:en', $expected_views_data],
-        ["views_data:$random_table_name:en", []],
-        ['views_data:en', $expected_views_data],
-        ["views_data:$random_table_name:en", []],
-      );
+      ->with($this->callback(function (string $key) use (&$sets): bool {
+        return $key === array_shift($sets);
+      }), $this->callback(function (array $data) use (&$sets): bool {
+        return $data === array_shift($sets);
+      }));
+
     $this->cacheTagsInvalidator->expects($this->once())
       ->method('invalidateTags')
       ->with(['views_data']);
@@ -303,12 +313,12 @@ public function testSingleTableGetCache() {
       ->method('alter')
       ->with('views_data', $this->viewsDataWithProvider());
 
-    $this->cacheBackend->expects($this->exactly(2))
+    $gets = ["views_data:$table_name:en", 'views_data:en'];
+    $this->cacheBackend->expects($this->exactly(count($gets)))
       ->method('get')
-      ->withConsecutive(
-        ["views_data:$table_name:en"],
-        ['views_data:en'],
-      )
+      ->with($this->callback(function (string $key) use (&$gets): bool {
+        return $key === array_shift($gets);
+      }))
       ->willReturn(FALSE);
 
     $views_data = $this->viewsData->get($table_name);
@@ -337,12 +347,12 @@ public function testNonExistingTableGetCache() {
       ->method('alter')
       ->with('views_data', $this->viewsDataWithProvider());
 
-    $this->cacheBackend->expects($this->exactly(2))
+    $gets = ["views_data:$random_table_name:en", 'views_data:en'];
+    $this->cacheBackend->expects($this->exactly(count($gets)))
       ->method('get')
-      ->withConsecutive(
-        ["views_data:$random_table_name:en"],
-        ['views_data:en'],
-      )
+      ->with($this->callback(function (string $key) use (&$gets): bool {
+        return $key === array_shift($gets);
+      }))
       ->willReturn(FALSE);
 
     // All views data should be requested on the first try.
@@ -362,18 +372,24 @@ public function testCacheCallsWithSameTableMultipleTimes() {
 
     $this->setupMockedModuleHandler();
 
-    $this->cacheBackend->expects($this->exactly(2))
+    $gets = ['views_data:views_test_data:en', 'views_data:en'];
+    $this->cacheBackend->expects($this->exactly(count($gets)))
       ->method('get')
-      ->withConsecutive(
-        ['views_data:views_test_data:en'],
-        ['views_data:en'],
-      );
-    $this->cacheBackend->expects($this->exactly(2))
+      ->with($this->callback(function (string $key) use (&$gets): bool {
+        return $key === array_shift($gets);
+      }));
+
+    $sets = [
+      'views_data:en', $expected_views_data,
+      'views_data:views_test_data:en', $expected_views_data['views_test_data'],
+    ];
+    $this->cacheBackend->expects($this->exactly(count($sets) / 2))
       ->method('set')
-      ->withConsecutive(
-        ['views_data:en', $expected_views_data],
-        ['views_data:views_test_data:en', $expected_views_data['views_test_data']],
-      );
+      ->with($this->callback(function (string $key) use (&$sets): bool {
+        return $key === array_shift($sets);
+      }), $this->callback(function (array $data) use (&$sets): bool {
+        return $data === array_shift($sets);
+      }));
 
     // Request the same table 5 times. The caches are empty at this point, so
     // what will happen is that it will first check for a cache entry for the
@@ -430,12 +446,12 @@ public function testCacheCallsWithWarmCacheAndDifferentTable() {
       ->method('invokeAllWith');
 
     // Setup a warm cache backend for a single table.
-    $this->cacheBackend->expects($this->exactly(2))
+    $gets = ['views_data:views_test_data_2:en', 'views_data:en'];
+    $this->cacheBackend->expects($this->exactly(count($gets)))
       ->method('get')
-      ->withConsecutive(
-        ['views_data:views_test_data_2:en'],
-        ['views_data:en'],
-      )
+      ->with($this->callback(function (string $key) use (&$gets): bool {
+        return $key === array_shift($gets);
+      }))
       ->willReturnOnConsecutiveCalls(
         FALSE,
         (object) ['data' => $expected_views_data],
@@ -469,12 +485,12 @@ public function testCacheCallsWithWarmCacheAndInvalidTable() {
       ->method('invokeAllWith');
 
     // Setup a warm cache backend for a single table.
-    $this->cacheBackend->expects($this->exactly(2))
+    $gets = ["views_data:$non_existing_table:en", 'views_data:en'];
+    $this->cacheBackend->expects($this->exactly(count($gets)))
       ->method('get')
-      ->withConsecutive(
-        ["views_data:$non_existing_table:en"],
-        ['views_data:en'],
-      )
+      ->with($this->callback(function (string $key) use (&$gets): bool {
+        return $key === array_shift($gets);
+      }))
       ->willReturnOnConsecutiveCalls(
         FALSE,
         (object) ['data' => $expected_views_data],
@@ -587,24 +603,29 @@ public function testCacheCallsWithoutWarmCacheAndGetMultipleTables() {
     $table_name_2 = 'views_test_data_2';
 
     // Setup a warm cache backend for all table data, but not single tables.
-    $this->cacheBackend->expects($this->exactly(3))
+    $gets = ["views_data:$table_name:en", 'views_data:en', "views_data:$table_name_2:en"];
+    $this->cacheBackend->expects($this->exactly(count($gets)))
       ->method('get')
-      ->withConsecutive(
-        ["views_data:$table_name:en"],
-        ['views_data:en'],
-        ["views_data:$table_name_2:en"],
-      )
+      ->with($this->callback(function (string $key) use (&$gets): bool {
+        return $key === array_shift($gets);
+      }))
       ->willReturnOnConsecutiveCalls(
         FALSE,
         (object) ['data' => $expected_views_data],
         FALSE,
       );
-    $this->cacheBackend->expects($this->exactly(2))
+
+    $sets = [
+      "views_data:$table_name:en", $expected_views_data[$table_name],
+      "views_data:$table_name_2:en", $expected_views_data[$table_name_2],
+    ];
+    $this->cacheBackend->expects($this->exactly(count($sets) / 2))
       ->method('set')
-      ->withConsecutive(
-        ["views_data:$table_name:en", $expected_views_data[$table_name]],
-        ["views_data:$table_name_2:en", $expected_views_data[$table_name_2]],
-      );
+      ->with($this->callback(function (string $key) use (&$sets): bool {
+        return $key === array_shift($sets);
+      }), $this->callback(function (array $data) use (&$sets): bool {
+        return $data === array_shift($sets);
+      }));
 
     $this->assertSame($expected_views_data[$table_name], $this->viewsData->get($table_name));
     $this->assertSame($expected_views_data[$table_name_2], $this->viewsData->get($table_name_2));
diff --git a/core/phpstan-baseline.neon b/core/phpstan-baseline.neon
index 5eb7a3bda49d..806b2fcb77d5 100644
--- a/core/phpstan-baseline.neon
+++ b/core/phpstan-baseline.neon
@@ -2819,11 +2819,6 @@ parameters:
 			count: 2
 			path: modules/views/tests/src/Kernel/RenderCacheIntegrationTest.php
 
-		-
-			message: "#^Call to deprecated method withConsecutive\\(\\) of class PHPUnit\\\\Framework\\\\MockObject\\\\Builder\\\\InvocationMocker\\.$#"
-			count: 10
-			path: modules/views/tests/src/Unit/ViewsDataTest.php
-
 		-
 			message: "#^Variable \\$relationship_handler in empty\\(\\) always exists and is not falsy\\.$#"
 			count: 1
-- 
GitLab