Problem/Motivation

Technically simpletest allows test methods to be both public and protected, but on the longrun we seem to convert stuff to
phpunit based testing, either via BrowserTestBase/KernelTestBaseNG/UnitTestCase, for which protected doens't work.

Proposed resolution

Replace all instances of protected test methods with public ones.

Here is a list of them:

Targets
    Occurrences of 'protected function test' in Project
Found Occurrences  (53 usages found)
    Unclassified occurrence  (53 usages found)
        d8  (53 usages found)
            core/modules/block/src/Tests/Views  (1 usage found)
                DisplayBlockTest.php  (1 usage found)
                    (132: 3) protected function testDeleteBlockDisplay() {
            core/modules/dblog/src/Tests  (2 usages found)
                DbLogTest.php  (2 usages found)
                    (447: 3) protected function testDBLogAddAndClear() {
                    (482: 3) protected function testFilter() {
            core/modules/search/src/Tests  (1 usage found)
                SearchBlockTest.php  (1 usage found)
                    (35: 3) protected function testSearchFormBlock() {
            core/modules/simpletest/src/Tests  (1 usage found)
                MissingCheckedRequirementsTest.php  (1 usage found)
                    (47: 3) protected function testCheckRequirements() {
            core/modules/system/src/Tests/Pager  (1 usage found)
                PagerTest.php  (1 usage found)
                    (68: 3) protected function testPagerQueryParameters() {
            core/modules/system/src/Tests/Session  (1 usage found)
                SessionHttpsTest.php  (1 usage found)
                    (35: 3) protected function testHttpsSession() {
            core/modules/user/src/Tests  (2 usages found)
                UserCreateFailMailTest.php  (1 usage found)
                    (29: 3) protected function testUserAdd() {
                UserCreateTest.php  (1 usage found)
                    (30: 3) protected function testUserAdd() {
            core/modules/views/src/Tests/Handler  (1 usage found)
                FilterDateTest.php  (1 usage found)
                    (50: 3) protected function testDateFilter() {
            core/modules/views/src/Tests/Plugin  (1 usage found)
                DisplayAttachmentTest.php  (1 usage found)
                    (35: 3) protected function testAttachment() {
            core/modules/views/src/Tests/Wizard  (1 usage found)
                BasicTest.php  (1 usage found)
                    (175: 3) protected function testWizardForm() {
            core/modules/views_ui/src/Tests  (1 usage found)
                PreviewTest.php  (1 usage found)
                    (29: 3) protected function testPreviewContextual() {

Remaining tasks

User interface changes

API changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pjbaert’s picture

Status: Active » Needs review
FileSize
8.13 KB

I changed all protected test methods to public.

dawehner’s picture

Status: Needs review » Needs work

It is looking great, beside one small case ...

+++ b/core/modules/views_ui/src/Tests/PreviewTest.php
@@ -26,7 +26,7 @@ class PreviewTest extends UITestBase {
diff --git a/core/vendor/phpunit/phpunit/tests/_files/NotPublicTestCase.php b/core/vendor/phpunit/phpunit/tests/_files/NotPublicTestCase.php

diff --git a/core/vendor/phpunit/phpunit/tests/_files/NotPublicTestCase.php b/core/vendor/phpunit/phpunit/tests/_files/NotPublicTestCase.php
index a391010..1e4dced 100644

index a391010..1e4dced 100644
--- a/core/vendor/phpunit/phpunit/tests/_files/NotPublicTestCase.php

--- a/core/vendor/phpunit/phpunit/tests/_files/NotPublicTestCase.php
+++ b/core/vendor/phpunit/phpunit/tests/_files/NotPublicTestCase.php

+++ b/core/vendor/phpunit/phpunit/tests/_files/NotPublicTestCase.php
+++ b/core/vendor/phpunit/phpunit/tests/_files/NotPublicTestCase.php
@@ -5,7 +5,7 @@ public function testPublic()

@@ -5,7 +5,7 @@ public function testPublic()
     {
     }
 
-    protected function testNotPublic()
+    public function testNotPublic()
     {
     }

Please don't change that, its part of phpunit itself, sorry.

pjbaert’s picture

I updated my patch.

pjbaert’s picture

Status: Needs work » Needs review
daffie’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.
You fixed the same 13 instances as the ones that I found.
Good work pjbaert!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Test code changes are permitted during beta. Committed cdfc902 and pushed to 8.0.x. Thanks!

  • alexpott committed cdfc902 on 8.0.x
    Issue #2443381 by pjbaert: Make all test functions public
    

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.