From 67343dfe99e207be9cce1752b14b589edab97076 Mon Sep 17 00:00:00 2001
From: xjm <xjm@65776.no-reply.drupal.org>
Date: Wed, 15 Nov 2023 14:58:42 -0600
Subject: [PATCH] Issue #3399992 by mstrelan, smustgrave, xjm: Fix strict type
 errors in test traits

(cherry picked from commit c304b09272b6e760db8cba83e718df454e20df7a)
---
 core/modules/filter/tests/src/Kernel/FilterKernelTest.php | 2 +-
 core/modules/user/tests/src/Traits/UserCreationTrait.php  | 7 +++----
 core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php         | 2 +-
 core/tests/Drupal/Tests/UiHelperTrait.php                 | 3 +--
 4 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/core/modules/filter/tests/src/Kernel/FilterKernelTest.php b/core/modules/filter/tests/src/Kernel/FilterKernelTest.php
index 0fa0d2885460..2460e186a213 100644
--- a/core/modules/filter/tests/src/Kernel/FilterKernelTest.php
+++ b/core/modules/filter/tests/src/Kernel/FilterKernelTest.php
@@ -391,7 +391,7 @@ public function testLineBreakFilter() {
     $this->assertFilteredString($filter, $tests);
 
     // Very long string hitting PCRE limits.
-    $limit = max(ini_get('pcre.backtrack_limit'), ini_get('pcre.recursion_limit'));
+    $limit = max((int) ini_get('pcre.backtrack_limit'), (int) ini_get('pcre.recursion_limit'));
     $source = $this->randomMachineName($limit);
     $result = _filter_autop($source);
     $this->assertEquals($result, '<p>' . $source . "</p>\n", 'Line break filter can process very long strings.');
diff --git a/core/modules/user/tests/src/Traits/UserCreationTrait.php b/core/modules/user/tests/src/Traits/UserCreationTrait.php
index 683ba355c8ad..9237d13b13e4 100644
--- a/core/modules/user/tests/src/Traits/UserCreationTrait.php
+++ b/core/modules/user/tests/src/Traits/UserCreationTrait.php
@@ -2,7 +2,6 @@
 
 namespace Drupal\Tests\user\Traits;
 
-use Drupal\Component\Render\FormattableMarkup;
 use Drupal\Core\Database\DatabaseExceptionWrapper;
 use Drupal\Core\Database\SchemaObjectExistsException;
 use Drupal\Core\Entity\EntityStorageException;
@@ -191,7 +190,7 @@ protected function createUser(array $permissions = [], $name = NULL, $admin = FA
     $account->save();
 
     $valid_user = $account->id() !== NULL;
-    $this->assertTrue($valid_user, new FormattableMarkup('User created with name %name and pass %pass', ['%name' => $edit['name'], '%pass' => $edit['pass']]));
+    $this->assertTrue($valid_user, "User created with name {$edit['name']} and pass {$edit['pass']}");
     if (!$valid_user) {
       return FALSE;
     }
@@ -271,7 +270,7 @@ protected function createRole(array $permissions, $rid = NULL, $name = NULL, $we
     }
     $result = $role->save();
 
-    $this->assertSame(SAVED_NEW, $result, new FormattableMarkup('Created role ID @rid with name @name.', ['@name' => var_export($role->label(), TRUE), '@rid' => var_export($role->id(), TRUE)]));
+    $this->assertSame(SAVED_NEW, $result, "Created role ID {$role->id()} with name {$role->label()}.");
 
     if ($result === SAVED_NEW) {
       // Grant the specified permissions to the role, if any.
@@ -302,7 +301,7 @@ protected function checkPermissions(array $permissions) {
     $valid = TRUE;
     foreach ($permissions as $permission) {
       if (!in_array($permission, $available)) {
-        $this->fail(new FormattableMarkup('Invalid permission %permission.', ['%permission' => $permission]));
+        $this->fail("Invalid permission $permission.");
         $valid = FALSE;
       }
     }
diff --git a/core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php b/core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php
index 9ef1913ab609..64c9566a6529 100644
--- a/core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php
+++ b/core/tests/Drupal/Tests/BrowserHtmlDebugTrait.php
@@ -137,7 +137,7 @@ protected function htmlOutput($message = NULL) {
    */
   protected function initBrowserOutputFile() {
     $browser_output_file = getenv('BROWSERTEST_OUTPUT_FILE');
-    $this->htmlOutputEnabled = is_file($browser_output_file);
+    $this->htmlOutputEnabled = is_string($browser_output_file) && is_file($browser_output_file);
     $this->htmlOutputBaseUrl = getenv('BROWSERTEST_OUTPUT_BASE_URL') ?: $GLOBALS['base_url'];
     if ($this->htmlOutputEnabled) {
       $this->htmlOutputFile = $browser_output_file;
diff --git a/core/tests/Drupal/Tests/UiHelperTrait.php b/core/tests/Drupal/Tests/UiHelperTrait.php
index 713e98518dcd..78c10d03a556 100644
--- a/core/tests/Drupal/Tests/UiHelperTrait.php
+++ b/core/tests/Drupal/Tests/UiHelperTrait.php
@@ -3,7 +3,6 @@
 namespace Drupal\Tests;
 
 use Behat\Mink\Driver\BrowserKitDriver;
-use Drupal\Component\Render\FormattableMarkup;
 use Drupal\Component\Utility\Html;
 use Drupal\Component\Utility\UrlHelper;
 use Drupal\Core\Session\AccountInterface;
@@ -161,7 +160,7 @@ protected function drupalLogin(AccountInterface $account) {
 
     // @see ::drupalUserIsLoggedIn()
     $account->sessionId = $this->getSession()->getCookie(\Drupal::service('session_configuration')->getOptions(\Drupal::request())['name']);
-    $this->assertTrue($this->drupalUserIsLoggedIn($account), new FormattableMarkup('User %name successfully logged in.', ['%name' => $account->getAccountName()]));
+    $this->assertTrue($this->drupalUserIsLoggedIn($account), "User {$account->getAccountName()} successfully logged in.");
 
     $this->loggedInUser = $account;
     $this->container->get('current_user')->setAccount($account);
-- 
GitLab