Problem/Motivation

There are 29 instances of public function setUp(): void in core tests that should be protected.

Steps to reproduce

$ grep -r "public function setUp()" core
core/tests/Drupal/KernelTests/Core/StreamWrapper/ExtensionStreamTest.php:  public function setUp(): void {
core/tests/Drupal/KernelTests/Core/Entity/Sql/SqlContentEntityStorageTest.php:  public function setUp(): void {
core/tests/Drupal/KernelTests/Core/Test/SimpletestTestRunResultsStorageTest.php:  public function setUp(): void {
core/tests/Drupal/KernelTests/Core/Test/TestRunTest.php:  public function setUp(): void {
core/tests/Drupal/KernelTests/Core/Datetime/Element/DatetimeFormElementTest.php:  public function setUp(): void {
core/tests/Drupal/KernelTests/Core/Datetime/DatetimeElementFormTest.php:  public function setUp(): void {
core/tests/Drupal/Tests/Core/Render/Element/ProceduralApiDeprecationTest.php:  public function setUp(): void {
core/tests/Drupal/Tests/Core/Theme/Icon/Plugin/SvgSpriteExtractorTest.php:  public function setUp():void {
core/tests/Drupal/Tests/Core/Theme/Icon/Plugin/PathExtractorTest.php:  public function setUp():void {
core/tests/Drupal/Tests/Core/Theme/Icon/Plugin/SvgExtractorTest.php:  public function setUp():void {
core/tests/Drupal/Tests/Core/Test/WebAssertTest.php:  public function setUp(): void {
core/tests/Drupal/Tests/Core/Session/AccessPolicyProcessorTest.php:  public function setUp(): void {
core/modules/system/tests/src/Functional/Menu/LinksetControllerTest.php:  public function setUp(): void {
core/modules/system/tests/src/Functional/Menu/LinksetControllerMultiLingualTest.php:  public function setUp(): void {
core/modules/system/tests/src/Kernel/ModuleAdminLinksHelperTest.php:  public function setUp(): void {
core/modules/system/tests/src/Kernel/Theme/ThemeHookTest.php:  public function setUp(): void {
core/modules/system/tests/src/Unit/Mail/HtmlToTextTest.php:  public function setUp(): void {
core/modules/user/tests/src/Functional/UserRegistrationRestTest.php:  public function setUp(): void {
core/modules/user/tests/src/Kernel/ModulePermissionsLinkHelperTest.php:  public function setUp(): void {
core/modules/announcements_feed/tests/src/FunctionalJavascript/AlertsJsonFeedTest.php:  public function setUp():void {
core/modules/announcements_feed/tests/src/FunctionalJavascript/AccessAnnouncementTest.php:  public function setUp():void {
core/modules/announcements_feed/tests/src/Unit/AnnounceFetcherUnitTest.php:  public function setUp():void {
core/modules/block_content/tests/src/Kernel/BlockContentPermissionsTest.php:  public function setUp(): void {
core/modules/block_content/tests/src/Kernel/BlockContentTest.php:  public function setUp(): void {
core/modules/block_content/tests/src/Kernel/BlockContentRevisionsTest.php:  public function setUp(): void {
core/modules/views_ui/tests/src/FunctionalJavascript/FilterEntityReferenceTest.php:  public function setUp(): void {
core/modules/workspaces/tests/src/FunctionalJavascript/WorkspacesMediaLibraryIntegrationTest.php:  public function setUp(): void {
core/modules/jsonapi/tests/src/Functional/CommentExtrasTest.php:  public function setUp(): void {
core/modules/jsonapi/tests/src/Functional/ConfigEntityResourceTestBase.php:  public function setUp(): void {

Proposed resolution

Make them all protected to match the visibility of this method in their base classes.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Comments

mstrelan created an issue.

longwave’s picture

Is there a way of adding a test or PHPStan rule for this to prevent this creeping back in?

mstrelan’s picture

Apparently we did this once before in #3182103: Ensure correct signature for setUp(), tearDown(), setUpBeforeClass(), and assertPostConditions() methods.

PHPStan does have a method.visibility rule, but since widening the visibility is allowed there is no violation. I think it would be straight forward to write one, but not sure if it's worth it.