From acd24cb30d0b79f07d6c3c1645bd11fb5da669f6 Mon Sep 17 00:00:00 2001
From: quietone <quietone@2572884.no-reply.drupal.org>
Date: Wed, 25 Sep 2024 19:57:19 +1200
Subject: [PATCH] Issue #3470203 by mstrelan, smustgrave: Add (more) bool
 return typehints to protected test helper methods

---
 .../tests/src/Functional/CommentTestBase.php   |  4 ++--
 .../Functional/ResourceResponseTestTrait.php   |  2 +-
 .../tests/src/Functional/ResourceTestBase.php  |  2 +-
 .../SettingsTrayTestBase.php                   |  2 +-
 .../Plugin/Field/FieldType/FieldTestItem.php   |  2 +-
 .../src/Functional/Cache/CacheTestBase.php     |  2 +-
 .../tests/src/Traits/UserCreationTrait.php     |  2 +-
 .../Plugin/views/Handler/FilterTest.php        |  4 ++--
 .../BuildTests/Framework/BuildTestBase.php     |  2 +-
 .../FunctionalJavascriptTests/JSWebAssert.php  |  2 +-
 .../Drupal/KernelTests/AssertContentTrait.php  | 18 +++++++++---------
 .../Commands/TestSiteTearDownCommand.php       |  2 +-
 core/tests/Drupal/Tests/UiHelperTrait.php      |  4 ++--
 13 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/core/modules/comment/tests/src/Functional/CommentTestBase.php b/core/modules/comment/tests/src/Functional/CommentTestBase.php
