From f60bcea7d7cfa53938bb16f70915ec90cf69965e Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Tue, 9 Apr 2024 23:19:05 +0100
Subject: [PATCH] Issue #3402713 by mstrelan, smustgrave, dww: Fix strict type
 errors: miscellaneous fixes in core Kernel tests

---
 core/modules/filter/tests/src/Kernel/FilterKernelTest.php   | 2 +-
 .../link/tests/src/Kernel/LinkItemSerializationTest.php     | 2 +-
 .../mysql/tests/src/Kernel/mysql/TemporaryQueryTest.php     | 2 +-
 core/modules/node/tests/src/Kernel/Views/PathPluginTest.php | 2 +-
 core/modules/node/tests/src/Kernel/Views/RowPluginTest.php  | 4 ++--
 core/modules/user/tests/src/Kernel/WhoIsOnlineBlockTest.php | 3 ++-
 .../tests/src/Kernel/Handler/ComputedBundleFieldTest.php    | 6 +++---
 .../Drupal/KernelTests/Core/Path/PathValidatorTest.php      | 4 +++-
 core/tests/Drupal/KernelTests/Core/Theme/ClaroTableTest.php | 2 +-
 9 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/core/modules/filter/tests/src/Kernel/FilterKernelTest.php b/core/modules/filter/tests/src/Kernel/FilterKernelTest.php
index a2cce36b180c..fd7fbc818102 100644
--- a/core/modules/filter/tests/src/Kernel/FilterKernelTest.php
+++ b/core/modules/filter/tests/src/Kernel/FilterKernelTest.php
@@ -513,7 +513,7 @@ public function testLineBreakFilterTwigDebug(): void {
       'children' => 'Test two',
     ];
     include_once $this->root . '/core/themes/engines/twig/twig.engine';
-    $render = twig_render_template('container.html.twig', $variables);
+    $render = (string) twig_render_template('container.html.twig', $variables);
     $render = trim($render);
 
     // Render text before applying the auto paragraph filter.
