From 371e006ebed728ce6bae8fdfe0f92d47c9ea50ad Mon Sep 17 00:00:00 2001 From: Lee Rowlands <lee.rowlands@previousnext.com.au> Date: Thu, 24 Oct 2024 13:11:30 +1000 Subject: [PATCH] Issue #3470403 by mstrelan, smustgrave, quietone: Add EntityInterface return typehints to protected test helper methods --- .../tests/src/Kernel/ContentModerationStateTest.php | 2 +- .../tests/src/Functional/ContentTranslationLinkTagTest.php | 3 ++- .../tests/src/Functional/ContentTranslationSyncImageTest.php | 2 +- core/modules/field/tests/src/Kernel/FieldKernelTestBase.php | 2 +- core/modules/file/tests/src/Functional/FileListingTest.php | 3 ++- core/modules/file/tests/src/Kernel/SpaceUsedTest.php | 3 ++- core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php | 2 +- .../tests/src/Functional/Entity/EntityViewControllerTest.php | 3 ++- .../tests/src/Functional/Plugin/NumericFormatPluralTest.php | 3 ++- .../workspaces/tests/src/Functional/WorkspaceTestUtilities.php | 3 ++- core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php | 2 +- .../Drupal/KernelTests/Core/Entity/EntityValidationTest.php | 3 ++- .../Drupal/KernelTests/Core/Entity/EntityViewBuilderTest.php | 3 ++- 13 files changed, 21 insertions(+), 13 deletions(-) diff --git a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php index 30d12fbb8109..2c8fe2ef91f3 100644 --- a/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php +++ b/core/modules/content_moderation/tests/src/Kernel/ContentModerationStateTest.php @@ -834,7 +834,7 @@ protected function createEntity($entity_type_id, $moderation_state = 'published' * @return \Drupal\Core\Entity\EntityInterface * The reloaded entity. */ - protected function reloadEntity(EntityInterface $entity, $revision_id = FALSE) { + protected function reloadEntity(EntityInterface $entity, $revision_id = FALSE): EntityInterface { /** @var \Drupal\Core\Entity\RevisionableStorageInterface $storage */ $storage = \Drupal::entityTypeManager()->getStorage($entity->getEntityTypeId()); $storage->resetCache([$entity->id()]); diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationLinkTagTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationLinkTagTest.php index 29e91a49af20..80fdd9a7188d 100644 --- a/core/modules/content_translation/tests/src/Functional/ContentTranslationLinkTagTest.php +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationLinkTagTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\content_translation\Functional; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Url; use Drupal\Tests\BrowserTestBase; use Drupal\language\Entity\ConfigurableLanguage; @@ -70,7 +71,7 @@ protected function setUp(): void { * @return \Drupal\Core\Entity\EntityInterface * An entity with translations. */ - protected function createTranslatableEntity() { + protected function createTranslatableEntity(): EntityInterface { $entity = EntityTestMul::create(['label' => $this->randomString()]); // Create translations for non default languages. diff --git a/core/modules/content_translation/tests/src/Functional/ContentTranslationSyncImageTest.php b/core/modules/content_translation/tests/src/Functional/ContentTranslationSyncImageTest.php index 006f28987c25..bf3c73d50a52 100644 --- a/core/modules/content_translation/tests/src/Functional/ContentTranslationSyncImageTest.php +++ b/core/modules/content_translation/tests/src/Functional/ContentTranslationSyncImageTest.php @@ -262,7 +262,7 @@ public function testImageFieldSync(): void { * @return \Drupal\Core\Entity\EntityInterface * The saved entity. */ - protected function saveEntity(EntityInterface $entity) { + protected function saveEntity(EntityInterface $entity): EntityInterface { $entity->save(); $entity = \Drupal::entityTypeManager()->getStorage('entity_test_mul')->loadUnchanged($entity->id()); return $entity; diff --git a/core/modules/field/tests/src/Kernel/FieldKernelTestBase.php b/core/modules/field/tests/src/Kernel/FieldKernelTestBase.php index b0b3fe82c014..28c8d85b7685 100644 --- a/core/modules/field/tests/src/Kernel/FieldKernelTestBase.php +++ b/core/modules/field/tests/src/Kernel/FieldKernelTestBase.php @@ -139,7 +139,7 @@ protected function createFieldWithStorage($suffix = '', $entity_type = 'entity_t * @return \Drupal\Core\Entity\EntityInterface * The entity, freshly reloaded from storage. */ - protected function entitySaveReload(EntityInterface $entity) { + protected function entitySaveReload(EntityInterface $entity): EntityInterface { $entity->save(); $controller = $this->container->get('entity_type.manager')->getStorage($entity->getEntityTypeId()); $controller->resetCache(); diff --git a/core/modules/file/tests/src/Functional/FileListingTest.php b/core/modules/file/tests/src/Functional/FileListingTest.php index cec109455b08..08b5c7cc6ad5 100644 --- a/core/modules/file/tests/src/Functional/FileListingTest.php +++ b/core/modules/file/tests/src/Functional/FileListingTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\file\Functional; +use Drupal\Core\Entity\EntityInterface; use Drupal\node\Entity\Node; use Drupal\file\Entity\File; use Drupal\entity_test\Entity\EntityTestConstraints; @@ -259,7 +260,7 @@ public function testFileListingUsageNoLink(): void { * @return \Drupal\Core\Entity\EntityInterface * A file entity. */ - protected function createFile() { + protected function createFile(): EntityInterface { // Create a new file entity. $file = File::create([ 'uid' => 1, diff --git a/core/modules/file/tests/src/Kernel/SpaceUsedTest.php b/core/modules/file/tests/src/Kernel/SpaceUsedTest.php index d8792a28147a..0f3dedf8fb43 100644 --- a/core/modules/file/tests/src/Kernel/SpaceUsedTest.php +++ b/core/modules/file/tests/src/Kernel/SpaceUsedTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\file\Kernel; +use Drupal\Core\Entity\EntityInterface; use Drupal\file\Entity\File; use Drupal\file\FileInterface; @@ -46,7 +47,7 @@ protected function setUp(): void { * @return \Drupal\Core\Entity\EntityInterface * The file entity. */ - protected function createFileWithSize($uri, $size, $uid, $status = FileInterface::STATUS_PERMANENT) { + protected function createFileWithSize($uri, $size, $uid, $status = FileInterface::STATUS_PERMANENT): EntityInterface { file_put_contents($uri, $this->randomMachineName($size)); $file = File::create([ 'uri' => $uri, diff --git a/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php b/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php index 2fe7a4510db7..bd587735352d 100644 --- a/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php +++ b/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php @@ -260,7 +260,7 @@ protected function setUp(): void { * * @throws \Drupal\Core\Entity\EntityStorageException */ - protected function setUpFields(EntityInterface $entity, UserInterface $account) { + protected function setUpFields(EntityInterface $entity, UserInterface $account): EntityInterface { if (!$entity instanceof FieldableEntityInterface) { return $entity; } diff --git a/core/modules/system/tests/src/Functional/Entity/EntityViewControllerTest.php b/core/modules/system/tests/src/Functional/Entity/EntityViewControllerTest.php index af1dd96386bc..be898a640cad 100644 --- a/core/modules/system/tests/src/Functional/Entity/EntityViewControllerTest.php +++ b/core/modules/system/tests/src/Functional/Entity/EntityViewControllerTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\system\Functional\Entity; +use Drupal\Core\Entity\EntityInterface; use Drupal\entity_test\Entity\EntityTest; use Drupal\Tests\BrowserTestBase; @@ -131,7 +132,7 @@ public function testEntityViewControllerViewBuilder(): void { * @return \Drupal\Core\Entity\EntityInterface * The created entity. */ - protected function createTestEntity($entity_type, $name = NULL) { + protected function createTestEntity($entity_type, $name = NULL): EntityInterface { $data = [ 'bundle' => $entity_type, 'name' => $name ?? $this->randomMachineName(), diff --git a/core/modules/views/tests/src/Functional/Plugin/NumericFormatPluralTest.php b/core/modules/views/tests/src/Functional/Plugin/NumericFormatPluralTest.php index 4af556d14f10..fff20aa1c206 100644 --- a/core/modules/views/tests/src/Functional/Plugin/NumericFormatPluralTest.php +++ b/core/modules/views/tests/src/Functional/Plugin/NumericFormatPluralTest.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\views\Functional\Plugin; +use Drupal\Core\Entity\EntityInterface; use Drupal\Component\Gettext\PoHeader; use Drupal\Component\Gettext\PoItem; use Drupal\file\Entity\File; @@ -151,7 +152,7 @@ public function testNumericFormatPlural(): void { * @return \Drupal\Core\Entity\EntityInterface * A file entity. */ - protected function createFile() { + protected function createFile(): EntityInterface { // Create a new file entity. $file = File::create([ 'uid' => 1, diff --git a/core/modules/workspaces/tests/src/Functional/WorkspaceTestUtilities.php b/core/modules/workspaces/tests/src/Functional/WorkspaceTestUtilities.php index 082948728edc..899dfec2780f 100644 --- a/core/modules/workspaces/tests/src/Functional/WorkspaceTestUtilities.php +++ b/core/modules/workspaces/tests/src/Functional/WorkspaceTestUtilities.php @@ -4,6 +4,7 @@ namespace Drupal\Tests\workspaces\Functional; +use Drupal\Core\Entity\EntityInterface; use Drupal\Tests\block\Traits\BlockCreationTrait; use Drupal\workspaces\Entity\Handler\IgnoredWorkspaceHandler; use Drupal\workspaces\Entity\Workspace; @@ -34,7 +35,7 @@ trait WorkspaceTestUtilities { * @return \Drupal\Core\Entity\EntityInterface * The entity. */ - protected function getOneEntityByLabel($type, $label) { + protected function getOneEntityByLabel($type, $label): EntityInterface { /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */ $entity_type_manager = \Drupal::service('entity_type.manager'); $property = $entity_type_manager->getDefinition($type)->getKey('label'); diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php index 98ee398abebb..8de8f5281c85 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityFieldTest.php @@ -79,7 +79,7 @@ protected function setUp(): void { * * @return \Drupal\Core\Entity\EntityInterface */ - protected function createTestEntity($entity_type) { + protected function createTestEntity($entity_type): EntityInterface { $this->entityName = $this->randomMachineName(); $this->entityUser = $this->createUser(); $this->entityFieldText = $this->randomMachineName(); diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityValidationTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityValidationTest.php index b2ef4be208b8..7e0fdfbda573 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityValidationTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityValidationTest.php @@ -4,6 +4,7 @@ namespace Drupal\KernelTests\Core\Entity; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Plugin\Validation\Constraint\CompositeConstraintBase; use Drupal\language\Entity\ConfigurableLanguage; @@ -73,7 +74,7 @@ protected function setUp(): void { * @return \Drupal\Core\Entity\EntityInterface * The created test entity. */ - protected function createTestEntity($entity_type) { + protected function createTestEntity($entity_type): EntityInterface { $this->entityName = $this->randomMachineName(); $this->entityUser = $this->createUser(); diff --git a/core/tests/Drupal/KernelTests/Core/Entity/EntityViewBuilderTest.php b/core/tests/Drupal/KernelTests/Core/Entity/EntityViewBuilderTest.php index fba7909ba65d..7a284b426efe 100644 --- a/core/tests/Drupal/KernelTests/Core/Entity/EntityViewBuilderTest.php +++ b/core/tests/Drupal/KernelTests/Core/Entity/EntityViewBuilderTest.php @@ -4,6 +4,7 @@ namespace Drupal\KernelTests\Core\Entity; +use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityViewBuilder; use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Cache\Cache; @@ -348,7 +349,7 @@ public function testHookEntityTypeViewModeAlter(): void { * @return \Drupal\Core\Entity\EntityInterface * The created entity. */ - protected function createTestEntity($entity_type) { + protected function createTestEntity($entity_type): EntityInterface { $data = [ 'bundle' => $entity_type, 'name' => $this->randomMachineName(), -- GitLab