index 27bd5bf6a875..d7a4f443f557 100644
--- a/core/modules/comment/tests/src/Functional/CommentTestBase.php
+++ b/core/modules/comment/tests/src/Functional/CommentTestBase.php
@@ -199,7 +199,7 @@ protected function postComment($entity, $comment, $subject = '', $contact = NULL
    * @return bool
    *   Boolean indicating whether the comment was found.
    */
-  protected function commentExists(?CommentInterface $comment = NULL, $reply = FALSE) {
+  protected function commentExists(?CommentInterface $comment = NULL, $reply = FALSE): bool {
     if ($comment) {
       $comment_element = $this->cssSelect(($reply ? '.indented ' : '') . 'article#comment-' . $comment->id());
       if (empty($comment_element)) {
@@ -347,7 +347,7 @@ protected function setCommentSettings($name, $value, $message, $field_name = 'co
    * @return bool
    *   Contact info is available.
    */
-  protected function commentContactInfoAvailable() {
+  protected function commentContactInfoAvailable(): bool {
     return (bool) preg_match('/(input).*?(name="name").*?(input).*?(name="mail").*?(input).*?(name="homepage")/s', $this->getSession()->getPage()->getContent());
   }
 
diff --git a/core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php b/core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php
index b2954987cec0..510035a070ab 100644
--- a/core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php
+++ b/core/modules/jsonapi/tests/src/Functional/ResourceResponseTestTrait.php
@@ -306,7 +306,7 @@ protected static function sortResourceCollection(array &$resources) {
    * @return bool
    *   TRUE if the needle exists is present in the haystack, FALSE otherwise.
    */
-  protected static function collectionHasResourceIdentifier(array $needle, array $haystack) {
+  protected static function collectionHasResourceIdentifier(array $needle, array $haystack): bool {
     foreach ($haystack as $resource) {
       if ($resource['type'] == $needle['type'] && $resource['id'] == $needle['id']) {
         return TRUE;
diff --git a/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php b/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
index 6586ac9392bb..c37f77ee6b4c 100644
--- a/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
+++ b/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
@@ -3504,7 +3504,7 @@ protected function getNestedIncludePaths($depth = 3) {
    *   TRUE if the field definition is found to be a reference field. FALSE
    *   otherwise.
    */
-  protected static function isReferenceFieldDefinition(FieldDefinitionInterface $field_definition) {
+  protected static function isReferenceFieldDefinition(FieldDefinitionInterface $field_definition): bool {
     /** @var \Drupal\Core\Field\TypedData\FieldItemDataDefinition $item_definition */
     $item_definition = $field_definition->getItemDefinition();
     $main_property = $item_definition->getMainPropertyName();
diff --git a/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayTestBase.php b/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayTestBase.php
index c03f73b077f0..ef3e977a93cf 100644
--- a/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayTestBase.php
+++ b/core/modules/settings_tray/tests/src/FunctionalJavascript/SettingsTrayTestBase.php
@@ -183,7 +183,7 @@ public function getBlockSelector(Block $block) {
    * @return bool
    *   TRUE if the label is visible, FALSE if it is not.
    */
-  protected function isLabelInputVisible() {
+  protected function isLabelInputVisible(): bool {
     return $this->getSession()->getPage()->find('css', static::LABEL_INPUT_SELECTOR)->isVisible();
   }
 
diff --git a/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/FieldTestItem.php b/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/FieldTestItem.php
index 2a6a468395db..c2dae20e7667 100644
--- a/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/FieldTestItem.php
+++ b/core/modules/system/tests/modules/entity_test/src/Plugin/Field/FieldType/FieldTestItem.php
@@ -104,7 +104,7 @@ public function postSave($update) {
    * @return bool
    *   TRUE if the item should be resaved, FALSE otherwise.
    */
-  protected function mustResave() {
+  protected function mustResave(): bool {
     return $this->getValue()['value'] == 'resave';
   }
 
diff --git a/core/modules/system/tests/src/Functional/Cache/CacheTestBase.php b/core/modules/system/tests/src/Functional/Cache/CacheTestBase.php
index 4b8033e9c44f..e09f46771968 100644
--- a/core/modules/system/tests/src/Functional/Cache/CacheTestBase.php
+++ b/core/modules/system/tests/src/Functional/Cache/CacheTestBase.php
@@ -28,7 +28,7 @@ abstract class CacheTestBase extends BrowserTestBase {
    * @return bool
    *   TRUE on pass, FALSE on fail.
    */
-  protected function checkCacheExists($cid, $var, $bin = NULL) {
+  protected function checkCacheExists($cid, $var, $bin = NULL): bool {
     if ($bin == NULL) {
       $bin = $this->defaultBin;
     }
diff --git a/core/modules/user/tests/src/Traits/UserCreationTrait.php b/core/modules/user/tests/src/Traits/UserCreationTrait.php
index 510d722ebd55..09d19c5f3396 100644
--- a/core/modules/user/tests/src/Traits/UserCreationTrait.php
+++ b/core/modules/user/tests/src/Traits/UserCreationTrait.php
@@ -290,7 +290,7 @@ protected function createRole(array $permissions, $rid = NULL, $name = NULL, $we
    * @return bool
    *   TRUE if the permissions are valid, FALSE otherwise.
    */
-  protected function checkPermissions(array $permissions) {
+  protected function checkPermissions(array $permissions): bool {
     $available = array_keys(\Drupal::service('user.permissions')->getPermissions());
     $valid = TRUE;
     foreach ($permissions as $permission) {
diff --git a/core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/FilterTest.php b/core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/FilterTest.php
index 4a574d30853d..6ecbeeff7883 100644
--- a/core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/FilterTest.php
+++ b/core/modules/views/tests/src/FunctionalJavascript/Plugin/views/Handler/FilterTest.php
@@ -123,7 +123,7 @@ protected function filterVisibleElements($elements): array {
    * @return bool
    *   TRUE if the required number was matched, FALSE otherwise.
    */
-  protected function waitForVisibleElementCount($count, $locator, $timeout = 10000) {
+  protected function waitForVisibleElementCount($count, $locator, $timeout = 10000): bool {
     $page = $this->getSession()->getPage();
 
     return $page->waitFor($timeout / 1000, function () use ($count, $page, $locator) {
@@ -145,7 +145,7 @@ protected function waitForVisibleElementCount($count, $locator, $timeout = 10000
    * @return bool
    *   TRUE if the required number was matched, FALSE otherwise.
    */
-  protected function waitForOnlyContentRows($timeout = 10000) {
+  protected function waitForOnlyContentRows($timeout = 10000): bool {
     $page = $this->getSession()->getPage();
 
     return $page->waitFor($timeout / 1000, function () use ($page) {
diff --git a/core/tests/Drupal/BuildTests/Framework/BuildTestBase.php b/core/tests/Drupal/BuildTests/Framework/BuildTestBase.php
index 14c46215ca31..388680bf0ad4 100644
--- a/core/tests/Drupal/BuildTests/Framework/BuildTestBase.php
+++ b/core/tests/Drupal/BuildTests/Framework/BuildTestBase.php
@@ -503,7 +503,7 @@ protected function findAvailablePort() {
    *
    * @return bool
    */
-  protected function checkPortIsAvailable($port) {
+  protected function checkPortIsAvailable($port): bool {
     $fp = @fsockopen(self::$hostName, $port, $errno, $errstr, 1);
     // If fsockopen() fails to connect, probably nothing is listening.
     // It could be a firewall but that's impossible to detect, so as a
diff --git a/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php b/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php
index 2dc675f8bb10..d3f77f05f8de 100644
--- a/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php
+++ b/core/tests/Drupal/FunctionalJavascriptTests/JSWebAssert.php
@@ -398,7 +398,7 @@ public function assertNotVisibleInViewport($selector_type, $selector, $corner =
    * @throws \Behat\Mink\Exception\UnsupportedDriverActionException
    *   When an invalid corner specification is given.
    */
-  private function checkNodeVisibilityInViewport(NodeElement $node, $corner = FALSE) {
+  private function checkNodeVisibilityInViewport(NodeElement $node, $corner = FALSE): bool {
     $xpath = $node->getXpath();
 
     // Build the JavaScript to test if the complete element or a specific corner
diff --git a/core/tests/Drupal/KernelTests/AssertContentTrait.php b/core/tests/Drupal/KernelTests/AssertContentTrait.php
index f5a73f1b6484..223d5ea662c0 100644
--- a/core/tests/Drupal/KernelTests/AssertContentTrait.php
+++ b/core/tests/Drupal/KernelTests/AssertContentTrait.php
@@ -557,7 +557,7 @@ protected function assertTextHelper($text, $message = '', $group = NULL, $not_ex
    * @return bool
    *   TRUE on pass, FALSE on fail.
    */
-  protected function assertUniqueText($text, $message = '') {
+  protected function assertUniqueText($text, $message = ''): bool {
     return $this->assertUniqueTextHelper($text, $message, NULL, TRUE);
   }
 
@@ -580,7 +580,7 @@ protected function assertUniqueText($text, $message = '') {
    * @return bool
    *   TRUE on pass, FALSE on fail.
    */
-  protected function assertNoUniqueText($text, $message = '') {
+  protected function assertNoUniqueText($text, $message = ''): bool {
     return $this->assertUniqueTextHelper($text, $message, NULL, FALSE);
   }
 
@@ -847,7 +847,7 @@ protected function assertFieldsByValue($fields, $value = NULL, $message = ''): b
    * @return bool
    *   TRUE on pass, FALSE on fail.
    */
-  protected function assertFieldByXPath($xpath, $value = NULL, $message = '') {
+  protected function assertFieldByXPath($xpath, $value = NULL, $message = ''): bool {
     $fields = $this->xpath($xpath);
 
     return $this->assertFieldsByValue($fields, $value, $message);
@@ -933,7 +933,7 @@ protected function assertNoFieldByXPath($xpath, $value = NULL, $message = ''): b
    * @return bool
    *   TRUE on pass, FALSE on fail.
    */
-  protected function assertFieldByName($name, $value = NULL, $message = NULL) {
+  protected function assertFieldByName($name, $value = NULL, $message = NULL): bool {
     if (!isset($message)) {
       if (!isset($value)) {
         $message = new FormattableMarkup('Found field with name @name', [
@@ -970,7 +970,7 @@ protected function assertFieldByName($name, $value = NULL, $message = NULL) {
    * @return bool
    *   TRUE on pass, FALSE on fail.
    */
-  protected function assertNoFieldByName($name, $value = '', $message = '') {
+  protected function assertNoFieldByName($name, $value = '', $message = ''): bool {
     return $this->assertNoFieldByXPath($this->constructFieldXpath('name', $name), $value, $message ? $message : new FormattableMarkup('Did not find field by name @name', ['@name' => $name]));
   }
 
@@ -994,7 +994,7 @@ protected function assertNoFieldByName($name, $value = '', $message = '') {
    * @return bool
    *   TRUE on pass, FALSE on fail.
    */
-  protected function assertFieldById($id, $value = '', $message = '') {
+  protected function assertFieldById($id, $value = '', $message = ''): bool {
     // Cast MarkupInterface objects to string.
     if (isset($value)) {
       $value = (string) $value;
@@ -1023,7 +1023,7 @@ protected function assertFieldById($id, $value = '', $message = '') {
    * @return bool
    *   TRUE on pass, FALSE on fail.
    */
-  protected function assertNoFieldById($id, $value = '', $message = '') {
+  protected function assertNoFieldById($id, $value = '', $message = ''): bool {
     return $this->assertNoFieldByXPath($this->constructFieldXpath('id', $id), $value, $message ? $message : new FormattableMarkup('Did not find field by id @id', ['@id' => $id]));
   }
 
@@ -1246,7 +1246,7 @@ protected function assertNoOptionSelected($id, $option, $message = ''): bool {
    * @return bool
    *   TRUE on pass, FALSE on fail.
    */
-  protected function assertField($field, $message = '') {
+  protected function assertField($field, $message = ''): bool {
     return $this->assertFieldByXPath($this->constructFieldXpath('name', $field) . '|' . $this->constructFieldXpath('id', $field), NULL, $message);
   }
 
@@ -1265,7 +1265,7 @@ protected function assertField($field, $message = '') {
    * @return bool
    *   TRUE on pass, FALSE on fail.
    */
-  protected function assertNoField($field, $message = '') {
+  protected function assertNoField($field, $message = ''): bool {
     return $this->assertNoFieldByXPath($this->constructFieldXpath('name', $field) . '|' . $this->constructFieldXpath('id', $field), NULL, $message);
   }
 
diff --git a/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php b/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php
index 9acc0d8d7b99..3d80f3a1c178 100644
--- a/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php
+++ b/core/tests/Drupal/TestSite/Commands/TestSiteTearDownCommand.php
@@ -116,7 +116,7 @@ protected function tearDown(TestDatabase $test_database, $db_url): void {
    *
    * @see \Drupal\Core\File\FileSystemInterface::deleteRecursive()
    */
-  protected function fileUnmanagedDeleteRecursive($path, $callback = NULL) {
+  protected function fileUnmanagedDeleteRecursive($path, $callback = NULL): bool {
     if (isset($callback)) {
       call_user_func($callback, $path);
     }
diff --git a/core/tests/Drupal/Tests/UiHelperTrait.php b/core/tests/Drupal/Tests/UiHelperTrait.php
index e81a058d61ae..047c3da521aa 100644
--- a/core/tests/Drupal/Tests/UiHelperTrait.php
+++ b/core/tests/Drupal/Tests/UiHelperTrait.php
@@ -401,7 +401,7 @@ protected function prepareRequest() {
    * @return bool
    *   Return TRUE if the user is logged in, FALSE otherwise.
    */
-  protected function drupalUserIsLoggedIn(AccountInterface $account) {
+  protected function drupalUserIsLoggedIn(AccountInterface $account): bool {
     $logged_in = FALSE;
 
     if (isset($account->sessionId)) {
@@ -534,7 +534,7 @@ protected function cssSelectToXpath($selector, $html = TRUE, $prefix = 'descenda
    * @return bool
    *   TRUE if test is using DrupalTestBrowser.
    */
-  protected function isTestUsingGuzzleClient() {
+  protected function isTestUsingGuzzleClient(): bool {
     $driver = $this->getSession()->getDriver();
     if ($driver instanceof BrowserKitDriver) {
       return $driver->getClient() instanceof DrupalTestBrowser;
-- 
GitLab