From 910b569f8e58ebcfd27436f3e6393c07894a6a36 Mon Sep 17 00:00:00 2001
From: xjm <xjm@65776.no-reply.drupal.org>
Date: Wed, 15 Nov 2023 19:57:15 -0600
Subject: [PATCH] Issue #3397890 by mstrelan, dww: Fix strict type errors in
 unit tests

---
 core/modules/ban/tests/src/Unit/BanMiddlewareTest.php     | 2 +-
 .../tests/src/Unit/MigrationStateUnitTest.php             | 2 +-
 core/modules/phpass/tests/src/Unit/PasswordVerifyTest.php | 2 +-
 core/modules/update/tests/src/Unit/UpdateFetcherTest.php  | 6 +++---
 .../Drupal/Tests/Component/Datetime/DateTimePlusTest.php  | 8 ++++----
 .../Dumper/OptimizedPhpArrayDumperTest.php                | 2 +-
 .../Drupal/Tests/Core/Datetime/DrupalDateTimeTest.php     | 4 ++--
 .../Core/Form/EventSubscriber/FormAjaxSubscriberTest.php  | 2 +-
 core/tests/Drupal/Tests/Core/Form/FormStateTest.php       | 4 ++--
 core/tests/Drupal/Tests/Core/Password/PhpPasswordTest.php | 2 +-
 .../Drupal/Tests/Core/Render/RendererBubblingTest.php     | 2 +-
 .../Drupal/Tests/Core/Render/RendererRecursionTest.php    | 2 +-
 core/tests/Drupal/Tests/Core/Render/RendererTest.php      | 4 ++--
 .../Drupal/Tests/Core/Template/TwigExtensionTest.php      | 2 +-
 .../tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php | 6 +++---
 15 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/core/modules/ban/tests/src/Unit/BanMiddlewareTest.php b/core/modules/ban/tests/src/Unit/BanMiddlewareTest.php