diff --git a/core/modules/link/tests/src/Kernel/LinkItemSerializationTest.php b/core/modules/link/tests/src/Kernel/LinkItemSerializationTest.php
index f0e71a659e62..36d5b97703d3 100644
--- a/core/modules/link/tests/src/Kernel/LinkItemSerializationTest.php
+++ b/core/modules/link/tests/src/Kernel/LinkItemSerializationTest.php
@@ -96,7 +96,7 @@ public function testLinkDeserialization() {
       ->set('query', $parsed_url['query']);
     $json = json_decode($this->serializer->serialize($entity, 'json'), TRUE);
     $json['field_test'][0]['options'] = 'string data';
-    $serialized = json_encode($json, TRUE);
+    $serialized = json_encode($json);
     $this->expectException(\LogicException::class);
     $this->expectExceptionMessage('The generic FieldItemNormalizer cannot denormalize string values for "options" properties of the "field_test" field (field item class: Drupal\link\Plugin\Field\FieldType\LinkItem).');
     $this->serializer->deserialize($serialized, EntityTest::class, 'json');
diff --git a/core/modules/mysql/tests/src/Kernel/mysql/TemporaryQueryTest.php b/core/modules/mysql/tests/src/Kernel/mysql/TemporaryQueryTest.php
index 484ccc75227e..a2d7fcbabb86 100644
--- a/core/modules/mysql/tests/src/Kernel/mysql/TemporaryQueryTest.php
+++ b/core/modules/mysql/tests/src/Kernel/mysql/TemporaryQueryTest.php
@@ -23,7 +23,7 @@ public function testTemporaryQuery() {
 
     // Assert that the table is indeed a temporary one.
     $temporary_table_info = $connection->query("SHOW CREATE TABLE {" . $table_name_test . "}")->fetchAssoc();
-    $this->stringContains($temporary_table_info["Create Table"], "CREATE TEMPORARY TABLE");
+    $this->assertStringContainsString('CREATE TEMPORARY TABLE', $temporary_table_info['Create Table']);
 
     // Assert that both have the same field names.
     $normal_table_fields = $connection->query("SELECT * FROM {test}")->fetch();
diff --git a/core/modules/node/tests/src/Kernel/Views/PathPluginTest.php b/core/modules/node/tests/src/Kernel/Views/PathPluginTest.php
index aadfeaff4748..c4fbd04d314d 100644
--- a/core/modules/node/tests/src/Kernel/Views/PathPluginTest.php
+++ b/core/modules/node/tests/src/Kernel/Views/PathPluginTest.php
@@ -86,7 +86,7 @@ public function testPathPlugin(): void {
 
     // Test with view_mode full.
     $output = $view->preview();
-    $output = $renderer->renderRoot($output);
+    $output = (string) $renderer->renderRoot($output);
     foreach ($this->nodes as $node) {
       $this->assertStringContainsString('This is <strong>not escaped</strong> and this is ' . $node->toLink('the link')->toString(), $output, 'Make sure path field rewriting is not escaped.');
     }
diff --git a/core/modules/node/tests/src/Kernel/Views/RowPluginTest.php b/core/modules/node/tests/src/Kernel/Views/RowPluginTest.php
index 4206fa9abf8b..251ee45dc50c 100644
--- a/core/modules/node/tests/src/Kernel/Views/RowPluginTest.php
+++ b/core/modules/node/tests/src/Kernel/Views/RowPluginTest.php
@@ -98,7 +98,7 @@ public function testRowPlugin(): void {
 
     // Test with view_mode full.
     $output = $view->preview();
-    $output = $renderer->renderRoot($output);
+    $output = (string) $renderer->renderRoot($output);
     foreach ($this->nodes as $node) {
       $this->assertStringNotContainsString($node->body->summary, $output, 'Make sure the teaser appears in the output of the view.');
       $this->assertStringContainsString($node->body->value, $output, 'Make sure the full text appears in the output of the view.');
@@ -107,7 +107,7 @@ public function testRowPlugin(): void {
     // Test with teasers.
     $view->rowPlugin->options['view_mode'] = 'teaser';
     $output = $view->preview();
-    $output = $renderer->renderRoot($output);
+    $output = (string) $renderer->renderRoot($output);
     foreach ($this->nodes as $node) {
       $this->assertStringContainsString($node->body->summary, $output, 'Make sure the teaser appears in the output of the view.');
       $this->assertStringNotContainsString($node->body->value, $output);
diff --git a/core/modules/user/tests/src/Kernel/WhoIsOnlineBlockTest.php b/core/modules/user/tests/src/Kernel/WhoIsOnlineBlockTest.php
index 0b329c96fb61..c9b52afa3494 100644
--- a/core/modules/user/tests/src/Kernel/WhoIsOnlineBlockTest.php
+++ b/core/modules/user/tests/src/Kernel/WhoIsOnlineBlockTest.php
@@ -123,7 +123,8 @@ public function testWhoIsOnlineBlock() {
     $this->assertText($user2->getAccountName(), 'Active user 2 found in online list.');
     $this->assertNoText($user3->getAccountName(), 'Inactive user not found in online list.');
     // Verify that online users are ordered correctly.
-    $this->assertGreaterThan(strpos($this->getRawContent(), $user2->getAccountName()), strpos($this->getRawContent(), $user1->getAccountName()));
+    $raw_content = (string) $this->getRawContent();
+    $this->assertGreaterThan(strpos($raw_content, $user2->getAccountName()), strpos($raw_content, $user1->getAccountName()));
   }
 
 }
diff --git a/core/modules/views/tests/src/Kernel/Handler/ComputedBundleFieldTest.php b/core/modules/views/tests/src/Kernel/Handler/ComputedBundleFieldTest.php
index cb1fd31d008e..8632f9c0f78d 100644
--- a/core/modules/views/tests/src/Kernel/Handler/ComputedBundleFieldTest.php
+++ b/core/modules/views/tests/src/Kernel/Handler/ComputedBundleFieldTest.php
@@ -84,9 +84,9 @@ public function testComputedFieldHandler() {
 
     // Entities 1 and 2 should have the computed bundle field. But entity 3
     // should not.
-    $this->assertStringContainsString('some other string that is also computed', $view->field['computed_bundle_field']->render($view->result[0]));
-    $this->assertStringContainsString('some other string that is also computed', $view->field['computed_bundle_field']->render($view->result[1]));
-    $this->assertStringNotContainsString('some other string that is also computed', $view->field['computed_bundle_field']->render($view->result[2]));
+    $this->assertStringContainsString('some other string that is also computed', (string) $view->field['computed_bundle_field']->render($view->result[0]));
+    $this->assertStringContainsString('some other string that is also computed', (string) $view->field['computed_bundle_field']->render($view->result[1]));
+    $this->assertStringNotContainsString('some other string that is also computed', (string) $view->field['computed_bundle_field']->render($view->result[2]));
 
     $view->destroy();
   }
diff --git a/core/tests/Drupal/KernelTests/Core/Path/PathValidatorTest.php b/core/tests/Drupal/KernelTests/Core/Path/PathValidatorTest.php
index 588fecae8c5b..383537bceb1b 100644
--- a/core/tests/Drupal/KernelTests/Core/Path/PathValidatorTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Path/PathValidatorTest.php
@@ -64,8 +64,10 @@ public function testGetUrlIfValidWithoutAccessCheck() {
         }
         $this->container->set('router.request_context', new RequestContext());
       }
+      else {
+        $requestContext->setMethod($method);
+      }
 
-      $requestContext->setMethod($method);
       /** @var \Drupal\Core\Url $url */
       $url = $pathValidator->getUrlIfValidWithoutAccessCheck($entity->toUrl()->toString(TRUE)->getGeneratedUrl());
       $this->assertEquals($method, $requestContext->getMethod());
diff --git a/core/tests/Drupal/KernelTests/Core/Theme/ClaroTableTest.php b/core/tests/Drupal/KernelTests/Core/Theme/ClaroTableTest.php
index 213f54b34e78..cb3e0ff35efa 100644
--- a/core/tests/Drupal/KernelTests/Core/Theme/ClaroTableTest.php
+++ b/core/tests/Drupal/KernelTests/Core/Theme/ClaroTableTest.php
@@ -64,7 +64,7 @@ public function testThemeTablePositionStickyPreRender(): void {
       ],
     ];
 
-    $renderedTable = \Drupal::service('renderer')->renderRoot($table);
+    $renderedTable = (string) \Drupal::service('renderer')->renderRoot($table);
 
     // Confirm that table is rendered.
     $this->assertStringContainsString('class="class"', $renderedTable);
-- 
GitLab