Problem/Motivation

When people think of making stuff private, its hard to think of usecases in the future.

One example: \Drupal\Tests\BrowserTestBase::prepareDatabasePrefix ... why would ever someone override it.
Here is a usecase: test an existing site installation rather than setting up an entire Drupal installation.

Proposed resolution

Make everything protected.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#25 2793443.patch1.3 KBborisson_
#2 2793443-2.patch2.96 KBdawehner

Comments

dawehner created an issue. See original summary.

dawehner’s picture

Status: Active » Needs review
StatusFileSize
new2.96 KB
jibran’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Quickfix, +Quick fix

Make everything protected.

OK

larowlan’s picture

Issue tags: +Quickerer fix, +Quickest fix, +You fix quickly

Why stop at two tags

xjm’s picture

Version: 8.3.x-dev » 8.2.x-dev
Status: Reviewed & tested by the community » Fixed

LOL @ the tags.

This is in line with our coding standards. Given the status of BTB generally as discussed in other internal API issues, and that 8.2.x is still in beta for a few more days, I've also backported the fix to 8.2.x. Committed bde1906 and pushed to 8.3.x and 8.2.x. Thanks!

  • xjm committed bde1906 on 8.3.x
    Issue #2793443 by dawehner: Make private functions protected in...

  • xjm committed 82396ae on 8.2.x
    Issue #2793443 by dawehner: Make private functions protected in...
dawehner’s picture

One thing which would be nice though is to mark those methods as @internal, aka. this might change in the future.
Is this possible?

alexpott’s picture

I'm not sure that this change was correct. These methods were protected for a reason. Because individual tests have no business overriding them and if they do they are very much on their own. Additionally tests have no business calling them either.

The stated use case

Here is a usecase: test an existing site installation rather than setting up an entire Drupal installation.

Needs far more work - since tidying up after a test on an existing site needs a lot more thought.

dawehner’s picture

Needs far more work - since tidying up after a test on an existing site needs a lot more thought.

Right, but you need to be able to override some of those methods to even get started with it.

xjm’s picture

One thing which would be nice though is to mark those methods as @internal, aka. this might change in the future.

Protected methods are implicitly considered internal and so can change from minor to minor so long as it's not disruptive, but it can't hurt to label them so explicitly, for sure. If they are truly internal, which these seem to be. I don't think we should mark things as internal only because we want to change them (e.g. in the case of things intended as public API) but in this case it makes sense. Followup issue?

These methods were protected for a reason. Because individual tests have no business overriding them and if they do they are very much on their own. Additionally tests have no business calling them either.

I'm confused; they still are protected. They were previously private which was against our coding standards. @dawehner also presented a usecase for them being protected in the summary.

Feel free to revert if it's incorrect, in any case.

dawehner’s picture

Issue tags: -Quickfix, -Quick fix, -Quickerer fix, -Quickest fix, -You fix quickly

I'm confused; they still are protected. They were previously private which was against our coding standards. @dawehner also presented a usecase for them being protected in the summary.

Is it? I tried to find examples for that: None of them mention anything: https://www.drupal.org/coding-standards/docs https://www.drupal.org/coding-standards https://www.drupal.org/node/608152

For me private methods are totally legit, I mean especially for custom/contrib code, it is fine for using private methods. Core though, as it grew organically over time, has not the best interface design, and by that need often protected methods to allow people to swap out specific bits.

I'd be fine, when we proceed with #2793445: Allow BTB to test an existing, already installed Drupal site instead of installing from scratch as this achieves everything I could imagine for my usecase.

Let's remove the silly tags :)

xjm’s picture

Hm, apparently it was removed here without any coding standards discussion or anything:
https://www.drupal.org/node/608152/revisions/view/2739353/6786689

The explanation is:

Remove paragraphs that are really just generic standard OO programming advice and not Drupal-specific coding standards

It used to say:

The use of private methods or properties is strongly discouraged. Private properties and methods may not be accessed or overridden by child classes, which limits the ability of other developers to extend a class to suit their needs.

If it needs a revert, please reopen the issue. But again, the methods are still protected, not public, so I'm not sure if @alexpott mistyped or missed what the actual change was.

dawehner’s picture

I had the discussion with @alexpott in IRC at some point, and yeah this is actually about being private and by that not being touchable. The setup of a test should be separate from all the other crap which is going on a high level.

I actually believe that #2796105: Move similar methods in BrowserTestBase / WebTestBase to a trait; untangle installDrupal() would help us to get there

xjm’s picture

@dawehner So would you want it reverted then also in favor of #2796105: Move similar methods in BrowserTestBase / WebTestBase to a trait; untangle installDrupal() only? (Which sounds awesome BTW, but might not be backportable to 8.2.x.)

dawehner’s picture

@xjm
If you are fine with that ...

  • xjm committed 4e86e29 on 8.2.x
    Revert "Issue #2793443 by dawehner: Make private functions protected in...

  • xjm committed fea0057 on 8.3.x
    Revert "Issue #2793443 by dawehner: Make private functions protected in...
xjm’s picture

Status: Fixed » Needs review

Alright, reverted. Setting as NR for now to discuss further, close as wontfix, close as dupe of the other issue, whatever is needed. :) Thanks @dawehner.

  • xjm committed bde1906 on 8.4.x
    Issue #2793443 by dawehner: Make private functions protected in...
  • xjm committed fea0057 on 8.4.x
    Revert "Issue #2793443 by dawehner: Make private functions protected in...

  • xjm committed bde1906 on 8.4.x
    Issue #2793443 by dawehner: Make private functions protected in...
  • xjm committed fea0057 on 8.4.x
    Revert "Issue #2793443 by dawehner: Make private functions protected in...

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

borisson_’s picture

StatusFileSize
new1.3 KB

#2796105: Move similar methods in BrowserTestBase / WebTestBase to a trait; untangle installDrupal() is committed, but there are still private functions left in KernelTestBase.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Running tests for 10.1

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Passes 10.1 so LGTM

alexpott’s picture

Status: Reviewed & tested by the community » Closed (won't fix)

I've given how long we've lasted with these as private and that no use-case has come up and force this issue we should close this as a won't fix. The discussion from #19 has never occurred. And Drupal Test Traits is a thing that exists and allows you to run tests against an existing site.