index 7f12b37e5dbf..42d61eee5ae4 100644
--- a/core/modules/ban/tests/src/Unit/BanMiddlewareTest.php
+++ b/core/modules/ban/tests/src/Unit/BanMiddlewareTest.php
@@ -78,7 +78,7 @@ public function testUnbannedIp() {
 
     $request = Request::create('/test-path');
     $request->server->set('REMOTE_ADDR', $unbanned_ip);
-    $expected_response = new Response(200);
+    $expected_response = new Response(status: 200);
     $this->kernel->expects($this->once())
       ->method('handle')
       ->with($request, HttpKernelInterface::MAIN_REQUEST, TRUE)
diff --git a/core/modules/migrate_drupal/tests/src/Unit/MigrationStateUnitTest.php b/core/modules/migrate_drupal/tests/src/Unit/MigrationStateUnitTest.php
index ea4b54356ea6..1dd8f926960f 100644
--- a/core/modules/migrate_drupal/tests/src/Unit/MigrationStateUnitTest.php
+++ b/core/modules/migrate_drupal/tests/src/Unit/MigrationStateUnitTest.php
@@ -48,7 +48,7 @@ public function testGetUpgradeStates($modules_to_enable, $files, $field_plugins,
 
     foreach ($files as $module => $contents) {
       $path = $url . '/' . $module . '/migrations/state';
-      mkdir($path, '0755', TRUE);
+      mkdir($path, 0755, TRUE);
       file_put_contents($path . '/' . $module . '.migrate_drupal.yml', $contents);
     }
     $moduleHandler->getModuleDirectories()
diff --git a/core/modules/phpass/tests/src/Unit/PasswordVerifyTest.php b/core/modules/phpass/tests/src/Unit/PasswordVerifyTest.php
index f080bd2396de..c130029ee185 100644
--- a/core/modules/phpass/tests/src/Unit/PasswordVerifyTest.php
+++ b/core/modules/phpass/tests/src/Unit/PasswordVerifyTest.php
@@ -149,7 +149,7 @@ public function providerLongPasswords() {
 
     // Check a string of 3-byte UTF-8 characters, 510 byte long password is
     // allowed.
-    $len = floor(PasswordInterface::PASSWORD_MAX_LENGTH / 3);
+    $len = (int) floor(PasswordInterface::PASSWORD_MAX_LENGTH / 3);
     $diff = PasswordInterface::PASSWORD_MAX_LENGTH % 3;
     $passwords['utf8'] = [str_repeat('€', $len), TRUE];
     // 512 byte long password is allowed.
diff --git a/core/modules/update/tests/src/Unit/UpdateFetcherTest.php b/core/modules/update/tests/src/Unit/UpdateFetcherTest.php
index cde0a60c3ded..2c1256e9f94a 100644
--- a/core/modules/update/tests/src/Unit/UpdateFetcherTest.php
+++ b/core/modules/update/tests/src/Unit/UpdateFetcherTest.php
@@ -178,7 +178,7 @@ public function testUpdateFetcherNoFallback() {
     // First, try without the HTTP fallback setting, and HTTPS mocked to fail.
     $settings = new Settings([]);
     $this->mockClient(
-      new Response('500', [], 'HTTPS failed'),
+      new Response(500, [], 'HTTPS failed'),
     );
     $update_fetcher = new UpdateFetcher($this->mockConfigFactory, $this->mockHttpClient, $settings, $this->logger);
 
@@ -206,8 +206,8 @@ public function testUpdateFetcherNoFallback() {
   public function testUpdateFetcherHttpFallback() {
     $settings = new Settings(['update_fetch_with_http_fallback' => TRUE]);
     $this->mockClient(
-      new Response('500', [], 'HTTPS failed'),
-      new Response('200', [], 'HTTP worked'),
+      new Response(500, [], 'HTTPS failed'),
+      new Response(200, [], 'HTTP worked'),
     );
     $update_fetcher = new UpdateFetcher($this->mockConfigFactory, $this->mockHttpClient, $settings, $this->logger);
 
diff --git a/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php b/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php
index 6e128c632afa..dcfa56ca9135 100644
--- a/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php
+++ b/core/tests/Drupal/Tests/Component/Datetime/DateTimePlusTest.php
@@ -186,7 +186,7 @@ public function testDateTimestamp($input, array $initial, array $transform) {
    *
    * @param \Drupal\Component\Datetime\DateTimePlus $date
    *   DateTimePlus to test.
-   * @param string $input
+   * @param string|int $input
    *   The original input passed to the test method.
    * @param array $initial
    *   @see testTimestamp()
@@ -195,7 +195,7 @@ public function testDateTimestamp($input, array $initial, array $transform) {
    *
    * @internal
    */
-  public function assertDateTimestamp(DateTimePlus $date, string $input, array $initial, array $transform): void {
+  public function assertDateTimestamp(DateTimePlus $date, string|int $input, array $initial, array $transform): void {
     // Check format.
     $value = $date->format($initial['format']);
     $this->assertEquals($initial['expected_date'], $value, sprintf("Test new DateTimePlus(%s, %s): should be %s, found %s.", $input, $initial['timezone'], $initial['expected_date'], $value));
@@ -694,7 +694,7 @@ public function providerTestDateDiff() {
       ],
       [
         'input1' => DateTimePlus::createFromFormat('U', 3600),
-        'input2' => \DateTime::createFromFormat('U', 0),
+        'input2' => \DateTime::createFromFormat('U', '0'),
         'absolute' => FALSE,
         'expected' => $negative_1_hour,
       ],
@@ -706,7 +706,7 @@ public function providerTestDateDiff() {
       ],
       [
         'input1' => DateTimePlus::createFromFormat('U', 3600),
-        'input2' => \DateTime::createFromFormat('U', 0),
+        'input2' => \DateTime::createFromFormat('U', '0'),
         'absolute' => TRUE,
         'expected' => $positive_1_hour,
       ],
diff --git a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php
index 90a2486bb741..3f9547b2e572 100644
--- a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php
+++ b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php
@@ -554,7 +554,7 @@ public function publicPrivateDataProvider() {
     public function testGetServiceDefinitionForDecoratedService() {
       $bar_definition = new Definition('\stdClass');
       $bar_definition->setPublic(TRUE);
-      $bar_definition->setDecoratedService(new Reference('foo'));
+      $bar_definition->setDecoratedService((string) new Reference('foo'));
       $services['bar'] = $bar_definition;
 
       $this->containerBuilder->getDefinitions()->willReturn($services);
diff --git a/core/tests/Drupal/Tests/Core/Datetime/DrupalDateTimeTest.php b/core/tests/Drupal/Tests/Core/Datetime/DrupalDateTimeTest.php
index 070aa13b1b0b..d9d70051a817 100644
--- a/core/tests/Drupal/Tests/Core/Datetime/DrupalDateTimeTest.php
+++ b/core/tests/Drupal/Tests/Core/Datetime/DrupalDateTimeTest.php
@@ -109,7 +109,7 @@ public function providerTestDateDiff() {
       ],
       [
         'input1' => DrupalDateTime::createFromFormat('U', 3600, $utc_tz, $settings),
-        'input2' => \DateTime::createFromFormat('U', 0),
+        'input2' => \DateTime::createFromFormat('U', '0'),
         'absolute' => FALSE,
         'expected' => $negative_1_hour,
       ],
@@ -121,7 +121,7 @@ public function providerTestDateDiff() {
       ],
       [
         'input1' => DrupalDateTime::createFromFormat('U', 3600, $utc_tz, $settings),
-        'input2' => \DateTime::createFromFormat('U', 0),
+        'input2' => \DateTime::createFromFormat('U', '0'),
         'absolute' => TRUE,
         'expected' => $positive_1_hour,
       ],
diff --git a/core/tests/Drupal/Tests/Core/Form/EventSubscriber/FormAjaxSubscriberTest.php b/core/tests/Drupal/Tests/Core/Form/EventSubscriber/FormAjaxSubscriberTest.php
index fe3b81afbc73..6f3f4e44f628 100644
--- a/core/tests/Drupal/Tests/Core/Form/EventSubscriber/FormAjaxSubscriberTest.php
+++ b/core/tests/Drupal/Tests/Core/Form/EventSubscriber/FormAjaxSubscriberTest.php
@@ -184,7 +184,7 @@ public function testOnExceptionBrokenPostRequest() {
     $container->set('renderer', $renderer);
     \Drupal::setContainer($container);
 
-    $exception = new BrokenPostRequestException(32 * 1e6);
+    $exception = new BrokenPostRequestException((int) (32 * 1e6));
     $request = new Request([FormBuilderInterface::AJAX_FORM_REQUEST => TRUE]);
 
     $event = new ExceptionEvent($this->httpKernel, $request, HttpKernelInterface::MAIN_REQUEST, $exception);
diff --git a/core/tests/Drupal/Tests/Core/Form/FormStateTest.php b/core/tests/Drupal/Tests/Core/Form/FormStateTest.php
index 7269077e23d3..8f48f16fcc12 100644
--- a/core/tests/Drupal/Tests/Core/Form/FormStateTest.php
+++ b/core/tests/Drupal/Tests/Core/Form/FormStateTest.php
@@ -368,10 +368,10 @@ public function testTemporaryValue() {
     $this->assertFalse($form_state->hasTemporaryValue('rainbow_sparkles'));
     $form_state->setTemporaryValue('rainbow_sparkles', 'yes');
     $this->assertSame($form_state->getTemporaryValue('rainbow_sparkles'), 'yes');
-    $this->assertTrue($form_state->hasTemporaryValue('rainbow_sparkles'), TRUE);
+    $this->assertTrue($form_state->hasTemporaryValue('rainbow_sparkles'));
     $form_state->setTemporaryValue(['rainbow_sparkles', 'magic_ponies'], 'yes');
     $this->assertSame($form_state->getTemporaryValue(['rainbow_sparkles', 'magic_ponies']), 'yes');
-    $this->assertTrue($form_state->hasTemporaryValue(['rainbow_sparkles', 'magic_ponies']), TRUE);
+    $this->assertTrue($form_state->hasTemporaryValue(['rainbow_sparkles', 'magic_ponies']));
   }
 
   /**
diff --git a/core/tests/Drupal/Tests/Core/Password/PhpPasswordTest.php b/core/tests/Drupal/Tests/Core/Password/PhpPasswordTest.php
index 21f7266d019c..f781fd7d6e94 100644
--- a/core/tests/Drupal/Tests/Core/Password/PhpPasswordTest.php
+++ b/core/tests/Drupal/Tests/Core/Password/PhpPasswordTest.php
@@ -112,7 +112,7 @@ public function providerLongPasswords() {
 
     // Check a string of 3-byte UTF-8 characters, 510 byte long password is
     // allowed.
-    $len = floor(PasswordInterface::PASSWORD_MAX_LENGTH / 3);
+    $len = (int) floor(PasswordInterface::PASSWORD_MAX_LENGTH / 3);
     $diff = PasswordInterface::PASSWORD_MAX_LENGTH % 3;
     $passwords['utf8'] = [str_repeat('€', $len), TRUE];
     // 512 byte long password is allowed.
diff --git a/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php b/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php
index 5d3e7d493ac4..eec25807ded5 100644
--- a/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php
+++ b/core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php
@@ -471,7 +471,7 @@ public function testBubblingWithPrerender($test_element) {
     );
 
     // Simulate the rendering of an entire response (i.e. a root call).
-    $output = $this->renderer->renderRoot($test_element);
+    $output = (string) $this->renderer->renderRoot($test_element);
 
     // First, assert the render array is of the expected form.
     $this->assertEquals('Cache context!Cache tag!Asset!Placeholder!barquxNested!Cached nested!', trim($output), 'Expected HTML generated.');
diff --git a/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php b/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php
index ce26cf14d906..d9716c39ed29 100644
--- a/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php
+++ b/core/tests/Drupal/Tests/Core/Render/RendererRecursionTest.php
@@ -70,7 +70,7 @@ public function testRenderRecursionWithNestedRender() {
     $this->setUpRequest();
 
     $callable = function ($markup) {
-      $this->assertStringStartsWith('<drupal-render-placeholder', $markup, 'Rendered complex child output as expected, without the placeholder replaced, i.e. with just the placeholder.');
+      $this->assertStringStartsWith('<drupal-render-placeholder', (string) $markup, 'Rendered complex child output as expected, without the placeholder replaced, i.e. with just the placeholder.');
       return $markup;
     };
 
diff --git a/core/tests/Drupal/Tests/Core/Render/RendererTest.php b/core/tests/Drupal/Tests/Core/Render/RendererTest.php
index 3fdefb20e5a0..de08a3d32228 100644
--- a/core/tests/Drupal/Tests/Core/Render/RendererTest.php
+++ b/core/tests/Drupal/Tests/Core/Render/RendererTest.php
@@ -497,7 +497,7 @@ public function testRenderSorting() {
         '#markup' => $first,
       ],
     ];
-    $output = $this->renderer->renderRoot($elements);
+    $output = (string) $this->renderer->renderRoot($elements);
 
     // The lowest weight element should appear last in $output.
     $this->assertGreaterThan(strpos($output, $first), strpos($output, $second));
@@ -533,7 +533,7 @@ public function testRenderSortingWithSetHashSorted() {
       ],
       '#sorted' => TRUE,
     ];
-    $output = $this->renderer->renderRoot($elements);
+    $output = (string) $this->renderer->renderRoot($elements);
 
     // The elements should appear in output in the same order as the array.
     $this->assertLessThan(strpos($output, $first), strpos($output, $second));
diff --git a/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php b/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php
index 1aa2da366a1c..21b1ffe7bba3 100644
--- a/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php
+++ b/core/tests/Drupal/Tests/Core/Template/TwigExtensionTest.php
@@ -107,7 +107,7 @@ public function testEscaping($template, $expected) {
     $nodes = $twig->parse($twig->tokenize(new Source($template, $name)));
 
     $this->assertSame($expected, $nodes->getNode('body')
-      ->getNode(0)
+      ->getNode('0')
       ->getNode('expr') instanceof FilterExpression);
   }
 
diff --git a/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php b/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php
index a64af6173edc..189056d6f87f 100644
--- a/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php
+++ b/core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php
@@ -411,7 +411,7 @@ public function testGenerateXss() {
     $url = new Url('test_route_4');
     $url->setUrlGenerator($this->urlGenerator);
     $result = $this->linkGenerator->generate("<script>alert('XSS!')</script>", $url);
-    $this->assertNoXPathResults('//a[@href="/test-route-4"]/script', $result);
+    $this->assertNoXPathResults('//a[@href="/test-route-4"]/script', (string) $result);
   }
 
   /**
@@ -450,7 +450,7 @@ public function testGenerateWithHtml() {
         'tag' => 'em',
       ],
     ], $result);
-    $this->assertStringContainsString('<em>HTML output</em>', $result);
+    $this->assertStringContainsString('<em>HTML output</em>', (string) $result);
   }
 
   /**
@@ -499,7 +499,7 @@ public function testGenerateActive() {
     $url = new Url('test_route_1', [], ['set_active_class' => FALSE]);
     $url->setUrlGenerator($this->urlGenerator);
     $result = $this->linkGenerator->generate('Test', $url);
-    $this->assertNoXPathResults('//a[@data-drupal-link-system-path="test-route-1"]', $result);
+    $this->assertNoXPathResults('//a[@data-drupal-link-system-path="test-route-1"]', (string) $result);
 
     // Render a link with an associated language.
     $url = new Url('test_route_1', [], [
-- 
GitLab