Closed (fixed)
Project:
Simplenews
Version:
8.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
7 Sep 2019 at 21:12 UTC
Updated:
23 Sep 2019 at 07:54 UTC
Jump to comment: Most recent
In the tests that have been newly ported to PHPUnit tests by #3055728: Convert from Simpletests to PHPUnit tests, the visibility of methods in the test classes is inconsistent and wrong in many place. The attached patch fixes this.
There are three types of changes in this patch:
setUp() should be protectedpublicprotected| Comment | File | Size | Author |
|---|---|---|---|
| visibility.patch | 20.61 KB | tr |
Comments
Comment #3
tr commentedComment #4
adamps commentedThanks @TR. Please can you post a link to the page that documents the requirements that you are fixing?
Comment #5
jcnventura@AdamPS, the fact the tests still pass show that the changes are not harmful. Unfortunately, I don't think there are any requirements to have everything 'protected' except the test* methods. But there should be, and they should be here: https://www.drupal.org/project/coding_standards/issues/2057905
The changes being made here make a lot of sense, as only the test functions are called externally, and all the rest is handled by the testing system, and as such can be made protected.
I'm setting this to RTBC, as I've verified the tests still run, and it solves a lot of missing method visibility problems.
Comment #6
tr commentedhttps://www.drupal.org/docs/develop/standards/object-oriented-code#visib...
says that all methods must declare a visibility. This patch does that.
There are currently 86 methods in all the Simplenews test classes. Of those 86, a full half - 43 methods - do not declare any visibility. So we must choose between public, protected, and private for these. This patch fixes those 43 methods plus corrects the visibility of 10 additional methods.
setUp(),protectedis the correct choice becausesetUp()is a method inherited fromBrowserTestBase. See https://api.drupal.org/api/drupal/core%21tests%21Drupal%21Tests%21Browse...A choice of anything other than
protectedamounts to a change to the API of the parent class, and that should only be done deliberately, for a specific purpose, and for a specific need. There is no such purpose or need here, and the current lack of visibility or public visibility is just legacy from poor PHP-based programming practices inherited from Drupal 6.publicbecause they are invoked from the testing framework so they must be visible to that framework.publicis the only visibility that will work here - any other visibility will fail to execute.publicis used for the public API of the class (the functionality the class exposes to the outside world),protectedis used for internal implementation of the public API (i.e. helper or utility functions) since we don't want the outside world to use these functions but we do want subclasses to be able to customize this functionality, andprivateis used only for internal implementation (of either the public API or of the utility functions) when we are *sure* that subclasses won't need to override these private methods. Private should be used rarely and only in very special cases, none of which apply here.Comment #8
adamps commented@TR thanks for a very clear and logical explanation.